vmtxbuilder

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package vmtxbuilder implements AnchorTransactionBuilder, a transaction builder used by the VM to construct anchor transaction. The AnchorTransactionBuilder keeps consistent state along operations of adding inputs and adding outputs (`Consume` and `AddOutput`). Total base tokens available to on-chain accounts are kept in the anchor output. The builder automatically maintains `internal` outputs which holds on-chain total balances of native tokens: one UTXO for one non-zero balance of iotago.NativeTokenID. Whenever native tokens are moved to/form the chain, those internal UTXO are updated by consuming input/producing output. The builder automatically ensures necessary minimal storage deposit on each of internal outputs. For this, builder takes base tokens from the total base tokens on the chain or puts them back, depending on the needs of internal outputs. When txbuilder is unable to maintain consistent state, it panics. The following panic code are possible: - ErrProtocolExceptionInputLimitExceeded when maximum number of inputs in the transaction is exceeded - ErrProtocolExceptionOutputLimitExceeded when maximum number of outputs in the transaction is exceeded - ErrProtocolExceptionNumberOfNativeTokensLimitExceeded when number of total different nativeTokenIDs is exceeded - ErrProtocolExceptionNotEnoughFundsForInternalStorageDeposit when total number of base tokens available is not enough for storage deposit of the new internal output - ErrNotEnoughBaseTokensBalance attempt to debit more base tokens than possible - ErrNotEnoughNativeAssetBalance attempt to debit more native tokens than possible - ErrOverflow overflow of arithmetics

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountsContractRead

type AccountsContractRead struct {
	// nativeTokenOutputLoaderFunc loads stored output from the state
	// Should return nil if does not exist
	NativeTokenOutput func(iotago.NativeTokenID) (*iotago.BasicOutput, iotago.OutputID)

	// foundryLoaderFunc returns foundry output and id by its serial number
	// Should return nil if foundry does not exist
	FoundryOutput func(uint32) (*iotago.FoundryOutput, iotago.OutputID)

	// NFTOutput returns the stored NFT output from the state
	// Should return nil if NFT is not accounted for
	NFTOutput func(id iotago.NFTID) (*iotago.NFTOutput, iotago.OutputID)

	// TotalFungibleTokens returns the total base tokens and native tokens accounted by the chain
	TotalFungibleTokens func() *isc.Assets
}

type AnchorTransactionBuilder

type AnchorTransactionBuilder struct {
	// contains filtered or unexported fields
}

AnchorTransactionBuilder represents structure which handles all the data needed to eventually build an essence of the anchor transaction

func NewAnchorTransactionBuilder

func NewAnchorTransactionBuilder(
	anchorOutput *iotago.AliasOutput,
	anchorOutputID iotago.OutputID,
	anchorOutputStorageDeposit uint64,
	accounts AccountsContractRead,
) *AnchorTransactionBuilder

NewAnchorTransactionBuilder creates new AnchorTransactionBuilder object

func (*AnchorTransactionBuilder) AddOutput

func (txb *AnchorTransactionBuilder) AddOutput(o iotago.Output) int64

AddOutput adds an information about posted request. It will produce output Return adjustment needed for the L2 ledger (adjustment on base tokens related to storage deposit)

func (*AnchorTransactionBuilder) AnchorOutputStorageDeposit

func (txb *AnchorTransactionBuilder) AnchorOutputStorageDeposit() uint64

func (*AnchorTransactionBuilder) BuildTransactionEssence

func (txb *AnchorTransactionBuilder) BuildTransactionEssence(stateMetadata []byte) (*iotago.TransactionEssence, []byte)

BuildTransactionEssence builds transaction essence from tx builder data

func (*AnchorTransactionBuilder) Clone

Clone clones the AnchorTransactionBuilder object. Used to snapshot/recover

func (*AnchorTransactionBuilder) Consume

Consume adds an input to the transaction. It panics if transaction cannot hold that many inputs All explicitly consumed inputs will hold fixed index in the transaction It updates total assets held by the chain. So it may panic due to exceed output counts Returns the amount of baseTokens needed to cover SD costs for the NTs/NFT contained by the request output

func (*AnchorTransactionBuilder) ConsumeUnprocessable

func (txb *AnchorTransactionBuilder) ConsumeUnprocessable(req isc.OnLedgerRequest) int

