backing

package
v1.99.99 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2023 License: Apache-2.0 Imports: 19 Imported by: 6

Documentation

Index

Constants

View Source
const MaxKeysInAccount = 16

MaxKeysInAccount is the maximum number of keys allowed to be associated with an account, and the maximum number of signatures allowed to be sent in a valid transaction.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountData

type AccountData struct {
	Balance             math.Ndau                    `json:"balance" chain:"61,Acct_Balance"`
	ValidationKeys      []signature.PublicKey        `json:"validationKeys" chain:"62,Acct_ValidationKeys"`
	ValidationScript    []byte                       `json:"validationScript" chain:"69,Acct_ValidationScript"`
	RewardsTarget       *address.Address             `json:"rewardsTarget" chain:"63,Acct_RewardsTarget"`
	IncomingRewardsFrom []address.Address            `json:"incomingRewardsFrom" chain:"64,Acct_IncomingRewardsFrom"`
	DelegationNode      *address.Address             `json:"delegationNode" chain:"65,Acct_DelegationNode"`
	Lock                *Lock                        `json:"lock" chain:"78"`
	LastEAIUpdate       math.Timestamp               `json:"lastEAIUpdate" chain:"66,Acct_LastEAIUpdate"`
	LastWAAUpdate       math.Timestamp               `json:"lastWAAUpdate" chain:"67,Acct_LastWAAUpdate"`
	WeightedAverageAge  math.Duration                `json:"weightedAverageAge" chain:"68,Acct_WeightedAverageAge"`
	Sequence            uint64                       `json:"sequence" chain:"71,Acct_Sequence"`
	StakeRules          *StakeRules                  `json:"stake_rules" chain:"79"`
	Costakers           map[string]map[string]uint64 `json:"costakers" chain:"76,Acct_Costakers"`
	Holds               []Hold                       `json:"holds" chain:"70,Acct_Holds"`
	RecourseSettings    RecourseSettings             `json:"recourseSettings" chain:"80"`
	CurrencySeatDate    *math.Timestamp              `json:"currencySeatDate" chain:"72,Acct_CurrencySeatDate"`
	Parent              *address.Address             `json:"parent" chain:"73,Acct_Parent"`
	Progenitor          *address.Address             `json:"progenitor" chain:"74,Acct_Progenitor"`
	UncreditedEAI       math.Ndau                    `json:"-" msg:"-"` // exclude from serialization
}

AccountData contains all the information the node needs to take action on a particular account.

See the whitepaper: https://github.com/ndau/whitepapers/blob/master/node_incentives/transactions.md#wallet-data

func NewAccountData

func NewAccountData(blockTime math.Timestamp, defaultRecoursePeriod math.Duration) AccountData

NewAccountData creates a new AccountData struct

The zero value of AccountData is not useful, because AccountData needs to have non-zero values for LastEAIUpdate and LastWAAUpdate if its EAI and WAA calculations are to be accurate.

Unfortunately, go being go, we can't require that this method is used, but we can provide it to make it easier to do the right thing.

func (AccountData) AvailableBalance

func (ad AccountData) AvailableBalance() (math.Ndau, error)

AvailableBalance computes the balance available

Normally one would wish to call UpdateRecourses shortly before calling this

func (AccountData) HoldSum

func (a AccountData) HoldSum() math.Ndau

HoldSum returns the sum of held ndau in this account

func (*AccountData) IsLocked

func (ad *AccountData) IsLocked(blockTime math.Timestamp) bool

IsLocked abstracts away the complexity of our lock model.

If the account is locked and not notified, this returns true. If the account is notified and the notification period has not yet elapsed, this returns true. If the account is notified and the notification period has elapsed, this returns false and removes the lock.

func (*AccountData) IsNotified

func (ad *AccountData) IsNotified(blockTime math.Timestamp) bool

IsNotified is true when this account has been notified but has not yet unlocked.

func (AccountData) IsSelfStakedTo

func (a AccountData) IsSelfStakedTo(rules address.Address) bool

IsSelfStakedTo is true when the target is self-staked to the rules account

func (*AccountData) MarshalMsg

