utxodb

package
v1.0.1-rc.14 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package utxodb provides tools to simulate an in-memory synchronous ledger, for testing purposes.

Index

Constants

View Source
const (
	DefaultBaseTokenSupply = tpkg.TestTokenSupply

	// FundsFromFaucetAmount is how many base tokens are returned from the faucet.
	FundsFromFaucetAmount = 1000 * isc.Million
)

Variables

This section is empty.

Functions

This section is empty.

Types

type InitParams

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

func DefaultInitParams

func DefaultInitParams() *InitParams

func (*InitParams) WithInitialTime

func (i *InitParams) WithInitialTime(t time.Time) *InitParams

func (*InitParams) WithSupply

func (i *InitParams) WithSupply(supply uint64) *InitParams

func (*InitParams) WithTimeStep

func (i *InitParams) WithTimeStep(timestep time.Duration) *InitParams

type UnixSeconds

type UnixSeconds uint64

type UtxoDB

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

UtxoDB mocks the Tangle ledger by implementing a fully synchronous in-memory database of transactions. It ensures the consistency of the ledger and all added transactions by checking inputs, outputs and signatures.

func New

func New(params ...*InitParams) *UtxoDB

New creates a new UtxoDB instance

func (*UtxoDB) AddToLedger

func (u *UtxoDB) AddToLedger(tx *iotago.Transaction) error

AddToLedger adds a transaction to UtxoDB, ensuring consistency of the UtxoDB ledger.

func (*UtxoDB) AdvanceClockBy

func (u *UtxoDB) AdvanceClockBy(step time.Duration)

func (*UtxoDB) GenesisAddress

func (u *UtxoDB) GenesisAddress() iotago.Address

GenesisAddress returns the genesis address.

func (*UtxoDB) GetAddressBalanceBaseTokens

func (u *UtxoDB) GetAddressBalanceBaseTokens(addr iotago.Address) uint64

GetAddressBalanceBaseTokens returns the total amount of base token owned by the address

func (*UtxoDB) GetAddressBalances

func (u *UtxoDB) GetAddressBalances(addr iotago.Address) *isc.Assets

GetAddressBalances returns the total amount of base tokens and tokens owned by the address

func (*UtxoDB) GetAddressNFTs

func (u *UtxoDB) GetAddressNFTs(addr iotago.Address) map[iotago.OutputID]*iotago.NFTOutput

func (*UtxoDB) GetAliasOutputs

func (u *UtxoDB) GetAliasOutputs(addr iotago.Address) map[iotago.OutputID]*iotago.AliasOutput

GetAliasOutputs collects all outputs of type iotago.AliasOutput for the address

func (*UtxoDB) GetFundsFromFaucet

func (u *UtxoDB) GetFundsFromFaucet(target iotago.Address, amount ...uint64) (*iotago.Transaction, error)

GetFundsFromFaucet sends FundsFromFaucetAmount base tokens from the genesis address to the given address.

func (*UtxoDB) GetOutput

func (u *UtxoDB) GetOutput(outID iotago.OutputID) iotago.Output

GetOutput finds an output by ID (either spent or unspent).

func (*UtxoDB) GetTransaction

func (u *UtxoDB) GetTransaction(txID iotago.TransactionID) (*iotago.Transaction, bool)

GetTransaction retrieves value transaction by its hash (ID).

func (*UtxoDB) GetUnspentOutputs

func (u *UtxoDB) GetUnspentOutputs(addr iotago.Address) (iotago.OutputSet, iotago.OutputIDs)

GetUnspentOutputs returns all unspent outputs locked by the address with its ids

func (*UtxoDB) GlobalTime

func (u *UtxoDB) GlobalTime() time.Time

func (*UtxoDB) MustGetTransaction

func (u *UtxoDB) MustGetTransaction(txID iotago.TransactionID) *iotago.Transaction

MustGetTransaction same as GetTransaction only panics if transaction is not in UtxoDB.

func (*UtxoDB) SetState

func (u *UtxoDB) SetState(state *UtxoDBState)

func (*UtxoDB) State

func (u *UtxoDB) State() *UtxoDBState

func (*UtxoDB) Supply

func (u *UtxoDB) Supply() uint64

Supply returns supply of the instance.

func (*UtxoDB) TimeStep

func (u *UtxoDB) TimeStep() time.Duration

type UtxoDBState

type UtxoDBState struct {
	Supply            uint64
	Transactions      map[string]*iotago.Transaction
	UTXO              []string
	GlobalLogicalTime time.Time
	TimeStep          time.Duration
}

Jump to

Keyboard shortcuts

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