utxo

package
v2.0.0-beta.7 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	UTXOStoreKeyPrefixLedgerMilestoneIndex byte = 0

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

	// UTXOStoreKeyPrefixOutputSpent defines the prefix for Track spent/unspent Outputs.
	UTXOStoreKeyPrefixOutputSpent   byte = 2
	UTXOStoreKeyPrefixOutputUnspent byte = 3

	// UTXOStoreKeyPrefixMilestoneDiffs defines the prefix for Milestone diffs.
	UTXOStoreKeyPrefixMilestoneDiffs byte = 4

	// UTXOStoreKeyPrefixTreasuryOutput defines the prefix for the Treasury Output.
	UTXOStoreKeyPrefixTreasuryOutput byte = 5
	UTXOStoreKeyPrefixReceipts       byte = 6
)
View Source
const (
	// A prefix which denotes a spent treasury output.
	// Do not modify the value since we're writing this as a bool.
	TreasuryOutputSpentPrefix = 1
	// A prefix which denotes an unspent treasury output.
	// Do not modify the value since we're writing this as a bool.
	TreasuryOutputUnspentPrefix = 0
)

Variables

View Source
var (
	// ErrInvalidTreasuryState is returned when the state of the treasury is invalid.
	ErrInvalidTreasuryState = errors.New("invalid treasury state")
)
View Source
var (
	// ErrOutputsSumNotEqualTotalSupply is returned if the sum of the output deposits is not equal the total supply of tokens.
	ErrOutputsSumNotEqualTotalSupply = errors.New("accumulated output balance is not equal to total supply")
)

Functions

func OutputIDForMigratedFunds

func OutputIDForMigratedFunds(milestoneHash iotago.MilestoneID, outputIndex uint16) iotago.OutputID

OutputIDForMigratedFunds returns the UTXO ID for a migrated funds entry given the milestone containing the receipt and the index of the entry.

func ParseBlockID

func ParseBlockID(ms *marshalutil.MarshalUtil) (iotago.BlockID, error)

func ParseOutputID

func ParseOutputID(ms *marshalutil.MarshalUtil) (iotago.OutputID, 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, j int) bool

func (LexicalOrderedOutputs) Swap

func (l LexicalOrderedOutputs) Swap(i, 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, j int) bool

func (LexicalOrderedSpents) Swap

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

type LookupKey

type LookupKey []byte

type Manager

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

func New

func New(store kvstore.KVStore) *Manager

func (*Manager) AddUnspentOutput

func (u *Manager) AddUnspentOutput(unspentOutput *Output) error

func (*Manager) ApplyConfirmation

func (u *Manager) ApplyConfirmation(msIndex iotago.MilestoneIndex, newOutputs Outputs, newSpents Spents, tm *TreasuryMutationTuple, rt *ReceiptTuple) error

func (*Manager) ApplyConfirmationWithoutLocking

func (u *Manager) ApplyConfirmationWithoutLocking(msIndex iotago.MilestoneIndex, newOutputs Outputs, newSpents Spents, tm *TreasuryMutationTuple, rt *ReceiptTuple) error

func (*Manager) CheckLedgerState

func (u *Manager) CheckLedgerState(tokenSupply uint64) error

func (*Manager) ClearLedger

func (u *Manager) ClearLedger(pruneReceipts bool) (err error)

ClearLedger removes all entries from the UTXO ledger (spent, unspent, diff, receipts, treasury).

func (*Manager) ComputeLedgerBalance

func (u *Manager) ComputeLedgerBalance(options ...IterateOption) (balance uint64, count int, err error)

func (*Manager) ForEachOutput

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

func (*Manager) ForEachReceiptTuple

func (u *Manager) ForEachReceiptTuple(consumer ReceiptTupleConsumer, options ...IterateOption) error

ForEachReceiptTuple iterates over all stored receipt tuples.

func (*Manager) ForEachReceiptTupleMigratedAt

func (u *Manager) ForEachReceiptTupleMigratedAt(migratedAtIndex iotago.MilestoneIndex, consumer ReceiptTupleConsumer, options ...IterateOption) error

ForEachReceiptTupleMigratedAt iterates over all stored receipt tuples for a given migrated at index.

func (*Manager) ForEachSpentOutput

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

func (*Manager) ForEachSpentTreasuryOutput

func (u *Manager) ForEachSpentTreasuryOutput(consumer TreasuryOutputConsumer, options ...IterateOption) error

func (*Manager) ForEachTreasuryOutput