func (z *AccountData) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (AccountData) MarshalNoms

func (x AccountData) MarshalNoms(vrw nt.ValueReadWriter) (accountDataValue nt.Value, err error)

MarshalNoms implements noms/go/marshal.Marshaler

func (*AccountData) Msgsize

func (z *AccountData) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (AccountData) PrimaryStake

func (a AccountData) PrimaryStake(rules address.Address) (ps *Hold)

PrimaryStake returns the stake data for a primary stake to a rules account

If it doesn't exist, returns nil.

func (AccountData) StakeOutboundSum

func (a AccountData) StakeOutboundSum() math.Ndau

StakeOutboundSum returns the sum of ndau staked from this account

func (*AccountData) UnmarshalMsg

func (z *AccountData) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*AccountData) UnmarshalNoms

func (x *AccountData) UnmarshalNoms(value nt.Value) (err error)

UnmarshalNoms implements noms/go/marshal.Unmarshaler

This method makes no attempt to zeroize the provided struct; it simply overwrites fields as they are found.

func (*AccountData) UpdateCurrencySeat

func (ad *AccountData) UpdateCurrencySeat(blockTime math.Timestamp)

UpdateCurrencySeat sets the account's currency seat status appropriately given its balance. It is safe to call repeatedly; it's smart enough not to change the state inappropriately.

func (*AccountData) UpdateRecourses

func (ad *AccountData) UpdateRecourses(blockTime math.Timestamp)

UpdateRecourses settles funds whose recourse periods have expired

func (*AccountData) ValidateSignatures

func (ad *AccountData) ValidateSignatures(data []byte, signatures []signature.Signature) (bool, *bitset256.Bitset256)

ValidateSignatures returns `true` if signature quantity makes sense and every signature provided is valid given the provided data.

It returns the validity of the signature set and a bitset.

The bitset is a map whose semantics differ according to whether or not validation succeeded.

If validation was successful, `1` elements are keys from `ad.ValidationKeys` which validated a signature.

If validation was not successful, `1` elements are elements from `signatures` which failed to validate.

func (AccountData) VisitStakesOutbound

func (a AccountData) VisitStakesOutbound(visit func(Hold) (stop bool))

VisitStakesOutbound visits each stake in this account

If the visitor ever returns true, iteration stops.

type Hold

type Hold struct {
	Qty    math.Ndau       `json:"qty" chain:"81,Hold_Quantity"`
	Expiry *math.Timestamp `json:"expiry" chain:"82,Hold_Expiry"`
	Txhash string          `json:"tx_hash" chain:"83,Hold_TxHash"`
	Stake  *StakeData      `json:"stake" chain:"84,Hold_Stake"`
}

Hold tracks a portion of this account's ndau which cannot currently be spent

func (*Hold) MarshalMsg

func (z *Hold) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Hold) MarshalNoms

func (x Hold) MarshalNoms(vrw nt.ValueReadWriter) (holdValue nt.Value, err error)

MarshalNoms implements noms/go/marshal.Marshaler

func (*Hold) Msgsize

func (z *Hold) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Hold) UnmarshalMsg

func (z *Hold) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Hold) UnmarshalNoms

func (x *Hold) UnmarshalNoms(value nt.Value) (err error)

UnmarshalNoms implements noms/go/marshal.Unmarshaler

This method makes no attempt to zeroize the provided struct; it simply overwrites fields as they are found.

type Lock

type Lock struct {
	NoticePeriod math.Duration `msg:"notice" chain:"91,Lock_NoticePeriod" json:"noticePeriod"`
	// if a lock has not been notified, this is nil
	UnlocksOn *math.Timestamp `msg:"unlock" chain:"92,Lock_UnlocksOn" json:"unlocksOn"`
	Bonus     eai.Rate        `msg:"bonus" chain:"93,Lock_Bonus" json:"bonus"`
}

Lock keeps track of an account's Lock information

func NewLock

func NewLock(period math.Duration, bonusTable eai.RateTable) *Lock

NewLock constructs a new lock with appropriate bonus rate looked up

func (*Lock) DecodeMsg

func (z *Lock) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Lock) EncodeMsg

