Documentation ¶
Index ¶
- Constants
- Variables
- type Consumer
- type EpochDiff
- type Events
- type Ledger
- func (l *Ledger) CheckTransaction(ctx context.Context, tx utxo.Transaction) (err error)
- func (l *Ledger) LoadEpochDiff(epochDiff *EpochDiff) error
- func (l *Ledger) LoadOutputWithMetadatas(outputsWithMetadatas []*OutputWithMetadata)
- func (l *Ledger) PruneTransaction(txID utxo.TransactionID, pruneFutureCone bool)
- func (l *Ledger) SetTransactionInclusionTime(txID utxo.TransactionID, inclusionTime time.Time)
- func (l *Ledger) Shutdown()
- func (l *Ledger) StoreAndProcessTransaction(ctx context.Context, tx utxo.Transaction) (err error)
- type MockedInput
- type MockedOutput
- type MockedTransaction
- type MockedVM
- func (m *MockedVM) ExecuteTransaction(transaction utxo.Transaction, _ *utxo.Outputs, _ ...uint64) (outputs []utxo.Output, err error)
- func (m *MockedVM) ParseOutput(outputBytes []byte) (output utxo.Output, err error)
- func (m *MockedVM) ParseTransaction(transactionBytes []byte) (transaction utxo.Transaction, err error)
- func (m *MockedVM) ResolveInput(input utxo.Input) (outputID utxo.OutputID)
- type Option
- func WithCacheTimeProvider(cacheTimeProvider *database.CacheTimeProvider) (option Option)
- func WithConflictDAGOptions(conflictDAGOptions ...conflictdag.Option) (option Option)
- func WithConsumerCacheTime(consumerCacheTime time.Duration) (option Option)
- func WithOutputCacheTime(outputCacheTime time.Duration) (option Option)
- func WithOutputMetadataCacheTime(outputMetadataCacheTime time.Duration) (option Option)
- func WithStore(store kvstore.KVStore) (option Option)
- func WithTransactionCacheTime(transactionCacheTime time.Duration) (option Option)
- func WithTransactionMetadataCacheTime(transactionMetadataCacheTime time.Duration) (option Option)
- func WithVM(vm vm.VM) (option Option)
- type OutputMetadata
- func (o *OutputMetadata) AccessManaPledgeID() (id identity.ID)
- func (o *OutputMetadata) ConfirmationState() (confirmationState confirmation.State)
- func (o *OutputMetadata) ConfirmationStateTime() (confirmationState time.Time)
- func (o *OutputMetadata) ConflictIDs() (conflictIDs *set.AdvancedSet[utxo.TransactionID])
- func (o *OutputMetadata) ConsensusManaPledgeID() (id identity.ID)
- func (o *OutputMetadata) CreationTime() (creationTime time.Time)
- func (o *OutputMetadata) FirstConsumer() (firstConsumer utxo.TransactionID)
- func (o *OutputMetadata) IsSpent() (isSpent bool)
- func (o *OutputMetadata) RegisterBookedConsumer(consumer utxo.TransactionID) (isConflicting bool, consumerToFork utxo.TransactionID)
- func (o *OutputMetadata) SetAccessManaPledgeID(id identity.ID) (updated bool)
- func (o *OutputMetadata) SetConfirmationState(confirmationState confirmation.State) (modified bool)
- func (o *OutputMetadata) SetConflictIDs(conflictIDs *set.AdvancedSet[utxo.TransactionID]) (modified bool)
- func (o *OutputMetadata) SetConsensusManaPledgeID(id identity.ID) (updated bool)
- func (o *OutputMetadata) SetCreationTime(creationTime time.Time) (updated bool)
- type OutputWithMetadata
- func (o *OutputWithMetadata) AccessManaPledgeID() (consensuPledgeID identity.ID)
- func (o *OutputWithMetadata) ConsensusManaPledgeID() (consensuPledgeID identity.ID)
- func (o *OutputWithMetadata) CreationTime() (creationTime time.Time)
- func (o *OutputWithMetadata) FromBytes(data []byte) error
- func (o *OutputWithMetadata) FromObjectStorage(key, value []byte) error
- func (o *OutputWithMetadata) Output() (output utxo.Output)
- func (o *OutputWithMetadata) SetAccessManaPledgeID(accessPledgeID identity.ID)
- func (o *OutputWithMetadata) SetConsensusManaPledgeID(consensusPledgeID identity.ID)
- func (o *OutputWithMetadata) SetCreationTime(creationTime time.Time)
- func (o *OutputWithMetadata) SetOutput(output utxo.Output)
- func (o *OutputWithMetadata) String() string
- type OutputsMetadata
- func (o *OutputsMetadata) Add(output *OutputMetadata) (added bool)
- func (o *OutputsMetadata) ConflictIDs() (conflictIDs *set.AdvancedSet[utxo.TransactionID])
- func (o *OutputsMetadata) Filter(predicate func(outputMetadata *OutputMetadata) bool) (filtered *OutputsMetadata)
- func (o *OutputsMetadata) ForEach(callback func(outputMetadata *OutputMetadata) error) (err error)
- func (o *OutputsMetadata) Get(id utxo.OutputID) (outputMetadata *OutputMetadata, exists bool)
- func (o *OutputsMetadata) IDs() (ids utxo.OutputIDs)
- func (o *OutputsMetadata) String() (humanReadable string)
- type Snapshot
- type SnapshotHeader
- type Storage
- func (s *Storage) CachedConsumer(outputID utxo.OutputID, txID utxo.TransactionID, ...) (cachedConsumer *objectstorage.CachedObject[*Consumer])
- func (s *Storage) CachedConsumers(outputID utxo.OutputID) (cachedConsumers objectstorage.CachedObjects[*Consumer])
- func (s *Storage) CachedOutput(outputID utxo.OutputID, ...) (cachedOutput *objectstorage.CachedObject[utxo.Output])
- func (s *Storage) CachedOutputMetadata(outputID utxo.OutputID, ...) (cachedOutputMetadata *objectstorage.CachedObject[*OutputMetadata])
- func (s *Storage) CachedOutputs(outputIDs utxo.OutputIDs) (cachedOutputs objectstorage.CachedObjects[utxo.Output])
- func (s *Storage) CachedOutputsMetadata(outputIDs utxo.OutputIDs) (cachedOutputsMetadata objectstorage.CachedObjects[*OutputMetadata])
- func (s *Storage) CachedTransaction(transactionID utxo.TransactionID, ...) (cachedTransaction *objectstorage.CachedObject[utxo.Transaction])
- func (s *Storage) CachedTransactionMetadata(transactionID utxo.TransactionID, ...) (cachedTransactionMetadata *objectstorage.CachedObject[*TransactionMetadata])
- func (s *Storage) Prune() (err error)
- func (s *Storage) Shutdown()
- type TestFramework
- func (t *TestFramework) AllBooked(txAliases ...string) (allBooked bool)
- func (t *TestFramework) AssertBooked(expectedBookedMap map[string]bool)
- func (t *TestFramework) AssertConflictDAG(expectedParents map[string][]string)
- func (t *TestFramework) AssertConflictIDs(expectedConflicts map[string][]string)
- func (t *TestFramework) AssertConflicts(expectedConflictsAliases map[string][]string)
- func (t *TestFramework) ConflictIDs(txAliases ...string) (conflictIDs *set.AdvancedSet[utxo.TransactionID])
- func (t *TestFramework) ConsumeConflict(conflictID utxo.TransactionID, ...)
- func (t *TestFramework) ConsumeOutput(outputID utxo.OutputID, consumer func(output utxo.Output))
- func (t *TestFramework) ConsumeOutputMetadata(outputID utxo.OutputID, consumer func(outputMetadata *OutputMetadata))
- func (t *TestFramework) ConsumeTransactionMetadata(txID utxo.TransactionID, consumer func(txMetadata *TransactionMetadata))
- func (t *TestFramework) ConsumeTransactionOutputs(mockTx *MockedTransaction, consumer func(outputMetadata *OutputMetadata))
- func (t *TestFramework) CreateTransaction(txAlias string, outputCount uint16, inputAliases ...string)
- func (t *TestFramework) IssueTransaction(txAlias string) (err error)
- func (t *TestFramework) MockOutputFromTx(tx *MockedTransaction, outputIndex uint16) (mockedOutputID utxo.OutputID)
- func (t *TestFramework) OutputID(alias string) (outputID utxo.OutputID)
- func (t *TestFramework) Transaction(txAlias string) (tx *MockedTransaction)
- func (t *TestFramework) TransactionIDs(txAliases ...string) (txIDs utxo.TransactionIDs)
- func (t *TestFramework) WaitUntilAllTasksProcessed() (self *TestFramework)
- type TransactionAcceptedEvent
- type TransactionBookedEvent
- type TransactionConflictIDUpdatedEvent
- type TransactionForkedEvent
- type TransactionInclusionUpdatedEvent
- type TransactionInvalidEvent
- type TransactionMetadata
- func (t *TransactionMetadata) BookingTime() (bookingTime time.Time)
- func (t *TransactionMetadata) ConfirmationState() (confirmationState confirmation.State)
- func (t *TransactionMetadata) ConfirmationStateTime() (confirmationStateTime time.Time)
- func (t *TransactionMetadata) ConflictIDs() (conflictIDs *set.AdvancedSet[utxo.TransactionID])
- func (t *TransactionMetadata) InclusionTime() (inclusionTime time.Time)
- func (t *TransactionMetadata) IsBooked() (booked bool)
- func (t *TransactionMetadata) IsConflicting() (isConflicting bool)
- func (t *TransactionMetadata) OutputIDs() (outputIDs utxo.OutputIDs)
- func (t *TransactionMetadata) SetBooked(booked bool) (modified bool)
- func (t *TransactionMetadata) SetConfirmationState(confirmationState confirmation.State) (modified bool)
- func (t *TransactionMetadata) SetConflictIDs(conflictIDs *set.AdvancedSet[utxo.TransactionID]) (modified bool)
- func (t *TransactionMetadata) SetInclusionTime(inclusionTime time.Time) (updated bool, previousInclusionTime time.Time)
- func (t *TransactionMetadata) SetOutputIDs(outputIDs utxo.OutputIDs) (modified bool)
- type TransactionRejectedEvent
- type TransactionStoredEvent
- type Utils
- func (u *Utils) ConflictIDsInFutureCone(conflictIDs utxo.TransactionIDs) (conflictIDsInFutureCone utxo.TransactionIDs)
- func (u *Utils) ConflictingTransactions(transactionID utxo.TransactionID) (conflictingTransactions utxo.TransactionIDs)
- func (u *Utils) OutputConfirmationState(outputID utxo.OutputID) (confirmationState confirmation.State)
- func (u *Utils) ReferencedTransactions(tx utxo.Transaction) (transactionIDs utxo.TransactionIDs)
- func (u *Utils) ResolveInputs(inputs []utxo.Input) (outputIDs utxo.OutputIDs)
- func (u *Utils) TransactionConfirmationState(txID utxo.TransactionID) (confirmationState confirmation.State)
- func (u *Utils) TransactionConflictIDs(txID utxo.TransactionID) (conflictIDs *set.AdvancedSet[utxo.TransactionID], err error)
- func (u *Utils) UnprocessedConsumingTransactions(outputIDs utxo.OutputIDs) (consumingTransactions utxo.TransactionIDs)
- func (u *Utils) WalkConsumingTransactionID(entryPoints utxo.OutputIDs, ...)
- func (u *Utils) WalkConsumingTransactionMetadata(entryPoints utxo.OutputIDs, ...)
- func (u *Utils) WithTransactionAndMetadata(txID utxo.TransactionID, ...)
Constants ¶
const ( // PrefixTransactionStorage defines the storage prefix for the Transaction object storage. PrefixTransactionStorage byte = iota // PrefixTransactionMetadataStorage defines the storage prefix for the TransactionMetadata object storage. PrefixTransactionMetadataStorage // PrefixOutputStorage defines the storage prefix for the Output object storage. PrefixOutputStorage // PrefixOutputMetadataStorage defines the storage prefix for the OutputMetadata object storage. PrefixOutputMetadataStorage // PrefixConsumerStorage defines the storage prefix for the Consumer object storage. PrefixConsumerStorage )
Variables ¶
var ( // ErrTransactionInvalid is returned if a Transaction is found to be invalid. ErrTransactionInvalid = errors.New("transaction invalid") // ErrTransactionUnsolid is returned if a Transaction consumes unsolid Outputs.. ErrTransactionUnsolid = errors.New("transaction unsolid") )
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
type Consumer struct { model.StorableReferenceWithMetadata[Consumer, *Consumer, utxo.OutputID, utxo.TransactionID, consumer] `serix:"0"` }
Consumer represents the reference between an Output and its spending Transaction.
func NewConsumer ¶
func NewConsumer(consumedInput utxo.OutputID, transactionID utxo.TransactionID) (new *Consumer)
NewConsumer return a new Consumer reference from the named Output to the named Transaction.
func (*Consumer) ConsumedInput ¶
ConsumedInput returns the identifier of the Output that was spent.
func (*Consumer) IsBooked ¶
IsBooked returns a boolean flag that indicates whether the Consumer was completely booked.
func (*Consumer) SetBooked ¶
SetBooked sets a boolean flag that indicates whether the Consumer was completely booked.
func (*Consumer) TransactionID ¶
func (c *Consumer) TransactionID() (spendingTransaction utxo.TransactionID)
TransactionID returns the identifier of the spending Transaction.
type EpochDiff ¶
EpochDiff represents the collection of OutputWithMetadata objects that have been included in an epoch.
func NewEpochDiff ¶
func NewEpochDiff(spent []*OutputWithMetadata, created []*OutputWithMetadata) (new *EpochDiff)
NewEpochDiff returns a new EpochDiff object.
func (*EpochDiff) Created ¶
func (e *EpochDiff) Created() []*OutputWithMetadata
Created returns the outputs created for this epoch diff.
func (*EpochDiff) Spent ¶
func (e *EpochDiff) Spent() []*OutputWithMetadata
Spent returns the outputs spent for this epoch diff.
type Events ¶
type Events struct { // TransactionStored is an event that gets triggered whenever a new Transaction is stored. TransactionStored *event.Event[*TransactionStoredEvent] // TransactionBooked is an event that gets triggered whenever a Transaction is booked. TransactionBooked *event.Event[*TransactionBookedEvent] // TransactionInclusionUpdated is an event that gets triggered whenever the inclusion time of a Transaction changes. TransactionInclusionUpdated *event.Event[*TransactionInclusionUpdatedEvent] // TransactionAccepted is an event that gets triggered whenever a Transaction is confirmed. TransactionAccepted *event.Event[*TransactionAcceptedEvent] // TransactionRejected is an event that gets triggered whenever a Transaction is rejected. TransactionRejected *event.Event[*TransactionRejectedEvent] // TransactionForked is an event that gets triggered whenever a Transaction is forked. TransactionForked *event.Event[*TransactionForkedEvent] // TransactionConflictIDUpdated is an event that gets triggered whenever the Conflict of a Transaction is updated. TransactionConflictIDUpdated *event.Event[*TransactionConflictIDUpdatedEvent] // TransactionInvalid is an event that gets triggered whenever a Transaction is found to be invalid. TransactionInvalid *event.Event[*TransactionInvalidEvent] // Error is event that gets triggered whenever an error occurs while processing a Transaction. Error *event.Event[error] }
Events is a container that acts as a dictionary for the existing events of a Ledger.
type Ledger ¶
type Ledger struct { // Events is a dictionary for Ledger related events. Events *Events // Storage is a dictionary for storage related API endpoints. Storage *Storage // Utils is a dictionary for utility methods that simplify the interaction with the Ledger. Utils *Utils // ConflictDAG is a reference to the ConflictDAG that is used by this Ledger. ConflictDAG *conflictdag.ConflictDAG[utxo.TransactionID, utxo.OutputID] // contains filtered or unexported fields }
Ledger is an implementation of a "realities-ledger" that manages Outputs according to the principles of the quadruple-entry accounting. It acts as a wrapper for the underlying components and exposes the public facing API.
func (*Ledger) CheckTransaction ¶
CheckTransaction checks the validity of a Transaction.
func (*Ledger) LoadEpochDiff ¶ added in v0.9.5
LoadEpochDiffs loads EpochDiffs from a snapshot file to the storage.
func (*Ledger) LoadOutputWithMetadatas ¶
func (l *Ledger) LoadOutputWithMetadatas(outputsWithMetadatas []*OutputWithMetadata)
LoadOutputWithMetadatas loads OutputWithMetadatas from a snapshot file to the storage.
func (*Ledger) PruneTransaction ¶
func (l *Ledger) PruneTransaction(txID utxo.TransactionID, pruneFutureCone bool)
PruneTransaction removes a Transaction from the Ledger (e.g. after it was orphaned or found to be invalid). If the pruneFutureCone flag is true, then we do not just remove the named Transaction but also its future cone.
func (*Ledger) SetTransactionInclusionTime ¶
func (l *Ledger) SetTransactionInclusionTime(txID utxo.TransactionID, inclusionTime time.Time)
SetTransactionInclusionTime sets the inclusion timestamp of a Transaction.
func (*Ledger) Shutdown ¶
func (l *Ledger) Shutdown()
Shutdown shuts down the stateful elements of the Ledger (the Storage and the ConflictDAG).
func (*Ledger) StoreAndProcessTransaction ¶
StoreAndProcessTransaction stores and processes the given Transaction.
type MockedInput ¶
type MockedInput struct { // outputID contains the referenced OutputID. OutputID utxo.OutputID `serix:"0"` }
MockedInput is a mocked entity that allows to "address" which Outputs are supposed to be used by a Transaction.
func NewMockedInput ¶
func NewMockedInput(outputID utxo.OutputID) (new *MockedInput)
NewMockedInput creates a new MockedInput from an utxo.OutputID.
func (*MockedInput) String ¶
func (m *MockedInput) String() (humanReadable string)
String returns a human-readable version of the MockedInput.
type MockedOutput ¶
type MockedOutput struct { model.Storable[utxo.OutputID, MockedOutput, *MockedOutput, mockedOutput] `serix:"0"` }
MockedOutput is the container for the data produced by executing a MockedTransaction.
func NewMockedOutput ¶
func NewMockedOutput(txID utxo.TransactionID, index uint16) (out *MockedOutput)
NewMockedOutput creates a new MockedOutput based on the utxo.TransactionID and its index within the MockedTransaction.
type MockedTransaction ¶
type MockedTransaction struct { model.Storable[utxo.TransactionID, MockedTransaction, *MockedTransaction, mockedTransaction] `serix:"0"` }
MockedTransaction is the type that is used to describe instructions how to modify the ledger state for MockedVM.
func NewMockedTransaction ¶
func NewMockedTransaction(inputs []*MockedInput, outputCount uint16) (tx *MockedTransaction)
NewMockedTransaction creates a new MockedTransaction with the given inputs and specified outputCount. A unique essence is simulated by an atomic counter, incremented globally for each MockedTransaction created.
func (*MockedTransaction) Inputs ¶
func (m *MockedTransaction) Inputs() (inputs []utxo.Input)
Inputs returns the inputs of the Transaction.
type MockedVM ¶
type MockedVM struct{}
MockedVM is an implementation of UTXO-based VMs for testing purposes.
func (*MockedVM) ExecuteTransaction ¶
func (m *MockedVM) ExecuteTransaction(transaction utxo.Transaction, _ *utxo.Outputs, _ ...uint64) (outputs []utxo.Output, err error)
ExecuteTransaction executes the Transaction and determines the Outputs from the given Inputs. It returns an error if the execution fails.
func (*MockedVM) ParseOutput ¶
ParseOutput un-serializes an Output from the given sequence of bytes.
func (*MockedVM) ParseTransaction ¶
func (m *MockedVM) ParseTransaction(transactionBytes []byte) (transaction utxo.Transaction, err error)
ParseTransaction un-serializes a Transaction from the given sequence of bytes.
type Option ¶
type Option func(*options)
Option represents the return type of optional parameters that can be handed into the constructor of the Ledger to configure its behavior.
func WithCacheTimeProvider ¶
func WithCacheTimeProvider(cacheTimeProvider *database.CacheTimeProvider) (option Option)
WithCacheTimeProvider is an Option for the Ledger that allows to configure which CacheTimeProvider is supposed to be used.
func WithConflictDAGOptions ¶
func WithConflictDAGOptions(conflictDAGOptions ...conflictdag.Option) (option Option)
WithConflictDAGOptions is an Option for the Ledger that allows to configure the options for the ConflictDAG
func WithConsumerCacheTime ¶
WithConsumerCacheTime is an Option for the Ledger that allows to configure how long Consumer objects stay cached after they have been released.
func WithOutputCacheTime ¶
WithOutputCacheTime is an Option for the Ledger that allows to configure how long Output objects stay cached after they have been released.
func WithOutputMetadataCacheTime ¶
WithOutputMetadataCacheTime is an Option for the Ledger that allows to configure how long OutputMetadata objects stay cached after they have been released.
func WithStore ¶
WithStore is an Option for the Ledger that allows to configure which KVStore is supposed to be used to persist data (the default option is to use a MapDB).
func WithTransactionCacheTime ¶
WithTransactionCacheTime is an Option for the Ledger that allows to configure how long Transaction objects stay cached after they have been released.
func WithTransactionMetadataCacheTime ¶
WithTransactionMetadataCacheTime is an Option for the Ledger that allows to configure how long TransactionMetadata objects stay cached after they have been released.
type OutputMetadata ¶
type OutputMetadata struct { model.Storable[utxo.OutputID, OutputMetadata, *OutputMetadata, outputMetadata] `serix:"0"` }
OutputMetadata represents a container for additional information about an Output.
func NewOutputMetadata ¶
func NewOutputMetadata(outputID utxo.OutputID) (new *OutputMetadata)
NewOutputMetadata returns new OutputMetadata for the given OutputID.
func (*OutputMetadata) AccessManaPledgeID ¶
func (o *OutputMetadata) AccessManaPledgeID() (id identity.ID)
AccessManaPledgeID returns the identifier of the node that received the access mana pledge.
func (*OutputMetadata) ConfirmationState ¶
func (o *OutputMetadata) ConfirmationState() (confirmationState confirmation.State)
ConfirmationState returns the confirmation state of the Output.
func (*OutputMetadata) ConfirmationStateTime ¶
func (o *OutputMetadata) ConfirmationStateTime() (confirmationState time.Time)
ConfirmationStateTime returns the last time the ConfirmationState was updated.
func (*OutputMetadata) ConflictIDs ¶
func (o *OutputMetadata) ConflictIDs() (conflictIDs *set.AdvancedSet[utxo.TransactionID])
ConflictIDs returns the conflicting ConflictIDs that the Output depends on.
func (*OutputMetadata) ConsensusManaPledgeID ¶
func (o *OutputMetadata) ConsensusManaPledgeID() (id identity.ID)
ConsensusManaPledgeID returns the identifier of the node that received the consensus mana pledge.
func (*OutputMetadata) CreationTime ¶
func (o *OutputMetadata) CreationTime() (creationTime time.Time)
CreationTime returns the creation time of the Output.
func (*OutputMetadata) FirstConsumer ¶
func (o *OutputMetadata) FirstConsumer() (firstConsumer utxo.TransactionID)
FirstConsumer returns the first Transaction that ever spent the Output.
func (*OutputMetadata) IsSpent ¶
func (o *OutputMetadata) IsSpent() (isSpent bool)
IsSpent returns true if the Output has been spent.
func (*OutputMetadata) RegisterBookedConsumer ¶
func (o *OutputMetadata) RegisterBookedConsumer(consumer utxo.TransactionID) (isConflicting bool, consumerToFork utxo.TransactionID)
RegisterBookedConsumer registers a booked consumer and checks if it is conflicting with another consumer that wasn't forked, yet.
func (*OutputMetadata) SetAccessManaPledgeID ¶
func (o *OutputMetadata) SetAccessManaPledgeID(id identity.ID) (updated bool)
SetAccessManaPledgeID sets the identifier of the node that received the access mana pledge.
func (*OutputMetadata) SetConfirmationState ¶
func (o *OutputMetadata) SetConfirmationState(confirmationState confirmation.State) (modified bool)
SetConfirmationState sets the confirmation state of the Output.
func (*OutputMetadata) SetConflictIDs ¶
func (o *OutputMetadata) SetConflictIDs(conflictIDs *set.AdvancedSet[utxo.TransactionID]) (modified bool)
SetConflictIDs sets the conflicting ConflictIDs that this Transaction depends on.
func (*OutputMetadata) SetConsensusManaPledgeID ¶
func (o *OutputMetadata) SetConsensusManaPledgeID(id identity.ID) (updated bool)
SetConsensusManaPledgeID sets the identifier of the node that received the consensus mana pledge.
func (*OutputMetadata) SetCreationTime ¶
func (o *OutputMetadata) SetCreationTime(creationTime time.Time) (updated bool)
SetCreationTime sets the creation time of the Output.
type OutputWithMetadata ¶
type OutputWithMetadata struct { model.Storable[utxo.OutputID, OutputWithMetadata, *OutputWithMetadata, outputWithMetadataModel] `serix:"0"` }
OutputWithMetadata represents an Output with its associated metadata fields that are needed for epoch management.
func NewOutputWithMetadata ¶
func NewOutputWithMetadata(outputID utxo.OutputID, output utxo.Output, creationTime time.Time, consensusManaPledgeID, accessManaPledgeID identity.ID) (new *OutputWithMetadata)
NewOutputWithMetadata returns a new OutputWithMetadata object.
func (*OutputWithMetadata) AccessManaPledgeID ¶
func (o *OutputWithMetadata) AccessManaPledgeID() (consensuPledgeID identity.ID)
AccessManaPledgeID returns the access pledge id of the output.
func (*OutputWithMetadata) ConsensusManaPledgeID ¶
func (o *OutputWithMetadata) ConsensusManaPledgeID() (consensuPledgeID identity.ID)
ConsensusManaPledgeID returns the consensus pledge id of the output.
func (*OutputWithMetadata) CreationTime ¶
func (o *OutputWithMetadata) CreationTime() (creationTime time.Time)
CreationTime returns the CreationTime field.
func (*OutputWithMetadata) FromBytes ¶
func (o *OutputWithMetadata) FromBytes(data []byte) error
FromBytes unmarshals an OutputWithMetadata from a sequence of bytes.
func (*OutputWithMetadata) FromObjectStorage ¶
func (o *OutputWithMetadata) FromObjectStorage(key, value []byte) error
FromObjectStorage creates an OutputWithMetadata from sequences of key and bytes.
func (*OutputWithMetadata) Output ¶
func (o *OutputWithMetadata) Output() (output utxo.Output)
Output returns the Output field.
func (*OutputWithMetadata) SetAccessManaPledgeID ¶
func (o *OutputWithMetadata) SetAccessManaPledgeID(accessPledgeID identity.ID)
SetAccessManaPledgeID sets the access pledge id of the output.
func (*OutputWithMetadata) SetConsensusManaPledgeID ¶
func (o *OutputWithMetadata) SetConsensusManaPledgeID(consensusPledgeID identity.ID)
SetConsensusManaPledgeID sets the consensus pledge id of the output.
func (*OutputWithMetadata) SetCreationTime ¶
func (o *OutputWithMetadata) SetCreationTime(creationTime time.Time)
SetCreationTime sets the CreationTime field.
func (*OutputWithMetadata) SetOutput ¶
func (o *OutputWithMetadata) SetOutput(output utxo.Output)
SetOutput sets the Output field.
func (*OutputWithMetadata) String ¶
func (o *OutputWithMetadata) String() string
String returns a human-readable version of the OutputWithMetadata.
type OutputsMetadata ¶
type OutputsMetadata struct { // OrderedMap is the underlying data structure that holds the OutputMetadata objects. orderedmap.OrderedMap[utxo.OutputID, *OutputMetadata] `serix:"0"` }
OutputsMetadata represents a collection of OutputMetadata objects indexed by their OutputID.
func NewOutputsMetadata ¶
func NewOutputsMetadata(outputsMetadata ...*OutputMetadata) (new *OutputsMetadata)
NewOutputsMetadata returns a new OutputMetadata collection with the given elements.
func (*OutputsMetadata) Add ¶
func (o *OutputsMetadata) Add(output *OutputMetadata) (added bool)
Add adds the given OutputMetadata object to the collection.
func (*OutputsMetadata) ConflictIDs ¶
func (o *OutputsMetadata) ConflictIDs() (conflictIDs *set.AdvancedSet[utxo.TransactionID])
ConflictIDs returns a union of all ConflictIDs of the contained OutputMetadata objects.
func (*OutputsMetadata) Filter ¶
func (o *OutputsMetadata) Filter(predicate func(outputMetadata *OutputMetadata) bool) (filtered *OutputsMetadata)
func (*OutputsMetadata) ForEach ¶
func (o *OutputsMetadata) ForEach(callback func(outputMetadata *OutputMetadata) error) (err error)
ForEach executes the callback for each element in the collection (it aborts if the callback returns an error).
func (*OutputsMetadata) Get ¶
func (o *OutputsMetadata) Get(id utxo.OutputID) (outputMetadata *OutputMetadata, exists bool)
Get returns the OutputMetadata object for the given OutputID.
func (*OutputsMetadata) IDs ¶
func (o *OutputsMetadata) IDs() (ids utxo.OutputIDs)
IDs returns the identifiers of the stored OutputMetadata objects.
func (*OutputsMetadata) String ¶
func (o *OutputsMetadata) String() (humanReadable string)
String returns a human-readable version of the OutputsMetadata.
type Snapshot ¶
type Snapshot struct { Header *SnapshotHeader `serix:"0"` OutputsWithMetadata []*OutputWithMetadata `serix:"1,lengthPrefixType=uint32"` EpochDiffs map[epoch.Index]*EpochDiff `serix:"2,lengthPrefixType=uint32"` EpochActiveNodes epoch.SnapshotEpochActivity `serix:"3,lengthPrefixType=uint32"` }
Snapshot represents a snapshot of the current ledger state.
func NewSnapshot ¶
func NewSnapshot(outputsWithMetadata []*OutputWithMetadata, activeNodes epoch.SnapshotEpochActivity) (new *Snapshot)
NewSnapshot creates a new Snapshot from the given details.
type SnapshotHeader ¶
type SnapshotHeader struct { OutputWithMetadataCount uint64 `serix:"0"` FullEpochIndex epoch.Index `serix:"1"` DiffEpochIndex epoch.Index `serix:"2"` LatestECRecord *epoch.ECRecord `serix:"3"` }
SnapshotHeader represents the info of a snapshot.
func (*SnapshotHeader) String ¶
func (h *SnapshotHeader) String() (humanReadable string)
String returns a human-readable version of the SnapshotHeader.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage is a Ledger component that bundles the storage related API.
func (*Storage) CachedConsumer ¶
func (s *Storage) CachedConsumer(outputID utxo.OutputID, txID utxo.TransactionID, computeIfAbsentCallback ...func(outputID utxo.OutputID, txID utxo.TransactionID) *Consumer) (cachedConsumer *objectstorage.CachedObject[*Consumer])
CachedConsumer retrieves the CachedObject representing the named Consumer. The optional computeIfAbsentCallback can be used to dynamically initialize a non-existing Consumer.
func (*Storage) CachedConsumers ¶
func (s *Storage) CachedConsumers(outputID utxo.OutputID) (cachedConsumers objectstorage.CachedObjects[*Consumer])
CachedConsumers retrieves the CachedObjects containing the named Consumers.
func (*Storage) CachedOutput ¶
func (s *Storage) CachedOutput(outputID utxo.OutputID, computeIfAbsentCallback ...func(outputID utxo.OutputID) utxo.Output) (cachedOutput *objectstorage.CachedObject[utxo.Output])
CachedOutput retrieves the CachedObject representing the named Output. The optional computeIfAbsentCallback can be used to dynamically initialize a non-existing Output.
func (*Storage) CachedOutputMetadata ¶
func (s *Storage) CachedOutputMetadata(outputID utxo.OutputID, computeIfAbsentCallback ...func(outputID utxo.OutputID) *OutputMetadata) (cachedOutputMetadata *objectstorage.CachedObject[*OutputMetadata])
CachedOutputMetadata retrieves the CachedObject representing the named OutputMetadata. The optional computeIfAbsentCallback can be used to dynamically initialize a non-existing OutputMetadata.
func (*Storage) CachedOutputs ¶
func (s *Storage) CachedOutputs(outputIDs utxo.OutputIDs) (cachedOutputs objectstorage.CachedObjects[utxo.Output])
CachedOutputs retrieves the CachedObjects containing the named Outputs.
func (*Storage) CachedOutputsMetadata ¶
func (s *Storage) CachedOutputsMetadata(outputIDs utxo.OutputIDs) (cachedOutputsMetadata objectstorage.CachedObjects[*OutputMetadata])
CachedOutputsMetadata retrieves the CachedObjects containing the named OutputMetadata.
func (*Storage) CachedTransaction ¶
func (s *Storage) CachedTransaction(transactionID utxo.TransactionID, computeIfAbsentCallback ...func(transactionID utxo.TransactionID) utxo.Transaction) (cachedTransaction *objectstorage.CachedObject[utxo.Transaction])
CachedTransaction retrieves the CachedObject representing the named Transaction. The optional computeIfAbsentCallback can be used to dynamically initialize a non-existing Transaction.
func (*Storage) CachedTransactionMetadata ¶
func (s *Storage) CachedTransactionMetadata(transactionID utxo.TransactionID, computeIfAbsentCallback ...func(transactionID utxo.TransactionID) *TransactionMetadata) (cachedTransactionMetadata *objectstorage.CachedObject[*TransactionMetadata])
CachedTransactionMetadata retrieves the CachedObject representing the named TransactionMetadata. The optional computeIfAbsentCallback can be used to dynamically initialize a non-existing TransactionMetadata.
type TestFramework ¶
type TestFramework struct {
// contains filtered or unexported fields
}
TestFramework provides common testing functionality for the ledger package. As such, it helps to easily build an UTXO-DAG by specifying transactions outputs/inputs via aliases. It makes use of a simplified MockedVM, with MockedTransaction, MockedOutput and MockedInput.
func NewTestFramework ¶
func NewTestFramework(t *testing.T, options ...Option) (new *TestFramework)
NewTestFramework creates a new instance of the TestFramework with one default output "Genesis" which has to be consumed by the first transaction.
func (*TestFramework) AllBooked ¶
func (t *TestFramework) AllBooked(txAliases ...string) (allBooked bool)
AllBooked returns whether all given transactions are booked.
func (*TestFramework) AssertBooked ¶
func (t *TestFramework) AssertBooked(expectedBookedMap map[string]bool)
AssertBooked asserts the booking status of all given transactions.
func (*TestFramework) AssertConflictDAG ¶
func (t *TestFramework) AssertConflictDAG(expectedParents map[string][]string)
AssertConflictDAG asserts the structure of the conflict DAG as specified in expectedParents. "conflict3": {"conflict1","conflict2"} asserts that "conflict3" should have "conflict1" and "conflict2" as parents. It also verifies the reverse mapping, that there is a child reference (conflictdag.ChildConflict) from "conflict1"->"conflict3" and "conflict2"->"conflict3".
func (*TestFramework) AssertConflictIDs ¶
func (t *TestFramework) AssertConflictIDs(expectedConflicts map[string][]string)
AssertConflictIDs asserts that the given transactions and their outputs are booked into the specified conflicts.
func (*TestFramework) AssertConflicts ¶
func (t *TestFramework) AssertConflicts(expectedConflictsAliases map[string][]string)
AssertConflicts asserts conflict membership from conflictID -> conflicts but also the reverse mapping conflict -> conflictIDs. expectedConflictAliases should be specified as "output.0": {"conflict1", "conflict2"}
func (*TestFramework) ConflictIDs ¶
func (t *TestFramework) ConflictIDs(txAliases ...string) (conflictIDs *set.AdvancedSet[utxo.TransactionID])
ConflictIDs gets all conflictdag.ConflictIDs given by txAliases. Panics if an alias doesn't exist.
func (*TestFramework) ConsumeConflict ¶
func (t *TestFramework) ConsumeConflict(conflictID utxo.TransactionID, consumer func(conflict *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]))
ConsumeConflict loads and consumes conflictdag.Conflict. Asserts that the loaded entity exists.
func (*TestFramework) ConsumeOutput ¶
func (t *TestFramework) ConsumeOutput(outputID utxo.OutputID, consumer func(output utxo.Output))
ConsumeOutput loads and consumes Output. Asserts that the loaded entity exists.
func (*TestFramework) ConsumeOutputMetadata ¶
func (t *TestFramework) ConsumeOutputMetadata(outputID utxo.OutputID, consumer func(outputMetadata *OutputMetadata))
ConsumeOutputMetadata loads and consumes OutputMetadata. Asserts that the loaded entity exists.
func (*TestFramework) ConsumeTransactionMetadata ¶
func (t *TestFramework) ConsumeTransactionMetadata(txID utxo.TransactionID, consumer func(txMetadata *TransactionMetadata))
ConsumeTransactionMetadata loads and consumes TransactionMetadata. Asserts that the loaded entity exists.
func (*TestFramework) ConsumeTransactionOutputs ¶
func (t *TestFramework) ConsumeTransactionOutputs(mockTx *MockedTransaction, consumer func(outputMetadata *OutputMetadata))
ConsumeTransactionOutputs loads and consumes all OutputMetadata of the given Transaction. Asserts that the loaded entities exists.
func (*TestFramework) CreateTransaction ¶
func (t *TestFramework) CreateTransaction(txAlias string, outputCount uint16, inputAliases ...string)
CreateTransaction creates a transaction with the given alias and outputCount. Inputs for the transaction are specified by their aliases where <txAlias.outputCount>. Panics if an input does not exist.
func (*TestFramework) IssueTransaction ¶
func (t *TestFramework) IssueTransaction(txAlias string) (err error)
IssueTransaction issues the transaction given by txAlias.
func (*TestFramework) MockOutputFromTx ¶
func (t *TestFramework) MockOutputFromTx(tx *MockedTransaction, outputIndex uint16) (mockedOutputID utxo.OutputID)
MockOutputFromTx creates an utxo.OutputID from a given MockedTransaction and outputIndex.
func (*TestFramework) OutputID ¶
func (t *TestFramework) OutputID(alias string) (outputID utxo.OutputID)
OutputID gets the created utxo.OutputID by the given alias. Panics if it doesn't exist.
func (*TestFramework) Transaction ¶
func (t *TestFramework) Transaction(txAlias string) (tx *MockedTransaction)
Transaction gets the created MockedTransaction by the given alias. Panics if it doesn't exist.
func (*TestFramework) TransactionIDs ¶
func (t *TestFramework) TransactionIDs(txAliases ...string) (txIDs utxo.TransactionIDs)
TransactionIDs gets all MockedTransaction given by txAliases. Panics if an alias doesn't exist.
func (*TestFramework) WaitUntilAllTasksProcessed ¶
func (t *TestFramework) WaitUntilAllTasksProcessed() (self *TestFramework)
type TransactionAcceptedEvent ¶
type TransactionAcceptedEvent struct { // TransactionID contains the identifier of the confirmed Transaction. TransactionID utxo.TransactionID }
TransactionAcceptedEvent is a container that acts as a dictionary for the TransactionAccepted event related parameters.
type TransactionBookedEvent ¶
type TransactionBookedEvent struct { // TransactionID contains the identifier of the booked Transaction. TransactionID utxo.TransactionID // Outputs contains the set of Outputs that this Transaction created. Outputs *utxo.Outputs // Context contains a Context provided by the caller that triggered this event. Context context.Context }
TransactionBookedEvent is a container that acts as a dictionary for the TransactionBooked event related parameters.
type TransactionConflictIDUpdatedEvent ¶
type TransactionConflictIDUpdatedEvent struct { // TransactionID contains the identifier of the Transaction whose ConflictIDs were updated. TransactionID utxo.TransactionID // AddedConflictID contains the identifier of the Conflict that was added to the ConflictIDs of the Transaction. AddedConflictID utxo.TransactionID // RemovedConflictIDs contains the set of the ConflictIDs that were removed while updating the Transaction. RemovedConflictIDs *set.AdvancedSet[utxo.TransactionID] // Context contains a Context provided by the caller that triggered this event. Context context.Context }
TransactionConflictIDUpdatedEvent is a container that acts as a dictionary for the TransactionConflictIDUpdated event related parameters.
type TransactionForkedEvent ¶
type TransactionForkedEvent struct { // TransactionID contains the identifier of the forked Transaction. TransactionID utxo.TransactionID // ParentConflicts contains the set of ConflictIDs that form the parent Conflicts for the newly forked Transaction. ParentConflicts *set.AdvancedSet[utxo.TransactionID] // Context contains a Context provided by the caller that triggered this event. Context context.Context }
TransactionForkedEvent is a container that acts as a dictionary for the TransactionForked event related parameters.
type TransactionInclusionUpdatedEvent ¶
type TransactionInclusionUpdatedEvent struct { // TransactionID contains the identifier of the booked Transaction. TransactionID utxo.TransactionID // InclusionTime contains the InclusionTime after it was updated. InclusionTime time.Time // PreviousInclusionTime contains the InclusionTime before it was updated. PreviousInclusionTime time.Time }
TransactionInclusionUpdatedEvent is a container that acts as a dictionary for the TransactionInclusionUpdated event related parameters.
type TransactionInvalidEvent ¶
type TransactionInvalidEvent struct { // TransactionID contains the identifier of the Transaction that was found to be invalid. TransactionID utxo.TransactionID // Reason contains the error that caused the Transaction to be considered invalid. Reason error // Context contains a Context provided by the caller that triggered this event. Context context.Context }
TransactionInvalidEvent is a container that acts as a dictionary for the TransactionInvalid event related parameters.
type TransactionMetadata ¶
type TransactionMetadata struct { model.Storable[utxo.TransactionID, TransactionMetadata, *TransactionMetadata, transactionMetadata] `serix:"0"` }
TransactionMetadata represents a container for additional information about a Transaction.
func NewTransactionMetadata ¶
func NewTransactionMetadata(txID utxo.TransactionID) (new *TransactionMetadata)
NewTransactionMetadata returns new TransactionMetadata for the given TransactionID.
func (*TransactionMetadata) BookingTime ¶
func (t *TransactionMetadata) BookingTime() (bookingTime time.Time)
BookingTime returns the time when the Transaction was booked.
func (*TransactionMetadata) ConfirmationState ¶
func (t *TransactionMetadata) ConfirmationState() (confirmationState confirmation.State)
ConfirmationState returns the confirmation status of the Transaction.
func (*TransactionMetadata) ConfirmationStateTime ¶
func (t *TransactionMetadata) ConfirmationStateTime() (confirmationStateTime time.Time)
ConfirmationStateTime returns the last time the ConfirmationState was updated.
func (*TransactionMetadata) ConflictIDs ¶
func (t *TransactionMetadata) ConflictIDs() (conflictIDs *set.AdvancedSet[utxo.TransactionID])
ConflictIDs returns the conflicting ConflictIDs that the Transaction depends on.
func (*TransactionMetadata) InclusionTime ¶
func (t *TransactionMetadata) InclusionTime() (inclusionTime time.Time)
InclusionTime returns the inclusion time of the Transaction.
func (*TransactionMetadata) IsBooked ¶
func (t *TransactionMetadata) IsBooked() (booked bool)
IsBooked returns a boolean flag indicating whether the Transaction has been booked.
func (*TransactionMetadata) IsConflicting ¶
func (t *TransactionMetadata) IsConflicting() (isConflicting bool)
IsConflicting returns true if the Transaction is conflicting with another Transaction (is a Conflict).
func (*TransactionMetadata) OutputIDs ¶
func (t *TransactionMetadata) OutputIDs() (outputIDs utxo.OutputIDs)
OutputIDs returns the identifiers of the Outputs that the Transaction created.
func (*TransactionMetadata) SetBooked ¶
func (t *TransactionMetadata) SetBooked(booked bool) (modified bool)
SetBooked sets a boolean flag indicating whether the Transaction has been booked.
func (*TransactionMetadata) SetConfirmationState ¶
func (t *TransactionMetadata) SetConfirmationState(confirmationState confirmation.State) (modified bool)
SetConfirmationState sets the confirmation status of the Transaction.
func (*TransactionMetadata) SetConflictIDs ¶
func (t *TransactionMetadata) SetConflictIDs(conflictIDs *set.AdvancedSet[utxo.TransactionID]) (modified bool)
SetConflictIDs sets the conflicting ConflictIDs that this Transaction depends on.
func (*TransactionMetadata) SetInclusionTime ¶
func (t *TransactionMetadata) SetInclusionTime(inclusionTime time.Time) (updated bool, previousInclusionTime time.Time)
SetInclusionTime sets the inclusion time of the Transaction.
func (*TransactionMetadata) SetOutputIDs ¶
func (t *TransactionMetadata) SetOutputIDs(outputIDs utxo.OutputIDs) (modified bool)
SetOutputIDs sets the identifiers of the Outputs that the Transaction created.
type TransactionRejectedEvent ¶
type TransactionRejectedEvent struct { // TransactionID contains the identifier of the rejected Transaction. TransactionID utxo.TransactionID }
TransactionRejectedEvent is a container that acts as a dictionary for the TransactionRejected event related parameters.
type TransactionStoredEvent ¶
type TransactionStoredEvent struct { // TransactionID contains the identifier of the stored Transaction. TransactionID utxo.TransactionID }
TransactionStoredEvent is a container that acts as a dictionary for the TransactionStored event related parameters.
type Utils ¶
type Utils struct {
// contains filtered or unexported fields
}
Utils is a Ledger component that bundles utility related API to simplify common interactions with the Ledger.
func (*Utils) ConflictIDsInFutureCone ¶
func (u *Utils) ConflictIDsInFutureCone(conflictIDs utxo.TransactionIDs) (conflictIDsInFutureCone utxo.TransactionIDs)
func (*Utils) ConflictingTransactions ¶
func (u *Utils) ConflictingTransactions(transactionID utxo.TransactionID) (conflictingTransactions utxo.TransactionIDs)
ConflictingTransactions returns the TransactionIDs that are conflicting with the given Transaction.
func (*Utils) OutputConfirmationState ¶
func (u *Utils) OutputConfirmationState(outputID utxo.OutputID) (confirmationState confirmation.State)
OutputConfirmationState returns the ConfirmationState of the Output.
func (*Utils) ReferencedTransactions ¶
func (u *Utils) ReferencedTransactions(tx utxo.Transaction) (transactionIDs utxo.TransactionIDs)
func (*Utils) ResolveInputs ¶
ResolveInputs returns the OutputIDs that were referenced by the given Inputs.
func (*Utils) TransactionConfirmationState ¶
func (u *Utils) TransactionConfirmationState(txID utxo.TransactionID) (confirmationState confirmation.State)
TransactionConfirmationState returns the ConfirmationState of the Transaction with the given TransactionID.
func (*Utils) TransactionConflictIDs ¶
func (u *Utils) TransactionConflictIDs(txID utxo.TransactionID) (conflictIDs *set.AdvancedSet[utxo.TransactionID], err error)
TransactionConflictIDs returns the ConflictIDs of the given TransactionID.
func (*Utils) UnprocessedConsumingTransactions ¶
func (u *Utils) UnprocessedConsumingTransactions(outputIDs utxo.OutputIDs) (consumingTransactions utxo.TransactionIDs)
UnprocessedConsumingTransactions returns the unprocessed consuming transactions of the named OutputIDs.
func (*Utils) WalkConsumingTransactionID ¶
func (u *Utils) WalkConsumingTransactionID(entryPoints utxo.OutputIDs, callback func(consumingTxID utxo.TransactionID, walker *walker.Walker[utxo.OutputID]))
WalkConsumingTransactionID walks over the TransactionIDs that consume the named OutputIDs.
func (*Utils) WalkConsumingTransactionMetadata ¶
func (u *Utils) WalkConsumingTransactionMetadata(entryPoints utxo.OutputIDs, callback func(txMetadata *TransactionMetadata, walker *walker.Walker[utxo.OutputID]))
WalkConsumingTransactionMetadata walks over the transactions that consume the named OutputIDs and calls the callback with their corresponding TransactionMetadata.
func (*Utils) WithTransactionAndMetadata ¶
func (u *Utils) WithTransactionAndMetadata(txID utxo.TransactionID, callback func(tx utxo.Transaction, txMetadata *TransactionMetadata))
WithTransactionAndMetadata walks over the transactions that consume the named OutputIDs and calls the callback with their corresponding Transaction and TransactionMetadata.