func (u *Manager) ForEachTreasuryOutput(consumer TreasuryOutputConsumer, options ...IterateOption) error

ForEachTreasuryOutput iterates over all stored treasury outputs.

func (*Manager) ForEachUnspentOutput

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

func (*Manager) ForEachUnspentOutputID

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

func (*Manager) IsOutputIDUnspentWithoutLocking

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

func (*Manager) IsOutputUnspentWithoutLocking

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

func (*Manager) KVStore

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

KVStore returns the underlying KVStore.

func (*Manager) LedgerStateSHA256Sum

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

func (*Manager) MilestoneDiff

func (u *Manager) MilestoneDiff(msIndex iotago.MilestoneIndex) (*MilestoneDiff, error)

func (*Manager) MilestoneDiffWithoutLocking

func (u *Manager) MilestoneDiffWithoutLocking(msIndex iotago.MilestoneIndex) (*MilestoneDiff, error)

func (*Manager) PruneMilestoneIndexWithoutLocking

func (u *Manager) PruneMilestoneIndexWithoutLocking(msIndex iotago.MilestoneIndex, pruneReceipts bool, receiptMigratedAtIndex ...iotago.MilestoneIndex) error

func (*Manager) ReadLedgerIndex

func (u *Manager) ReadLedgerIndex() (iotago.MilestoneIndex, error)

func (*Manager) ReadLedgerIndexWithoutLocking

func (u *Manager) ReadLedgerIndexWithoutLocking() (iotago.MilestoneIndex, error)

func (*Manager) ReadLockLedger

func (u *Manager) ReadLockLedger()

func (*Manager) ReadOutputByOutputID

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

func (*Manager) ReadOutputByOutputIDWithoutLocking

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

func (*Manager) ReadRawOutputBytesByOutputIDWithoutLocking

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

func (*Manager) ReadSpentForOutputIDWithoutLocking

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

func (*Manager) ReadUnlockLedger

func (u *Manager) ReadUnlockLedger()

func (*Manager) RollbackConfirmation

func (u *Manager) RollbackConfirmation(msIndex iotago.MilestoneIndex, newOutputs Outputs, newSpents Spents, tm *TreasuryMutationTuple, rt *ReceiptTuple) error

func (*Manager) RollbackConfirmationWithoutLocking

func (u *Manager) RollbackConfirmationWithoutLocking(msIndex iotago.MilestoneIndex, newOutputs Outputs, newSpents Spents, tm *TreasuryMutationTuple, rt *ReceiptTuple) error

func (*Manager) SearchHighestReceiptMigratedAtIndex

func (u *Manager) SearchHighestReceiptMigratedAtIndex(options ...IterateOption) (iotago.MilestoneIndex, error)

SearchHighestReceiptMigratedAtIndex searches the highest migratedAt of all stored receipts.

func (*Manager) SpentOutputs

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

func (*Manager) StoreLedgerIndex

func (u *Manager) StoreLedgerIndex(msIndex iotago.MilestoneIndex) error

func (*Manager) StoreUnspentTreasuryOutput

func (u *Manager) StoreUnspentTreasuryOutput(to *TreasuryOutput) error

StoreUnspentTreasuryOutput stores the given unspent treasury output and also deletes any existing unspent one in the same procedure.

func (*Manager) UnspentOutputs

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

func (*Manager) UnspentOutputsIDs

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

func (*Manager) UnspentTreasuryOutputWithoutLocking

func (u *Manager) UnspentTreasuryOutputWithoutLocking() (*TreasuryOutput, error)

UnspentTreasuryOutputWithoutLocking returns the unspent treasury output.

func (*Manager) WriteLockLedger

func (u *Manager) WriteLockLedger()

func (*Manager) WriteUnlockLedger

func (u *Manager) WriteUnlockLedger()

type MilestoneDiff

type MilestoneDiff struct {

	// The index of the milestone.
	Index iotago.MilestoneIndex
	// The outputs newly generated with this diff.
	Outputs Outputs
	// The outputs spent with this diff.
	Spents Spents
	// The treasury output this diff generated.
	TreasuryOutput *TreasuryOutput
	// The treasury output this diff consumed.
	SpentTreasuryOutput *TreasuryOutput
	// contains filtered or unexported fields
}

MilestoneDiff represents the generated and spent outputs by a milestone's confirmation.

func (*MilestoneDiff) KVStorableKey

func (ms *MilestoneDiff) KVStorableKey() []byte