func (z *Lock) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Lock) GetBonusRate

func (l *Lock) GetBonusRate() eai.Rate

GetBonusRate implements eai.Lock

func (*Lock) GetNoticePeriod

func (l *Lock) GetNoticePeriod() math.Duration

GetNoticePeriod implements eai.Lock

func (*Lock) GetUnlocksOn

func (l *Lock) GetUnlocksOn() *math.Timestamp

GetUnlocksOn implements eai.Lock

func (*Lock) MarshalMsg

func (z *Lock) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Lock) MarshalNoms

func (x Lock) MarshalNoms(vrw nt.ValueReadWriter) (lockValue nt.Value, err error)

MarshalNoms implements noms/go/marshal.Marshaler

func (*Lock) Msgsize

func (z *Lock) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Lock) Notify

func (l *Lock) Notify(blockTime math.Timestamp, weightedAverageAge math.Duration) error

Notify updates this lock with notification of intent to unlock

func (*Lock) UnmarshalMsg

func (z *Lock) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Lock) UnmarshalNoms

func (x *Lock) UnmarshalNoms(value nt.Value) (err error)

UnmarshalNoms implements noms/go/marshal.Unmarshaler

This method makes no attempt to zeroize the provided struct; it simply overwrites fields as they are found.

type Node

type Node struct {
	Active             bool                `json:"active"`
	DistributionScript []byte              `json:"distribution_script"`
	TMAddress          string              `json:"tm_address"`
	Key                signature.PublicKey `json:"public_key"`
	// contains filtered or unexported fields
}

Node keeps track of nodes in the validator and verifier sets

Types here are noms-compatible for ease of marshalling and unmarshalling; though they're public for auto-marshalling purposes, they're not really meant for public access. Instead, the intent is that helper functions will manage all changes and handle type conversions.

nomsify Node

func (*Node) GetRegistration

func (x *Node) GetRegistration() math.Timestamp

GetRegistration returns the Node struct's managedVarRegistration value.

func (*Node) IsManagedVarSet

func (x *Node) IsManagedVarSet(name string) bool

IsManagedVarSet returns whether the given managed var has ever been set in the Node.

func (*Node) MarshalMsg

func (z *Node) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Node) MarshalNoms

func (x Node) MarshalNoms(vrw nt.ValueReadWriter) (nodeValue nt.Value, err error)

MarshalNoms implements noms/go/marshal.Marshaler

func (*Node) Msgsize

func (z *Node) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Node) SetRegistration

func (x *Node) SetRegistration(val math.Timestamp)

SetRegistration sets the Node struct's managedVarRegistration value, and flags it for noms marshaling if this is the first time it's being set.

func (*Node) UnmarshalMsg

func (z *Node) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Node) UnmarshalNoms

func (x *Node) UnmarshalNoms(value nt.Value) (err error)

UnmarshalNoms implements noms/go/marshal.Unmarshaler

This method makes no attempt to zeroize the provided struct; it simply overwrites fields as they are found.

type RecourseSettings

type RecourseSettings struct {
	Period    math.Duration   `json:"period" chain:"111,RecourseSettings_Period"`
	ChangesAt *math.Timestamp `json:"changes_at" chain:"112,RecourseSettings_ChangesAt"`
	Next      *math.Duration  `json:"next" chain:"113,RecourseSettings_Next"`
}

RecourseSettings tracks the recourse settings for outbound transactions

func (*RecourseSettings) MarshalMsg

func (z *RecourseSettings) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (RecourseSettings) MarshalNoms

func (x RecourseSettings) MarshalNoms(vrw nt.ValueReadWriter) (recourseSettingsValue nt.Value, err error)

MarshalNoms implements noms/go/marshal.Marshaler

func (*RecourseSettings) Msgsize

func (z *RecourseSettings) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*RecourseSettings) UnmarshalMsg

func (z *RecourseSettings) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*RecourseSettings) UnmarshalNoms

func (x *RecourseSettings) UnmarshalNoms(value nt.Value) (err error)

UnmarshalNoms implements noms/go/marshal.Unmarshaler

