utxoledger

package
v1.0.0-beta.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	StoreKeyPrefixLedgerSlotIndex byte = 0

	// StoreKeyPrefixOutput defines the prefix for Output and Spent storage.
	StoreKeyPrefixOutput byte = 1

	// StoreKeyPrefixOutputSpent defines the prefix for Track spent/unspent Outputs.
	StoreKeyPrefixOutputSpent   byte = 2
	StoreKeyPrefixOutputUnspent byte = 3

	// StoreKeyPrefixSlotDiffs defines the prefix for Slot diffs.
	StoreKeyPrefixSlotDiffs byte = 4

	StoreKeyPrefixStateTree byte = 5
)

Variables

View Source
var ErrOutputsSumNotEqualTotalSupply = ierrors.New("accumulated output balance is not equal to total supply")

ErrOutputsSumNotEqualTotalSupply is returned if the sum of the output base token amounts is not equal the total supply of tokens.

Functions

func WriteSlotDiffToSnapshotWriter

func WriteSlotDiffToSnapshotWriter(writer io.WriteSeeker, diff *SlotDiff) error

Types

type IterateOption

type IterateOption func(*IterateOptions)

func ReadLockLedger

func ReadLockLedger(lockLedger bool) IterateOption

type IterateOptions

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

type LexicalOrderedOutputs

type LexicalOrderedOutputs []*Output

LexicalOrderedOutputs are outputs ordered in lexical order by their outputID.

func (LexicalOrderedOutputs) Len

func (l LexicalOrderedOutputs) Len() int

func (LexicalOrderedOutputs) Less

func (l LexicalOrderedOutputs) Less(i int, j int) bool

func (LexicalOrderedOutputs) Swap

func (l LexicalOrderedOutputs) Swap(i int, j int)

type LexicalOrderedSpents

type LexicalOrderedSpents []*Spent

LexicalOrderedSpents are spents ordered in lexical order by their outputID.

func (LexicalOrderedSpents) Len

func (l LexicalOrderedSpents) Len() int

func (LexicalOrderedSpents) Less

func (l LexicalOrderedSpents) Less(i int, j int) bool

func (LexicalOrderedSpents) Swap

func (l LexicalOrderedSpents) Swap(i int, j int)

type LookupKey

type LookupKey []byte

type Manager

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

func New

func New(store kvstore.KVStore, apiProvider iotago.APIProvider) *Manager

func (*Manager) AddGenesisUnspentOutput

func (m *Manager) AddGenesisUnspentOutput(unspentOutput *Output) error

func (*Manager) AddGenesisUnspentOutputWithoutLocking

func (m *Manager) AddGenesisUnspentOutputWithoutLocking(unspentOutput *Output) error

func (*Manager) ApplyDiff

func (m *Manager) ApplyDiff(slot iotago.SlotIndex, newOutputs Outputs, newSpents Spents) (newStateTreeRoot iotago.Identifier, err error)

func (*Manager) ApplyDiffWithoutLocking

func (m *Manager) ApplyDiffWithoutLocking(slot iotago.SlotIndex, newOutputs Outputs, newSpents Spents) (newStateTreeRoot iotago.Identifier, err error)

func (*Manager) CheckLedgerState

func (m *Manager) CheckLedgerState(tokenSupply iotago.BaseToken) error

func (*Manager) CheckStateTree

func (m *Manager) CheckStateTree() bool

func (*Manager) ClearLedgerState

func (m *Manager) ClearLedgerState() (err error)

ClearLedgerState removes all entries from the ledger (spent, unspent, diff).

func (*Manager) ComputeLedgerBalance

func (m *Manager) ComputeLedgerBalance(options ...IterateOption) (balance iotago.BaseToken, count int, err error)

func (*Manager) Export

func (m *Manager) Export(writer io.WriteSeeker, targetIndex iotago.SlotIndex) error

Export exports the ledger state to the given writer.

func (*Manager) ForEachOutput

func (m *Manager) ForEachOutput(consumer OutputConsumer, options ...IterateOption) error

func (*Manager) ForEachSpentOutput

func (m *Manager) ForEachSpentOutput(consumer SpentConsumer, options ...IterateOption) error

func (*Manager) ForEachUnspentOutput

func (m *Manager) ForEachUnspentOutput(consumer OutputConsumer, options ...IterateOption) error

func (*Manager) ForEachUnspentOutputID

func (m *Manager) ForEachUnspentOutputID(consumer OutputIDConsumer, options ...IterateOption) error

func (*Manager) Import

func (m *Manager) Import(reader io.ReadSeeker) error

Import imports the ledger state from the given reader.

func (*Manager) IsOutputIDUnspentWithoutLocking

func (m *Manager) IsOutputIDUnspentWithoutLocking(outputID iotago.OutputID) (bool, error)

