utxo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UTXOStoreKeyPrefixLedgerMilestoneIndex byte = 0
	UTXOStoreKeyPrefixOutput               byte = 1
	UTXOStoreKeyPrefixUnspent              byte = 2
	UTXOStoreKeyPrefixSpent                byte = 3
	UTXOStoreKeyPrefixMilestoneDiffs       byte = 4
	UTXOStoreKeyPrefixBalances             byte = 5
	UTXOStoreKeyPrefixTreasuryOutput       byte = 6
	UTXOStoreKeyPrefixReceipts             byte = 7
)
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 (
	// ErrInvalidBalancesTotalSupply is returned when the sum of all balances does not match total supply.
	ErrInvalidBalancesTotalSupply = errors.New("invalid balances total supply")

	// ErrInvalidBalanceOnAddress is returned when the balance on an address is invalid.
	ErrInvalidBalanceOnAddress = errors.New("invalid balance on address")

	// ErrInvalidDustForAddress is returned when the dust for an address is invalid.
	ErrInvalidDustForAddress = errors.New("invalid dust for address")
)
View Source
var (
	// Returned if the size of the given address is incorrect.
	ErrInvalidAddressSize = errors.New("invalid address size")

	// 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")
)
View Source
var (
	// Returned when the state of the treasury is invalid.
	ErrInvalidTreasuryState = errors.New("invalid treasury state")
)
View Source
var FakeTreasuryAddress = iotago.Ed25519Address{}

Functions

func OutputIDForMigratedFunds

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

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

Types

type BalanceDiff

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

func NewBalanceDiff

func NewBalanceDiff() *BalanceDiff

func (*BalanceDiff) Add

func (d *BalanceDiff) Add(newOutputs Outputs, newSpents Spents) error

func (*BalanceDiff) DiffForAddress

func (d *BalanceDiff) DiffForAddress(address iotago.Address) (balanceDiff int64, dustAllowanceBalance int64, dustOutputCount int64, err error)

func (*BalanceDiff) Remove

func (d *BalanceDiff) Remove(newOutputs Outputs, newSpents Spents) error

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

func (u *Manager) AddressBalance(address iotago.Address) (balance uint64, dustAllowed bool, err error)

func (*Manager) AddressBalanceWithoutLocking

func (u *Manager) AddressBalanceWithoutLocking(address iotago.Address) (balance uint64, dustAllowed bool, err error)

func (*Manager) ApplyConfirmation

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

func (*Manager) ApplyConfirmationWithoutLocking

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

func (*Manager) CheckLedgerState

func (u *Manager) CheckLedgerState() error

func (*Manager) ClearLedger

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

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

func (*Manager) ComputeBalance

func (u *Manager) ComputeBalance(options ...UTXOIterateOption) (balance uint64, count int, err error)

func (*Manager) ForEachOutput

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

func (*Manager) ForEachReceiptTuple

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

ForEachReceiptTuple iterates over all stored receipt tuples.

func (*Manager) ForEachReceiptTupleMigratedAt

func (u *Manager) ForEachReceiptTupleMigratedAt(migratedAtIndex milestone.Index, consumer ReceiptTupleConsumer, options ...UTXOIterateOption) error

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

func (*Manager) ForEachSpentOutput

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

func (*Manager) ForEachSpentTreasuryOutput

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

func (*Manager) ForEachTreasuryOutput

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

ForEachTreasuryOutput iterates over all stored treasury outputs.

func (*Manager) ForEachUnspentOutput

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

func (*Manager) GetMilestoneDiff

func (u *Manager) GetMilestoneDiff(msIndex milestone.Index) (*MilestoneDiff, error)

func (*Manager) GetMilestoneDiffWithoutLocking

func (u *Manager) GetMilestoneDiffWithoutLocking(msIndex milestone.Index) (*MilestoneDiff, error)

func (*Manager) IsOutputUnspent

func (u *Manager) IsOutputUnspent(outputID *iotago.UTXOInputID) (bool, error)

func (*Manager) IsOutputUnspentWithoutLocking

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

func (*Manager) PruneMilestoneIndexWithoutLocking

func (u *Manager) PruneMilestoneIndexWithoutLocking(msIndex milestone.Index, pruneReceipts bool, receiptMigratedAtIndex ...uint32) error

func (*Manager) ReadDustForAddress