This method makes no attempt to zeroize the provided struct; it simply overwrites fields as they are found.

type StakeData

type StakeData struct {
	Point     math.Timestamp  `json:"point" chain:"101,Stake_Point"`
	RulesAcct address.Address `json:"rules_acct" chain:"102,Stake_RulesAcct"`
	StakeTo   address.Address `json:"stake_to" chain:"103,Stake_To"`
}

StakeData keeps track of a particular stake or costake

func (*StakeData) DecodeMsg

func (z *StakeData) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*StakeData) EncodeMsg

func (z *StakeData) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*StakeData) MarshalMsg

func (z *StakeData) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (StakeData) MarshalNoms

func (x StakeData) MarshalNoms(vrw nt.ValueReadWriter) (stakeDataValue nt.Value, err error)

MarshalNoms implements noms/go/marshal.Marshaler

func (*StakeData) Msgsize

func (z *StakeData) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*StakeData) UnmarshalMsg

func (z *StakeData) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*StakeData) UnmarshalNoms

func (x *StakeData) UnmarshalNoms(value nt.Value) (err error)

UnmarshalNoms implements noms/go/marshal.Unmarshaler

This method makes no attempt to zeroize the provided struct; it simply overwrites fields as they are found.

type StakeRules

type StakeRules struct {
	Script  []byte            `json:"script" chain:"120,StakeRules_Script"`
	Inbound map[string]uint64 `json:"inbound" chain:"121,StakeRules_Inbound"`
}

StakeRules keeps track of data associated with Rules accounts

func (*StakeRules) DecodeMsg

func (z *StakeRules) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*StakeRules) EncodeMsg

func (z *StakeRules) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*StakeRules) MarshalMsg

func (z *StakeRules) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (StakeRules) MarshalNoms

func (x StakeRules) MarshalNoms(vrw nt.ValueReadWriter) (stakeRulesValue nt.Value, err error)

MarshalNoms implements noms/go/marshal.Marshaler

func (*StakeRules) Msgsize

func (z *StakeRules) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*StakeRules) UnmarshalMsg

func (z *StakeRules) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*StakeRules) UnmarshalNoms

func (x *StakeRules) UnmarshalNoms(value nt.Value) (err error)

UnmarshalNoms implements noms/go/marshal.Unmarshaler

This method makes no attempt to zeroize the provided struct; it simply overwrites fields as they are found.

type State

type State struct {

	// Accounts is a map of all accounts that exist on the blockchain.
	Accounts map[string]AccountData
	// Delegates is a map of strings to a set of strings
	// All strings are addresses
	// the keys are the delegated nodes
	// the values are the addresses of the accounts which those nodes must
	// compute
	Delegates map[string]map[string]struct{}
	// Nodes keeps track of the validator and verifier nodes.
	// The key is the node address. The value is a Node struct.
	Nodes map[string]Node
	// The last node reward nomination is necessary in state because this
	// governs the validity of upcoming node reward nominations; there's
	// a minimum interval between them.
	LastNodeRewardNomination math.Timestamp
	// Node rewards are a bit complex. They're accumulated with every
	// CreditEAI transaction into the PendingNodeReward variable. On
	// NominateNodeReward, the balance in PendingNodeReward is moved into
	// UnclaimedNodeReward, because there may be further CreditEAI transactions,
	// which have to be stored up for the subsequent node.
	// ClaimNodeReward transactions actually claim the unclaimed node reward;
	// otherwise, it's overwritten at the next Nominate tx.
	PendingNodeReward   math.Ndau
	UnclaimedNodeReward math.Ndau
	// Of course, we have to keep track of which node has acutally won
	NodeRewardWinner *address.Address
	// TotalRFE is the sum of all RFE transactions.
	// It is also updated by the genesis program: it's initialized with the
	// implied RFEs for genesis accounts
	TotalRFE math.Ndau
	// TotalIssue is the sum of all Issue transactions.
	TotalIssue math.Ndau
	// SIB is the current burn rate applied to all transfers.
	SIB eai.Rate
	// TotalBurned is the sum of all burned ndau
	TotalBurned math.Ndau
	// These prices are preserved here just to assist downstream consumers
	// have more trust in the SIB calculations.
	MarketPrice pricecurve.Nanocent
	TargetPrice pricecurve.Nanocent

	// System variables are all stored here. A system variable is a named
	// msgp-encoded object. It is safe to assume that all keys are valid utf-8.
	Sysvars map[string][]byte
	// contains filtered or unexported fields
}

