Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateDynamicFee(cost uint64, baseFee *big.Int) (uint64, error)
- func SortEVMInputsAndSigners(inputs []EVMInput, signers [][]*secp256k1.PrivateKey)
- type AtomicBlockContext
- type EVMInput
- type EVMOutput
- type Metadata
- type StateDB
- type Status
- type Tx
- func ExtractAtomicTx(atomicTxBytes []byte, codec codec.Manager) (*Tx, error)
- func ExtractAtomicTxs(atomicTxBytes []byte, batch bool, codec codec.Manager) ([]*Tx, error)
- func ExtractAtomicTxsBatch(atomicTxBytes []byte, codec codec.Manager) ([]*Tx, error)
- func NewExportTx(ctx *snow.Context, rules extras.Rules, state StateDB, assetID ids.ID, ...) (*Tx, error)
- func NewImportTx(ctx *snow.Context, rules extras.Rules, time uint64, chainID ids.ID, ...) (*Tx, error)
- type TxMarshaller
- type UnsignedAtomicTx
- type UnsignedExportTx
- func (utx *UnsignedExportTx) AtomicOps() (ids.ID, *atomic.Requests, error)
- func (utx *UnsignedExportTx) Burned(assetID ids.ID) (uint64, error)
- func (utx *UnsignedExportTx) EVMStateTransfer(ctx *snow.Context, state StateDB) error
- func (utx *UnsignedExportTx) GasUsed(fixedFee bool) (uint64, error)
- func (utx *UnsignedExportTx) InputUTXOs() set.Set[ids.ID]
- func (utx *UnsignedExportTx) Verify(ctx *snow.Context, rules extras.Rules) error
- func (utx *UnsignedExportTx) Visit(v Visitor) error
- type UnsignedImportTx
- func (utx *UnsignedImportTx) AtomicOps() (ids.ID, *atomic.Requests, error)
- func (utx *UnsignedImportTx) Burned(assetID ids.ID) (uint64, error)
- func (utx *UnsignedImportTx) EVMStateTransfer(ctx *snow.Context, state StateDB) error
- func (utx *UnsignedImportTx) GasUsed(fixedFee bool) (uint64, error)
- func (utx *UnsignedImportTx) InputUTXOs() set.Set[ids.ID]
- func (utx *UnsignedImportTx) Verify(ctx *snow.Context, rules extras.Rules) error
- func (utx *UnsignedImportTx) Visit(v Visitor) error
- type UnsignedTx
- type Visitor
Constants ¶
const ( AvalancheAtomicTxFee = units.MilliAvax // The base cost to charge per atomic transaction. Added in Apricot Phase 5. AtomicTxBaseCost uint64 = 10_000 )
const CodecVersion = uint16(0)
const (
X2CRateUint64 uint64 = 1_000_000_000
)
Variables ¶
var ( ErrExportNonAVAXInputBanff = errors.New("export input cannot contain non-AVAX in Banff") ErrExportNonAVAXOutputBanff = errors.New("export output cannot contain non-AVAX in Banff") ErrNoExportOutputs = errors.New("tx has no export outputs") )
var ( ErrImportNonAVAXInputBanff = errors.New("import input cannot contain non-AVAX in Banff") ErrImportNonAVAXOutputBanff = errors.New("import output cannot contain non-AVAX in Banff") ErrNoImportInputs = errors.New("tx has no imported inputs") ErrWrongChainID = errors.New("tx has wrong chain ID") ErrNoEVMOutputs = errors.New("tx has no EVM outputs") ErrInputsNotSortedUnique = errors.New("inputs not sorted and unique") ErrOutputsNotSortedUnique = errors.New("outputs not sorted and unique") ErrOutputsNotSorted = errors.New("tx outputs not sorted") )
var ( ErrWrongNetworkID = errors.New("tx was issued with a different network ID") ErrNilTx = errors.New("tx is nil") ErrNoValueInput = errors.New("input has no value") )
var ( TxBytesGas uint64 = 1 EVMOutputGas uint64 = (common.AddressLength + wrappers.LongLen + hashing.HashLen) * TxBytesGas EVMInputGas uint64 = (common.AddressLength+wrappers.LongLen+hashing.HashLen+wrappers.LongLen)*TxBytesGas + secp256k1fx.CostPerSignature // X2CRate is the conversion rate between the smallest denomination on the X-Chain // 1 nAVAX and the smallest denomination on the C-Chain 1 wei. Where 1 nAVAX = 1 gWei. // This is only required for AVAX because the denomination of 1 AVAX is 9 decimal // places on the X and P chains, but is 18 decimal places within the EVM. X2CRate = uint256.NewInt(X2CRateUint64) )
Constants for calculating the gas consumed by atomic transactions
var ( // Codec does serialization and deserialization Codec codec.Manager )
Functions ¶
func CalculateDynamicFee ¶
calculates the amount of AVAX that must be burned by an atomic transaction that consumes [cost] at [baseFee].
func SortEVMInputsAndSigners ¶
func SortEVMInputsAndSigners(inputs []EVMInput, signers [][]*secp256k1.PrivateKey)
SortEVMInputsAndSigners sorts the list of EVMInputs based on the addresses and assetIDs
Types ¶
type AtomicBlockContext ¶
type AtomicBlockContext interface {
AtomicTxs() []*Tx
}
type EVMInput ¶
type EVMInput struct { Address common.Address `serialize:"true" json:"address"` Amount uint64 `serialize:"true" json:"amount"` AssetID ids.ID `serialize:"true" json:"assetID"` Nonce uint64 `serialize:"true" json:"nonce"` }
EVMInput defines an input created from the EVM state to fund export transactions
type EVMOutput ¶
type EVMOutput struct { Address common.Address `serialize:"true" json:"address"` Amount uint64 `serialize:"true" json:"amount"` AssetID ids.ID `serialize:"true" json:"assetID"` }
EVMOutput defines an output that is added to the EVM state created by import transactions
type Metadata ¶
type Metadata struct {
// contains filtered or unexported fields
}
func (*Metadata) Initialize ¶
Initialize set the bytes and ID
func (*Metadata) SignedBytes ¶
Bytes returns the binary representation of this data
type StateDB ¶
type StateDB interface { AddBalance(common.Address, *uint256.Int) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) SubBalance(common.Address, *uint256.Int) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) GetBalance(common.Address) *uint256.Int GetBalanceMultiCoin(common.Address, common.Hash) *big.Int GetNonce(common.Address) uint64 SetNonce(common.Address, uint64) }
type Status ¶
type Status uint32
Status ...
List of possible status values Unknown Zero value, means the status is not known Dropped means the transaction was in the mempool, but was dropped because it failed verification Processing means the transaction is in the mempool Accepted means the transaction was accepted
type Tx ¶
type Tx struct { // The body of this transaction UnsignedAtomicTx `serialize:"true" json:"unsignedTx"` // The credentials of this transaction Creds []verify.Verifiable `serialize:"true" json:"credentials"` }
Tx is a signed transaction
func ExtractAtomicTx ¶
ExtractAtomicTx extracts a singular atomic transaction from [atomicTxBytes] and returns a slice of atomic transactions for compatibility with the type returned post ApricotPhase5. Note: this function assumes [atomicTxBytes] is non-empty.
func ExtractAtomicTxs ¶
extractAtomicTxs returns the atomic transactions in [atomicTxBytes] if they exist. if [batch] is true, it attempts to unmarshal [atomicTxBytes] as a slice of transactions (post-ApricotPhase5), and if it is false, then it unmarshals it as a single atomic transaction.
func ExtractAtomicTxsBatch ¶
ExtractAtomicTxsBatch extracts a slice of atomic transactions from [atomicTxBytes]. Note: this function assumes [atomicTxBytes] is non-empty.
func NewExportTx ¶
func NewExportTx( ctx *snow.Context, rules extras.Rules, state StateDB, assetID ids.ID, amount uint64, chainID ids.ID, to ids.ShortID, baseFee *big.Int, keys []*secp256k1.PrivateKey, ) (*Tx, error)
NewExportTx returns a new ExportTx
func NewImportTx ¶
func NewImportTx( ctx *snow.Context, rules extras.Rules, time uint64, chainID ids.ID, to common.Address, baseFee *big.Int, kc *secp256k1fx.Keychain, atomicUTXOs []*avax.UTXO, ) (*Tx, error)
NewImportTx returns a new ImportTx
func (*Tx) BlockFeeContribution ¶
func (tx *Tx) BlockFeeContribution(fixedFee bool, avaxAssetID ids.ID, baseFee *big.Int) (*big.Int, *big.Int, error)
BlockFeeContribution calculates how much AVAX towards the block fee contribution was paid for via this transaction denominated in [avaxAssetID] with [baseFee] used to calculate the cost of this transaction. This function also returns the [gasUsed] by the transaction for inclusion in the [baseFee] algorithm.
type TxMarshaller ¶ added in v0.15.1
type TxMarshaller struct{}
func (*TxMarshaller) MarshalGossip ¶ added in v0.15.1
func (g *TxMarshaller) MarshalGossip(tx *Tx) ([]byte, error)
func (*TxMarshaller) UnmarshalGossip ¶ added in v0.15.1
func (_ *TxMarshaller) UnmarshalGossip(bytes []byte) (*Tx, error)
type UnsignedAtomicTx ¶
type UnsignedAtomicTx interface { UnsignedTx // InputUTXOs returns the UTXOs this tx consumes InputUTXOs() set.Set[ids.ID] // Verify attempts to verify that the transaction is well formed Verify(ctx *snow.Context, rules extras.Rules) error // Visit calls the corresponding method for the underlying transaction type // implementing [Visitor]. // This is used in semantic verification of the tx. Visit(v Visitor) error // AtomicOps returns the blockchainID and set of atomic requests that // must be applied to shared memory for this transaction to be accepted. // The set of atomic requests must be returned in a consistent order. AtomicOps() (ids.ID, *atomic.Requests, error) EVMStateTransfer(ctx *snow.Context, state StateDB) error }
UnsignedAtomicTx is an unsigned operation that can be atomically accepted
type UnsignedExportTx ¶
type UnsignedExportTx struct { Metadata // ID of the network on which this tx was issued NetworkID uint32 `serialize:"true" json:"networkID"` // ID of this blockchain. BlockchainID ids.ID `serialize:"true" json:"blockchainID"` // Which chain to send the funds to DestinationChain ids.ID `serialize:"true" json:"destinationChain"` // Inputs Ins []EVMInput `serialize:"true" json:"inputs"` // Outputs that are exported to the chain ExportedOutputs []*avax.TransferableOutput `serialize:"true" json:"exportedOutputs"` }
UnsignedExportTx is an unsigned ExportTx
func (*UnsignedExportTx) Burned ¶
func (utx *UnsignedExportTx) Burned(assetID ids.ID) (uint64, error)
Amount of [assetID] burned by this transaction
func (*UnsignedExportTx) EVMStateTransfer ¶
func (utx *UnsignedExportTx) EVMStateTransfer(ctx *snow.Context, state StateDB) error
EVMStateTransfer executes the state update from the atomic export transaction
func (*UnsignedExportTx) GasUsed ¶
func (utx *UnsignedExportTx) GasUsed(fixedFee bool) (uint64, error)
func (*UnsignedExportTx) InputUTXOs ¶
func (utx *UnsignedExportTx) InputUTXOs() set.Set[ids.ID]
InputUTXOs returns a set of all the hash(address:nonce) exporting funds.
func (*UnsignedExportTx) Visit ¶ added in v0.15.1
func (utx *UnsignedExportTx) Visit(v Visitor) error
type UnsignedImportTx ¶
type UnsignedImportTx struct { Metadata // ID of the network on which this tx was issued NetworkID uint32 `serialize:"true" json:"networkID"` // ID of this blockchain. BlockchainID ids.ID `serialize:"true" json:"blockchainID"` // Which chain to consume the funds from SourceChain ids.ID `serialize:"true" json:"sourceChain"` // Inputs that consume UTXOs produced on the chain ImportedInputs []*avax.TransferableInput `serialize:"true" json:"importedInputs"` // Outputs Outs []EVMOutput `serialize:"true" json:"outputs"` }
UnsignedImportTx is an unsigned ImportTx
func (*UnsignedImportTx) AtomicOps ¶
AtomicOps returns imported inputs spent on this transaction We spend imported UTXOs here rather than in verification because we don't want to remove an imported UTXO in verification only to have the transaction not be Accepted. This would be inconsistent. Recall that imported UTXOs are not kept in a versionDB.
func (*UnsignedImportTx) Burned ¶
func (utx *UnsignedImportTx) Burned(assetID ids.ID) (uint64, error)
Amount of [assetID] burned by this transaction
func (*UnsignedImportTx) EVMStateTransfer ¶
func (utx *UnsignedImportTx) EVMStateTransfer(ctx *snow.Context, state StateDB) error
EVMStateTransfer performs the state transfer to increase the balances of accounts accordingly with the imported EVMOutputs
func (*UnsignedImportTx) GasUsed ¶
func (utx *UnsignedImportTx) GasUsed(fixedFee bool) (uint64, error)
func (*UnsignedImportTx) InputUTXOs ¶
func (utx *UnsignedImportTx) InputUTXOs() set.Set[ids.ID]
InputUTXOs returns the UTXOIDs of the imported funds
func (*UnsignedImportTx) Visit ¶ added in v0.15.1
func (utx *UnsignedImportTx) Visit(v Visitor) error
type UnsignedTx ¶
type UnsignedTx interface { Initialize(unsignedBytes, signedBytes []byte) ID() ids.ID GasUsed(fixedFee bool) (uint64, error) Burned(assetID ids.ID) (uint64, error) Bytes() []byte SignedBytes() []byte }
UnsignedTx is an unsigned transaction
type Visitor ¶ added in v0.15.1
type Visitor interface { ImportTx(*UnsignedImportTx) error ExportTx(*UnsignedExportTx) error }
Visitor allows executing custom logic against the underlying transaction types.