func (*Manager) IsOutputUnspentWithoutLocking

func (m *Manager) IsOutputUnspentWithoutLocking(output *Output) (bool, error)

func (*Manager) KVStore

func (m *Manager) KVStore() kvstore.KVStore

KVStore returns the underlying KVStore.

func (*Manager) LedgerStateSHA256Sum

func (m *Manager) LedgerStateSHA256Sum() ([]byte, error)

func (*Manager) PruneSlotIndexWithoutLocking

func (m *Manager) PruneSlotIndexWithoutLocking(slot iotago.SlotIndex) error

func (*Manager) ReInitStateTreeWithLocking

func (m *Manager) ReInitStateTreeWithLocking()

func (*Manager) ReadLedgerIndexWithoutLocking

func (m *Manager) ReadLedgerIndexWithoutLocking() (iotago.SlotIndex, error)

func (*Manager) ReadLedgerSlot

func (m *Manager) ReadLedgerSlot() (iotago.SlotIndex, error)

func (*Manager) ReadLockLedger

func (m *Manager) ReadLockLedger()

func (*Manager) ReadOutputByOutputID

func (m *Manager) ReadOutputByOutputID(outputID iotago.OutputID) (*Output, error)

func (*Manager) ReadOutputByOutputIDWithoutLocking

func (m *Manager) ReadOutputByOutputIDWithoutLocking(outputID iotago.OutputID) (*Output, error)

func (*Manager) ReadRawOutputBytesByOutputIDWithoutLocking

func (m *Manager) ReadRawOutputBytesByOutputIDWithoutLocking(outputID iotago.OutputID) ([]byte, error)

func (*Manager) ReadSpentForOutputIDWithoutLocking

func (m *Manager) ReadSpentForOutputIDWithoutLocking(outputID iotago.OutputID) (*Spent, error)

func (*Manager) ReadUnlockLedger

func (m *Manager) ReadUnlockLedger()

func (*Manager) Rollback

func (m *Manager) Rollback(targetSlot iotago.SlotIndex) error

Rollback rolls back ledger state to the given target slot.

func (*Manager) RollbackDiff

func (m *Manager) RollbackDiff(slot iotago.SlotIndex, newOutputs Outputs, newSpents Spents) error

func (*Manager) RollbackDiffWithoutLocking

func (m *Manager) RollbackDiffWithoutLocking(slot iotago.SlotIndex, newOutputs Outputs, newSpents Spents) error

func (*Manager) SlotDiff

func (m *Manager) SlotDiff(index iotago.SlotIndex) (*SlotDiff, error)

func (*Manager) SlotDiffWithoutLocking

func (m *Manager) SlotDiffWithoutLocking(index iotago.SlotIndex) (*SlotDiff, error)

func (*Manager) SpentOutputs

func (m *Manager) SpentOutputs(options ...IterateOption) (Spents, error)

func (*Manager) StateTreeRoot

func (m *Manager) StateTreeRoot() iotago.Identifier

func (*Manager) StoreLedgerIndex

func (m *Manager) StoreLedgerIndex(slot iotago.SlotIndex) error

func (*Manager) StoreLedgerIndexWithoutLocking

func (m *Manager) StoreLedgerIndexWithoutLocking(slot iotago.SlotIndex) error

func (*Manager) UnspentOutputs

func (m *Manager) UnspentOutputs(options ...IterateOption) (Outputs, error)

func (*Manager) UnspentOutputsIDs

func (m *Manager) UnspentOutputsIDs(options ...IterateOption) (iotago.OutputIDs, error)

func (*Manager) WriteLockLedger

func (m *Manager) WriteLockLedger()

func (*Manager) WriteUnlockLedger

func (m *Manager) WriteUnlockLedger()

type Output

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

func CreateOutput

func CreateOutput(apiProvider iotago.APIProvider,
	outputID iotago.OutputID,
	blockID iotago.BlockID,
	slotBooked iotago.SlotIndex,
	output iotago.Output,
	outputProof *iotago.OutputIDProof,
) *Output

func NewOutput

func NewOutput(apiProvider iotago.APIProvider,
	outputID iotago.OutputID,
	blockID iotago.BlockID,
	slotBooked iotago.SlotIndex,
	output iotago.Output,
	outputBytes []byte,
	outputProof *iotago.OutputIDProof,
	outputProofBytes []byte,
) *Output

func OutputFromSnapshotReader

func OutputFromSnapshotReader(reader io.ReadSeeker, apiProvider iotago.APIProvider) (*Output, error)

func (*Output) BaseTokenAmount

func (o *Output) BaseTokenAmount() iotago.BaseToken

func (*Output) BlockID

func (o *Output) BlockID() iotago.BlockID