func (*MilestoneDiff) KVStorableValue

func (ms *MilestoneDiff) KVStorableValue() []byte

func (*MilestoneDiff) SHA256Sum

func (ms *MilestoneDiff) SHA256Sum() ([]byte, error)

SHA256Sum computes the sha256 of the milestone diff byte representation.

type Output

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

func CreateOutput

func CreateOutput(outputID iotago.OutputID, blockID iotago.BlockID, msIndexBooked iotago.MilestoneIndex, msTimestampBooked uint32, output iotago.Output) *Output

func NewOutput

func NewOutput(blockID iotago.BlockID, msIndexBooked iotago.MilestoneIndex, msTimestampBooked uint32, transaction *iotago.Transaction, index uint16) (*Output, error)

func OutputFromSnapshotReader

func OutputFromSnapshotReader(reader io.ReadSeeker, protoParams *iotago.ProtocolParameters) (*Output, error)

func ReceiptToOutputs

func ReceiptToOutputs(r *iotago.ReceiptMilestoneOpt, milestoneID iotago.MilestoneID, msIndex iotago.MilestoneIndex, msTimestamp uint32) ([]*Output, error)

ReceiptToOutputs extracts the migrated funds to outputs.

func (*Output) BlockID

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

func (*Output) Deposit

func (o *Output) Deposit() uint64

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) MilestoneIndexBooked

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

func (*Output) MilestoneTimestampBooked

func (o *Output) MilestoneTimestampBooked() uint32

func (*Output) Output

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

func (*Output) OutputID

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

func (*Output) OutputType

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

func (*Output) SnapshotBytes

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

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 ReceiptTuple

type ReceiptTuple struct {
	// The actual receipt.
	Receipt *iotago.ReceiptMilestoneOpt `json:"receipt"`
	// The index of the milestone which included the receipt.
	MilestoneIndex iotago.MilestoneIndex `json:"milestoneIndex"`
}

ReceiptTuple contains a receipt and the index of the milestone which contained the receipt.

type ReceiptTupleConsumer

type ReceiptTupleConsumer func(rt *ReceiptTuple) bool

ReceiptTupleConsumer is a function that consumes a receipt tuple. Returning false from this function indicates to abort the iteration.

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, msIndexSpent iotago.MilestoneIndex, msTimestampSpent uint32) *Spent

func SpentFromSnapshotReader

func SpentFromSnapshotReader(reader io.ReadSeeker, protoParams *iotago.ProtocolParameters, msIndexSpent iotago.MilestoneIndex, msTimestampSpent uint32) (*Spent, error)

func (*Spent) BlockID

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

func (*Spent) Deposit

func (s *Spent) Deposit() uint64

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) MilestoneIndexSpent

func (s *Spent) MilestoneIndexSpent() iotago.MilestoneIndex

MilestoneIndexSpent returns the index of the milestone that spent the output.

func (*Spent) MilestoneTimestampSpent

func (s *Spent) MilestoneTimestampSpent() uint32

MilestoneTimestampSpent returns the timestamp of the milestone that spent the output.

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) 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

type TreasuryMutationTuple

type TreasuryMutationTuple struct {
	// The treasury transaction causes this mutation.
	NewOutput *TreasuryOutput
	// The previous treasury output which funded the new transaction.
	SpentOutput *TreasuryOutput
}

TreasuryMutationTuple holds data about a mutation happening to the treasury.

func ReceiptToTreasuryMutation

func ReceiptToTreasuryMutation(r *iotago.ReceiptMilestoneOpt, unspentTreasuryOutput *TreasuryOutput, newMilestoneID iotago.MilestoneID) (*TreasuryMutationTuple, error)

ReceiptToTreasuryMutation converts a receipt to a treasury mutation tuple.

type TreasuryOutput

type TreasuryOutput struct {
	// The ID of the milestone which generated this output.
	MilestoneID iotago.MilestoneID
	// The amount residing on this output.
	Amount uint64
	// Whether this output was already spent
	Spent bool
}

TreasuryOutput represents the output of a treasury transaction.

func (*TreasuryOutput) MarshalJSON

func (t *TreasuryOutput) MarshalJSON() ([]byte, error)

func (*TreasuryOutput) UnmarshalJSON

func (t *TreasuryOutput) UnmarshalJSON(bytes []byte) error

type TreasuryOutputConsumer

type TreasuryOutputConsumer func(output *TreasuryOutput) bool

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

Jump to

Keyboard shortcuts

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