func (u *Manager) ReadDustForAddress(address iotago.Address, applyDiff *BalanceDiff) (dustAllowanceBalance uint64, dustOutputCount int64, err error)

func (*Manager) ReadLedgerIndex

func (u *Manager) ReadLedgerIndex() (milestone.Index, error)

func (*Manager) ReadLedgerIndexWithoutLocking

func (u *Manager) ReadLedgerIndexWithoutLocking() (milestone.Index, error)

func (*Manager) ReadLockLedger

func (u *Manager) ReadLockLedger()

func (*Manager) ReadOutputByOutputID

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

func (*Manager) ReadOutputByOutputIDWithoutLocking

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

func (*Manager) ReadUnlockLedger

func (u *Manager) ReadUnlockLedger()

func (*Manager) RollbackConfirmation

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

func (*Manager) RollbackConfirmationWithoutLocking

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

func (*Manager) SearchHighestReceiptMigratedAtIndex

func (u *Manager) SearchHighestReceiptMigratedAtIndex(options ...UTXOIterateOption) (uint32, error)

SearchHighestReceiptMigratedAtIndex searches the highest migratedAt of all stored receipts.

func (*Manager) SpentOutputs

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

func (*Manager) StoreLedgerIndex

func (u *Manager) StoreLedgerIndex(msIndex milestone.Index) 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 ...UTXOIterateOption) ([]*Output, 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 milestone.Index
	// 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.

type Output

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

func CreateOutput

func CreateOutput(outputID *iotago.UTXOInputID, messageID hornet.MessageID, outputType iotago.OutputType, address iotago.Address, amount uint64) *Output

func NewOutput

func NewOutput(messageID hornet.MessageID, transaction *iotago.Transaction, index uint16) (*Output, error)

func ReceiptToOutputs

func ReceiptToOutputs(r *iotago.Receipt, msgId hornet.MessageID, msId *iotago.MilestoneID) ([]*Output, error)

ReceiptToOutputs extracts the migrated funds to outputs.

func (*Output) Address

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

func (*Output) Amount

func (o *Output) Amount() uint64

func (*Output) MessageID

func (o *Output) MessageID() hornet.MessageID

func (*Output) OutputID

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

func (*Output) OutputType

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

func (*Output) UTXOInput

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

type OutputConsumer

type OutputConsumer func(output *Output) bool

type Outputs

type Outputs []*Output

func (Outputs) InputToOutputMapping

func (o Outputs) InputToOutputMapping() (iotago.InputToOutputMapping, error)

type ReceiptTuple

type ReceiptTuple struct {
	// The actual receipt.
	Receipt *iotago.Receipt `json:"receipt"`
	// The index of the milestone which included the receipt.
	MilestoneIndex milestone.Index `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.

type Spent

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

Spent are already spent TXOs (transaction outputs) per address

func NewSpent

func NewSpent(output *Output, targetTransactionID *iotago.TransactionID, confirmationIndex milestone.Index) *Spent

func (*Spent) Address

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

func (*Spent) Amount

func (s *Spent) Amount() uint64

func (*Spent) ConfirmationIndex

func (s *Spent) ConfirmationIndex() milestone.Index

func (*Spent) MessageID

func (s *Spent) MessageID() hornet.MessageID

func (*Spent) Output

func (s *Spent) Output() *Output

func (*Spent) OutputID

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

func (*Spent) OutputType

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

func (*Spent) TargetTransactionID

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

type SpentConsumer

type SpentConsumer func(spent *Spent) bool

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.Receipt, unspentTreasuryOutput *TreasuryOutput, newMsId *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.

type TreasuryOutputConsumer

type TreasuryOutputConsumer func(output *TreasuryOutput) bool

TreasuryOutputConsumer is a function that consumes an output.

type UTXOIterateOption

type UTXOIterateOption func(*UTXOIterateOptions)

func FilterAddress

func FilterAddress(address iotago.Address) UTXOIterateOption

func FilterOutputType

func FilterOutputType(outputType iotago.OutputType) UTXOIterateOption

func MaxResultCount

func MaxResultCount(count int) UTXOIterateOption

func ReadLockLedger

func ReadLockLedger(lockLedger bool) UTXOIterateOption

type UTXOIterateOptions

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

Jump to

Keyboard shortcuts

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