ConsumeUnprocessable adds an unprocessable request to the txbuilder, consumes the original request and cretes a new output keeping assets intact return the position of the resulting output in `txb.postedOutputs`

func (*AnchorTransactionBuilder) CreateAnchorOutput

func (txb *AnchorTransactionBuilder) CreateAnchorOutput(stateMetadata []byte) *iotago.AliasOutput

func (*AnchorTransactionBuilder) CreateNewFoundry

func (txb *AnchorTransactionBuilder) CreateNewFoundry(
	scheme iotago.TokenScheme,
	metadata []byte,
) (uint32, uint64)

func (*AnchorTransactionBuilder) DestroyFoundry

func (txb *AnchorTransactionBuilder) DestroyFoundry(sn uint32) uint64

DestroyFoundry destroys existing foundry. Return storage deposit

func (*AnchorTransactionBuilder) FoundriesToBeUpdated

func (txb *AnchorTransactionBuilder) FoundriesToBeUpdated() ([]uint32, []uint32)

func (*AnchorTransactionBuilder) FoundryOutputsBySN

func (txb *AnchorTransactionBuilder) FoundryOutputsBySN(serNums []uint32) map[uint32]*iotago.FoundryOutput

func (*AnchorTransactionBuilder) InputsAreFull

func (txb *AnchorTransactionBuilder) InputsAreFull() bool

InputsAreFull returns if transaction cannot hold more inputs

func (*AnchorTransactionBuilder) MintNFT

func (txb *AnchorTransactionBuilder) MintNFT(addr iotago.Address, immutableMetadata []byte, issuer iotago.Address) (uint16, *iotago.NFTOutput)

func (*AnchorTransactionBuilder) ModifyNativeTokenSupply

func (txb *AnchorTransactionBuilder) ModifyNativeTokenSupply(nativeTokenID iotago.NativeTokenID, delta *big.Int) int64

ModifyNativeTokenSupply inflates the supply is delta > 0, shrinks if delta < 0 returns adjustment of the storage deposit.

func (*AnchorTransactionBuilder) MustBalanced

func (txb *AnchorTransactionBuilder) MustBalanced()

MustBalanced asserts that the txb is balanced (intputs/outputs) and is consistent with L2 IMPORTANT: must be executed after `BuildTransactionEssence`, so that txb.resultAnchorOutput is calculated

func (*AnchorTransactionBuilder) NFTOutputs

func (txb *AnchorTransactionBuilder) NFTOutputs() []*iotago.NFTOutput

func (*AnchorTransactionBuilder) NFTOutputsToBeUpdated

func (txb *AnchorTransactionBuilder) NFTOutputsToBeUpdated() (toBeAdded, toBeRemoved []*iotago.NFTOutput, minted []iotago.Output)

func (*AnchorTransactionBuilder) NativeTokenOutputsByTokenIDs

func (txb *AnchorTransactionBuilder) NativeTokenOutputsByTokenIDs(ids []iotago.NativeTokenID) map[iotago.NativeTokenID]*iotago.BasicOutput

func (*AnchorTransactionBuilder) NativeTokenRecordsToBeUpdated

func (txb *AnchorTransactionBuilder) NativeTokenRecordsToBeUpdated() ([]iotago.NativeTokenID, []iotago.NativeTokenID)

func (*AnchorTransactionBuilder) TotalBaseTokensInOutputs

func (txb *AnchorTransactionBuilder) TotalBaseTokensInOutputs() (uint64, uint64)

TotalBaseTokensInOutputs returns (a) total base tokens owned by SCs and (b) total base tokens locked as storage deposit

type TransactionTotals

type TransactionTotals struct {
	// does not include internal storage deposits
	TotalBaseTokensInL2Accounts uint64
	// internal storage deposit
	TotalBaseTokensInStorageDeposit uint64
	// balances of native tokens (in all inputs/outputs). In the tx builder only loaded those which are needed
	NativeTokenBalances map[iotago.NativeTokenID]*big.Int
	// token supplies in foundries
	TokenCirculatingSupplies map[iotago.NativeTokenID]*big.Int
	// base tokens sent out by the transaction
	SentOutBaseTokens uint64
	// Sent out native tokens by the transaction
	SentOutTokenBalances map[iotago.NativeTokenID]*big.Int
}

func (*TransactionTotals) BalancedWith

func (t *TransactionTotals) BalancedWith(another *TransactionTotals) error

Jump to

Keyboard shortcuts

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