func (*Output) Bytes

func (o *Output) Bytes() []byte

func (*Output) CopyWithBlockIDAndSlotBooked

func (o *Output) CopyWithBlockIDAndSlotBooked(blockID iotago.BlockID, slotBooked iotago.SlotIndex) *Output

func (*Output) IsReadOnly

func (o *Output) IsReadOnly() bool

func (*Output) KVStorableKey

func (o *Output) KVStorableKey() (key []byte)

func (*Output) KVStorableValue

func (o *Output) KVStorableValue() (value []byte)

func (*Output) MapKey

func (o *Output) MapKey() string

func (*Output) Output

func (o *Output) Output() iotago.Output

func (*Output) OutputID

func (o *Output) OutputID() iotago.OutputID

func (*Output) OutputIDProof

func (o *Output) OutputIDProof() *iotago.OutputIDProof

func (*Output) OutputType

func (o *Output) OutputType() iotago.OutputType

func (*Output) ProofBytes

func (o *Output) ProofBytes() []byte

func (*Output) SlotBooked

func (o *Output) SlotBooked() iotago.SlotIndex

func (*Output) SlotCreated

func (o *Output) SlotCreated() iotago.SlotIndex

func (*Output) SnapshotBytes

func (o *Output) SnapshotBytes() []byte

func (*Output) StateID

func (o *Output) StateID() iotago.Identifier

func (*Output) StoredMana

func (o *Output) StoredMana() iotago.Mana

func (*Output) Type

func (o *Output) Type() mempool.StateType

func (*Output) UnspentLookupKey

func (o *Output) UnspentLookupKey() LookupKey

type OutputConsumer

type OutputConsumer func(output *Output) bool

OutputConsumer is a function that consumes an output. Returning false from this function indicates to abort the iteration.

type OutputIDConsumer

type OutputIDConsumer func(outputID iotago.OutputID) bool

OutputIDConsumer is a function that consumes an output ID. Returning false from this function indicates to abort the iteration.

type Outputs

type Outputs []*Output

func (Outputs) ToOutputSet

func (o Outputs) ToOutputSet() iotago.OutputSet

type SlotDiff

type SlotDiff struct {
	// The index of the slot.
	Slot iotago.SlotIndex
	// The outputs newly generated with this diff.
	Outputs Outputs
	// The outputs spent with this diff.
	Spents Spents
}

SlotDiff represents the generated and spent outputs by a slot's confirmation.

func ReadSlotDiffToSnapshotReader

func ReadSlotDiffToSnapshotReader(reader io.ReadSeeker, apiProvider iotago.APIProvider) (*SlotDiff, error)

func (*SlotDiff) KVStorableKey

func (sd *SlotDiff) KVStorableKey() []byte

func (*SlotDiff) KVStorableValue

func (sd *SlotDiff) KVStorableValue() []byte

func (*SlotDiff) SHA256Sum

func (sd *SlotDiff) SHA256Sum() ([]byte, error)

SHA256Sum computes the sha256 of the slot diff byte representation.

type Spent

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

Spent are already spent TXOs (transaction outputs).

func NewSpent

func NewSpent(output *Output, transactionIDSpent iotago.TransactionID, slotSpent iotago.SlotIndex) *Spent

func SpentFromSnapshotReader

func SpentFromSnapshotReader(reader io.ReadSeeker, apiProvider iotago.APIProvider, indexSpent iotago.SlotIndex) (*Spent, error)

func (*Spent) BaseTokenAmount

func (s *Spent) BaseTokenAmount() iotago.BaseToken

func (*Spent) BlockID

func (s *Spent) BlockID() iotago.BlockID

func (*Spent) KVStorableKey

func (s *Spent) KVStorableKey() (key []byte)

func (*Spent) KVStorableValue

func (s *Spent) KVStorableValue() (value []byte)

func (*Spent) MapKey

func (s *Spent) MapKey() string

func (*Spent) Output

func (s *Spent) Output() *Output

func (*Spent) OutputID

func (s *Spent) OutputID() iotago.OutputID

func (*Spent) OutputType

func (s *Spent) OutputType() iotago.OutputType

func (*Spent) SlotSpent

func (s *Spent) SlotSpent() iotago.SlotIndex

SlotSpent returns the index of the slot that spent the output.

func (*Spent) SnapshotBytes

func (s *Spent) SnapshotBytes() []byte

func (*Spent) TransactionIDSpent

func (s *Spent) TransactionIDSpent() iotago.TransactionID

TransactionIDSpent returns the ID of the transaction that spent the output.

type SpentConsumer

type SpentConsumer func(spent *Spent) bool

SpentConsumer is a function that consumes a spent output. Returning false from this function indicates to abort the iteration.

type Spents

type Spents []*Spent

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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