State is primarily a set of accounts nomsify State

func (*State) AccountHasAttribute

func (s *State) AccountHasAttribute(addr address.Address, attr string) (bool, error)

AccountHasAttribute returns whether the account with the given address has the given account attribute. Valid attributes can be found in system_vars/pkg/system_vars/account_attributes.go

func (State) AggregateStake

func (s State) AggregateStake(target, rules address.Address) (ps *Hold)

AggregateStake returns the aggregate stake data from a target account to a rules account

The only way in which this differs from target.PrimaryStake is that the Qty is suitably adjusted to include the contributions of all costakers.

If target isn't a primary staker to the rules account, returns nil.

func (*State) GetAccount

func (s *State) GetAccount(
	address address.Address,
	blockTime math.Timestamp,
	defaultRecoursePeriod math.Duration,
) (AccountData, bool)

GetAccount returns the account at the requested address.

If the account does not already exist, a fresh one is created.

This function is necessary because account zero values are not valid: the `Last*Update` fields must be initialized with the current block time.

The boolean return value is true when the account previously existed; false when it is new.

func (*State) GetEndowmentNAV

func (x *State) GetEndowmentNAV() pricecurve.Nanocent

GetEndowmentNAV returns the State struct's managedVarEndowmentNAV value.

func (*State) Init

func (s *State) Init(nt.ValueReadWriter)

Init satisfies meta.State

func (State) IsActiveNode

func (s State) IsActiveNode(node address.Address) bool

IsActiveNode is true when the provided address is an active node

func (*State) IsManagedVarSet

func (x *State) IsManagedVarSet(name string) bool

IsManagedVarSet returns whether the given managed var has ever been set in the State.

func (State) MarshalNoms

func (x State) MarshalNoms(vrw nt.ValueReadWriter) (stateValue nt.Value, err error)

MarshalNoms implements noms/go/marshal.Marshaler

func (*State) PayReward

func (s *State) PayReward(
	srcAddress address.Address,
	reward math.Ndau,
	blockTime math.Timestamp,
	defaultRecoursePeriod math.Duration,
	isEAI bool,
	resetUncreditedEAI bool,
) ([]address.Address, error)

PayReward updates the state of the target address to add the given qty of ndau, following the link to any specified rewards target. If the rewards target account does not previously exist, it will be created. Returns a list of accounts whose state was updated in some way. Note that if the reward is redirected, it is still the original account whose lastEAIUpdate time is changed. If isEAI we change WAA only if it's not the same account (per the rules of EAI). If isEAI and resetUncreditedEAI we set the source account's UncreditedEAI to 0. If it's redirected we change WAA for the target account and do nothing to the source. If it's not redirected we change WAA only if it's not EAI. After updating the balance in an account, this also updates currency seat information for that account.

func (*State) SetEndowmentNAV

func (x *State) SetEndowmentNAV(val pricecurve.Nanocent)

SetEndowmentNAV sets the State struct's managedVarEndowmentNAV value, and flags it for noms marshaling if this is the first time it's being set.

func (*State) TotalDelegationTo

func (s *State) TotalDelegationTo(node address.Address) math.Ndau

TotalDelegationTo computes the total amount of ndau delegated to a particular node

func (State) TotalStake

func (s State) TotalStake(target, primary, rules address.Address) (qty math.Ndau)

TotalStake returns the total stake from a target account to a rules account

Because any account may stake multiple times to the same rules account via various primary stakes, this function requires that you pass in the primary stake of interest.

func (*State) UnmarshalNoms

func (x *State) UnmarshalNoms(value nt.Value) (err error)

UnmarshalNoms implements noms/go/marshal.Unmarshaler

This method makes no attempt to zeroize the provided struct; it simply overwrites fields as they are found.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL