Documentation ¶
Index ¶
- type ApplyData
- type AssetConfigTxnFields
- type AssetFreezeTxnFields
- type AssetTransferTxnFields
- type Balances
- type ExplicitTxnContext
- type Header
- type KeyregTxnFields
- type LogicSig
- type MinFeeError
- type PaymentTxnFields
- type Payset
- type SignedTxn
- type SignedTxnInBlock
- type SignedTxnWithAD
- type SpecialAddresses
- type Transaction
- func (tx Transaction) Apply(balances Balances, spec SpecialAddresses, ctr uint64) (ad ApplyData, err error)
- func (tx Transaction) EstimateEncodedSize() int
- func (tx Transaction) ID() Txid
- func (tx *Transaction) InitCaches()
- func (tx Transaction) MatchAddress(addr basics.Address, spec SpecialAddresses, proto config.ConsensusParams) bool
- func (tx Transaction) RelevantAddrs(spec SpecialAddresses, proto config.ConsensusParams) []basics.Address
- func (tx *Transaction) ResetCaches()
- func (tx Transaction) Sign(secrets *crypto.SignatureSecrets) SignedTxn
- func (tx Transaction) ToBeHashed() (protocol.HashID, []byte)
- func (tx Transaction) TxAmount() basics.MicroAlgos
- func (tx Transaction) WellFormed(spec SpecialAddresses, proto config.ConsensusParams) error
- type TxGroup
- type Txid
- type TxnContext
- type TxnDeadError
- type TxnPriority
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplyData ¶
type ApplyData struct { // Closing amount for transaction. ClosingAmount basics.MicroAlgos `codec:"ca"` // Rewards applied to the Sender, Receiver, and CloseRemainderTo accounts. SenderRewards basics.MicroAlgos `codec:"rs"` ReceiverRewards basics.MicroAlgos `codec:"rr"` CloseRewards basics.MicroAlgos `codec:"rc"` // contains filtered or unexported fields }
ApplyData contains information about the transaction's execution.
type AssetConfigTxnFields ¶
type AssetConfigTxnFields struct { // ConfigAsset is the asset being configured or destroyed. // A zero value means allocation ConfigAsset basics.AssetIndex `codec:"caid"` // AssetParams are the parameters for the asset being // created or re-configured. A zero value means destruction. AssetParams basics.AssetParams `codec:"apar"` // contains filtered or unexported fields }
AssetConfigTxnFields captures the fields used for asset allocation, re-configuration, and destruction.
type AssetFreezeTxnFields ¶
type AssetFreezeTxnFields struct { // FreezeAccount is the address of the account whose asset // slot is being frozen or un-frozen. FreezeAccount basics.Address `codec:"fadd"` // FreezeAsset is the asset ID being frozen or un-frozen. FreezeAsset basics.AssetIndex `codec:"faid"` // AssetFrozen is the new frozen value. AssetFrozen bool `codec:"afrz"` // contains filtered or unexported fields }
AssetFreezeTxnFields captures the fields used for freezing asset slots.
type AssetTransferTxnFields ¶
type AssetTransferTxnFields struct { XferAsset basics.AssetIndex `codec:"xaid"` // AssetAmount is the amount of asset to transfer. // A zero amount transferred to self allocates that asset // in the account's Assets map. AssetAmount uint64 `codec:"aamt"` // AssetSender is the sender of the transfer. If this is not // a zero value, the real transaction sender must be the Clawback // address from the AssetParams. If this is the zero value, // the asset is sent from the transaction's Sender. AssetSender basics.Address `codec:"asnd"` // AssetReceiver is the recipient of the transfer. AssetReceiver basics.Address `codec:"arcv"` // AssetCloseTo indicates that the asset should be removed // from the account's Assets map, and specifies where the remaining // asset holdings should be transferred. It's always valid to transfer // remaining asset holdings to the creator account. AssetCloseTo basics.Address `codec:"aclose"` // contains filtered or unexported fields }
AssetTransferTxnFields captures the fields used for asset transfers.
type Balances ¶
type Balances interface { // Get looks up the balance record for an address // If the account is known to be empty, then err should be nil and the returned balance record should have the given address and empty AccountData // withPendingRewards specifies whether pending rewards should be applied. // A non-nil error means the lookup is impossible (e.g., if the database doesn't have necessary state anymore) Get(addr basics.Address, withPendingRewards bool) (basics.BalanceRecord, error) // GetAssetCreator gets the address of the account whose balance record // contains the asset params GetAssetCreator(aidx basics.AssetIndex) (basics.Address, error) Put(basics.BalanceRecord) error // Move MicroAlgos from one account to another, doing all necessary overflow checking (convenience method) // TODO: Does this need to be part of the balances interface, or can it just be implemented here as a function that calls Put and Get? Move(src, dst basics.Address, amount basics.MicroAlgos, srcRewards *basics.MicroAlgos, dstRewards *basics.MicroAlgos) error // Balances correspond to a Round, which mean that they also correspond // to a ConsensusParams. This returns those parameters. ConsensusParams() config.ConsensusParams }
Balances allow to move MicroAlgos from one address to another and to update balance records, or to access and modify individual balance records After a call to Put (or Move), future calls to Get or Move will reflect the updated balance record(s)
type ExplicitTxnContext ¶
type ExplicitTxnContext struct { ExplicitRound basics.Round Proto config.ConsensusParams GenID string GenHash crypto.Digest }
ExplicitTxnContext is a struct that implements TxnContext with explicit fields for everything.
func (ExplicitTxnContext) ConsensusProtocol ¶
func (tc ExplicitTxnContext) ConsensusProtocol() config.ConsensusParams
ConsensusProtocol implements the TxnContext interface
func (ExplicitTxnContext) GenesisHash ¶
func (tc ExplicitTxnContext) GenesisHash() crypto.Digest
GenesisHash implements the TxnContext interface
func (ExplicitTxnContext) GenesisID ¶
func (tc ExplicitTxnContext) GenesisID() string
GenesisID implements the TxnContext interface
func (ExplicitTxnContext) Round ¶
func (tc ExplicitTxnContext) Round() basics.Round
Round implements the TxnContext interface
type Header ¶
type Header struct { Sender basics.Address `codec:"snd"` Fee basics.MicroAlgos `codec:"fee"` FirstValid basics.Round `codec:"fv"` LastValid basics.Round `codec:"lv"` Note []byte `codec:"note"` // Uniqueness or app-level data about txn GenesisID string `codec:"gen"` GenesisHash crypto.Digest `codec:"gh"` // Group specifies that this transaction is part of a // transaction group (and, if so, specifies the hash // of a TxGroup). Group crypto.Digest `codec:"grp"` // Lease enforces mutual exclusion of transactions. If this field is // nonzero, then once the transaction is confirmed, it acquires the // lease identified by the (Sender, Lease) pair of the transaction until // the LastValid round passes. While this transaction possesses the // lease, no other transaction specifying this lease can be confirmed. Lease [32]byte `codec:"lx"` // contains filtered or unexported fields }
Header captures the fields common to every transaction type.
func (Header) Alive ¶
func (tx Header) Alive(tc TxnContext) error
Alive checks to see if the transaction is still alive (can be applied) at the specified Round.
func (Header) Src ¶
Src returns the address that posted the transaction. This is the account that pays the associated Fee.
func (Header) TxFee ¶
func (tx Header) TxFee() basics.MicroAlgos
TxFee returns the fee associated with this transaction.
type KeyregTxnFields ¶
type KeyregTxnFields struct { VotePK crypto.OneTimeSignatureVerifier `codec:"votekey"` SelectionPK crypto.VRFVerifier `codec:"selkey"` VoteFirst basics.Round `codec:"votefst"` VoteLast basics.Round `codec:"votelst"` VoteKeyDilution uint64 `codec:"votekd"` Nonparticipation bool `codec:"nonpart"` // contains filtered or unexported fields }
KeyregTxnFields captures the fields used for key registration transactions.
type LogicSig ¶
type LogicSig struct { // Logic signed by Sig or Msig, OR hashed to be the Address of an account. Logic []byte `codec:"l"` Sig crypto.Signature `codec:"sig"` Msig crypto.MultisigSig `codec:"msig"` // Args are not signed, but checked by Logic Args [][]byte `codec:"arg"` // contains filtered or unexported fields }
LogicSig contains logic for validating a transaction. LogicSig is signed by an account, allowing delegation of operations. OR LogicSig defines a contract account.
type MinFeeError ¶
type MinFeeError string
MinFeeError defines an error type which could be returned from the method WellFormed
func (MinFeeError) Error ¶
func (err MinFeeError) Error() string
type PaymentTxnFields ¶
type PaymentTxnFields struct { Receiver basics.Address `codec:"rcv"` Amount basics.MicroAlgos `codec:"amt"` // When CloseRemainderTo is set, it indicates that the // transaction is requesting that the account should be // closed, and all remaining funds be transferred to this // address. CloseRemainderTo basics.Address `codec:"close"` // contains filtered or unexported fields }
PaymentTxnFields captures the fields used by payment transactions.
type Payset ¶
type Payset []SignedTxnInBlock
A Payset represents a common, unforgeable, consistent, ordered set of SignedTxn objects.
func (Payset) Commit ¶
Commit returns a commitment to the Payset.
If the flat argument is true, the commitment is a hash of the entire payset.
If the flat argument is false, the commitment is the root of a merkle tree whose leaves are the Txids in the Payset. Note that the transaction root depends on the order in which the Txids appear, and that Txids do NOT cover transaction signatures.
type SignedTxn ¶
type SignedTxn struct { Sig crypto.Signature `codec:"sig"` Msig crypto.MultisigSig `codec:"msig"` Lsig LogicSig `codec:"lsig"` Txn Transaction `codec:"txn"` // contains filtered or unexported fields }
SignedTxn wraps a transaction and a signature. It exposes a Verify() method that verifies the signature and checks that the underlying transaction is well-formed. For performance, it also caches the Txid of the underlying transaction on creation. TODO: update this documentation now that there's multisig
Never instantiate a SignedTxn directly (other than inside the transactions package), and after creating a SignedTxn never modify its Txn field. Otherwise the cached Txid will be incorrect. Instead use txn.Sign to sign a normal transaction or use UnmarshalBinary / protocol.Decode to deserialize a SignedTxn from the network. These correctly cache the Txid and furthermore ensure the underlying Transaction is non-nil.
Assuming these guidelines are followed, any SignedTxn object is guaranteed to have a non-nil Txn field, and calling signedtxn.ID() will return that transaction's correct Txid.
func AssembleSignedTxn ¶
func AssembleSignedTxn(txn Transaction, sig crypto.Signature, msig crypto.MultisigSig) (SignedTxn, error)
AssembleSignedTxn assembles a multisig-signed transaction from a transaction an optional sig, and an optional multisig. No signature checking is done -- for example, this might only be a partial multisig
func (SignedTxn) GetEncodedLength ¶
GetEncodedLength returns the length in bytes of the encoded transaction
func (*SignedTxn) InitCaches ¶
func (s *SignedTxn) InitCaches()
InitCaches initializes caches inside of SignedTxn.
func (*SignedTxn) MessUpSigForTesting ¶
func (stxn *SignedTxn) MessUpSigForTesting()
MessUpSigForTesting will mess up the signature so that Verify() will fail on the signed transaction. Intended to be used in tests outside the transactions package (e.g., block validation tests) where we want to check whether we're verifying signatures.
func (SignedTxn) Priority ¶
func (s SignedTxn) Priority() TxnPriority
Priority returns the pool priority of this signed transaction.
func (*SignedTxn) PtrPriority ¶
func (s *SignedTxn) PtrPriority() TxnPriority
PtrPriority returns the pool priority of this signed transaction.
func (*SignedTxn) ResetCaches ¶
func (s *SignedTxn) ResetCaches()
ResetCaches clears cached state in this SignedTxn.
type SignedTxnInBlock ¶
type SignedTxnInBlock struct { SignedTxnWithAD HasGenesisID bool `codec:"hgi"` HasGenesisHash bool `codec:"hgh"` // contains filtered or unexported fields }
SignedTxnInBlock is how a signed transaction is encoded in a block.
func (SignedTxnInBlock) ID ¶
func (s SignedTxnInBlock) ID()
ID on SignedTxnInBlock should never be called, because the ID depends on the block from which this transaction will be decoded. By having a different return value from SignedTxn.ID(), we will catch errors at compile-time.
type SignedTxnWithAD ¶
SignedTxnWithAD is a (decoded) SignedTxn with associated ApplyData
type SpecialAddresses ¶
SpecialAddresses holds addresses with nonstandard properties.
type Transaction ¶
type Transaction struct { // Type of transaction Type protocol.TxType `codec:"type"` // Common fields for all types of transactions Header // Fields for different types of transactions KeyregTxnFields PaymentTxnFields AssetConfigTxnFields AssetTransferTxnFields AssetFreezeTxnFields // contains filtered or unexported fields }
Transaction describes a transaction that can appear in a block.
func (Transaction) Apply ¶
func (tx Transaction) Apply(balances Balances, spec SpecialAddresses, ctr uint64) (ad ApplyData, err error)
Apply changes the balances according to this transaction.
func (Transaction) EstimateEncodedSize ¶
func (tx Transaction) EstimateEncodedSize() int
EstimateEncodedSize returns the estimated encoded size of the transaction including the signature. This function is to be used for calculating the fee
func (Transaction) ID ¶
func (tx Transaction) ID() Txid
ID returns the Txid (i.e., hash) of the transaction. For efficiency this is precomputed when the Transaction is created.
func (*Transaction) InitCaches ¶
func (tx *Transaction) InitCaches()
InitCaches initializes caches inside of Transaction.
func (Transaction) MatchAddress ¶
func (tx Transaction) MatchAddress(addr basics.Address, spec SpecialAddresses, proto config.ConsensusParams) bool
MatchAddress checks if the transaction touches a given address.
func (Transaction) RelevantAddrs ¶
func (tx Transaction) RelevantAddrs(spec SpecialAddresses, proto config.ConsensusParams) []basics.Address
RelevantAddrs returns the addresses whose balance records this transaction will need to access. The header's default is to return just the sender and the fee sink.
func (*Transaction) ResetCaches ¶
func (tx *Transaction) ResetCaches()
ResetCaches clears caches inside of Transaction, if the Transaction was modified.
func (Transaction) Sign ¶
func (tx Transaction) Sign(secrets *crypto.SignatureSecrets) SignedTxn
Sign signs a transaction using a given Account's secrets.
func (Transaction) ToBeHashed ¶
func (tx Transaction) ToBeHashed() (protocol.HashID, []byte)
ToBeHashed implements the crypto.Hashable interface.
func (Transaction) TxAmount ¶
func (tx Transaction) TxAmount() basics.MicroAlgos
TxAmount returns the amount paid to the recipient in this payment
func (Transaction) WellFormed ¶
func (tx Transaction) WellFormed(spec SpecialAddresses, proto config.ConsensusParams) error
WellFormed checks that the transaction looks reasonable on its own (but not necessarily valid against the actual ledger). It does not check signatures.
type TxGroup ¶
type TxGroup struct { // TxGroupHashes specifies a list of hashes of transactions that must appear // together, sequentially, in a block in order for the group to be // valid. Each hash in the list is a hash of a transaction with // the `Group` field omitted. TxGroupHashes []crypto.Digest `codec:"txlist"` // contains filtered or unexported fields }
TxGroup describes a group of transactions that must appear together in a specific order in a block.
type Txid ¶
Txid is a hash used to uniquely identify individual transactions
func (*Txid) UnmarshalText ¶
UnmarshalText initializes the Address from an array of bytes.
type TxnContext ¶
type TxnContext interface { Round() basics.Round ConsensusProtocol() config.ConsensusParams GenesisID() string GenesisHash() crypto.Digest }
TxnContext describes the context in which a transaction can appear (pretty much, a block, but we don't have the definition of a block here, since that would be a circular dependency). This is used to decide if a transaction is alive or not.
type TxnDeadError ¶
TxnDeadError defines an error type which indicates a transaction is outside of the round validity window.
func (TxnDeadError) Error ¶
func (err TxnDeadError) Error() string
type TxnPriority ¶
type TxnPriority uint64
TxnPriority represents the pool priority of a transaction.
func (TxnPriority) LessThan ¶
func (a TxnPriority) LessThan(b TxnPriority) bool
LessThan compares two TxnPriority values
func (TxnPriority) Mul ¶
func (a TxnPriority) Mul(b uint64) TxnPriority
Mul multiplies a TxnPriority by a scalar, with saturation on overflow