ledger

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: Apache-2.0, BSD-2-Clause Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func (c *Consumer) ConsumedInput() (outputID utxo.OutputID)

ConsumedInput returns the identifier of the Output that was spent.

func (*Consumer) IsBooked

func (c *Consumer) IsBooked() (processed bool)

IsBooked returns a boolean flag that indicates whether the Consumer was completely booked.

func (*Consumer) SetBooked

func (c *Consumer) SetBooked() (updated bool)

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

	// TransactionConfirmed is an event that gets triggered whenever a Transaction is confirmed.
	TransactionConfirmed *event.Event[*TransactionConfirmedEvent]

	// 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]

	// TransactionBranchIDUpdated is an event that gets triggered whenever the Branch of a Transaction is updated.
	TransactionBranchIDUpdated *event.Event[*TransactionBranchIDUpdatedEvent]

	// 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 New

func New(options ...Option) (ledger *Ledger)

New returns a new Ledger from the given options.

func (*Ledger) CheckTransaction

func (l *Ledger) CheckTransaction(ctx context.Context, tx utxo.Transaction) (err error)

CheckTransaction checks the validity of a Transaction.

func (*Ledger) LoadSnapshot

func (l *Ledger) LoadSnapshot(snapshot *Snapshot)

LoadSnapshot loads a snapshot of the Ledger from the given snapshot.

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

func (l *Ledger) StoreAndProcessTransaction(ctx context.Context, tx utxo.Transaction) (err error)

StoreAndProcessTransaction stores and processes the given Transaction.

func (*Ledger) TakeSnapshot

func (l *Ledger) TakeSnapshot() (snapshot *Snapshot)

TakeSnapshot returns a snapshot of the Ledger state.

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 NewMockedVM

func NewMockedVM() *MockedVM

NewMockedVM creates a new MockedVM.

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

func (m *MockedVM) ParseOutput(outputBytes []byte) (output utxo.Output, err error)

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.

func (*MockedVM) ResolveInput

func (m *MockedVM) ResolveInput(input utxo.Input) (outputID utxo.OutputID)

ResolveInput translates the Input into an OutputID.

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(branchDAGOptions ...conflictdag.Option) (option Option)

WithConflictDAGOptions is an Option for the Ledger that allows to configure the options for the ConflictDAG

func WithConsumerCacheTime

func WithConsumerCacheTime(consumerCacheTime time.Duration) (option Option)

WithConsumerCacheTime is an Option for the Ledger that allows to configure how long Consumer objects stay cached after they have been released.

func WithOutputCacheTime

func WithOutputCacheTime(outputCacheTime time.Duration) (option Option)

WithOutputCacheTime is an Option for the Ledger that allows to configure how long Output objects stay cached after they have been released.

func WithOutputMetadataCacheTime

func WithOutputMetadataCacheTime(outputMetadataCacheTime time.Duration) (option Option)

WithOutputMetadataCacheTime is an Option for the Ledger that allows to configure how long OutputMetadata objects stay cached after they have been released.

func WithStore

func WithStore(store kvstore.KVStore) (option Option)

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

func WithTransactionCacheTime(transactionCacheTime time.Duration) (option Option)

WithTransactionCacheTime is an Option for the Ledger that allows to configure how long Transaction objects stay cached after they have been released.

func WithTransactionMetadataCacheTime

func WithTransactionMetadataCacheTime(transactionMetadataCacheTime time.Duration) (option Option)

WithTransactionMetadataCacheTime is an Option for the Ledger that allows to configure how long TransactionMetadata objects stay cached after they have been released.

func WithVM

func WithVM(vm vm.VM) (option Option)

WithVM is an Option for the Ledger that allows to configure which VM is supposed to be used to process transactions.

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

func (o *OutputMetadata) BranchIDs() (branchIDs *set.AdvancedSet[utxo.TransactionID])

BranchIDs returns the conflicting BranchIDs 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) GradeOfFinality

func (o *OutputMetadata) GradeOfFinality() (gradeOfFinality gof.GradeOfFinality)

GradeOfFinality returns the confirmation status of the Output.

func (*OutputMetadata) GradeOfFinalityTime

func (o *OutputMetadata) GradeOfFinalityTime() (gradeOfFinality time.Time)

GradeOfFinalityTime returns the last time the GradeOfFinality was updated.

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

func (o *OutputMetadata) SetBranchIDs(branchIDs *set.AdvancedSet[utxo.TransactionID]) (modified bool)

SetBranchIDs sets the conflicting BranchIDs 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.

func (*OutputMetadata) SetGradeOfFinality

func (o *OutputMetadata) SetGradeOfFinality(gradeOfFinality gof.GradeOfFinality) (modified bool)

SetGradeOfFinality sets the confirmation status of the Output.

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

func (o *OutputsMetadata) BranchIDs() (branchIDs *set.AdvancedSet[utxo.TransactionID])

BranchIDs returns a union of all BranchIDs 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 {
	Outputs         *utxo.Outputs    `serix:"0"`
	OutputsMetadata *OutputsMetadata `serix:"1"`
}

Snapshot represents a snapshot of the current ledger state.

func NewSnapshot

func NewSnapshot(outputs *utxo.Outputs, outputsMetadata *OutputsMetadata) (new *Snapshot)

NewSnapshot creates a new Snapshot from the given details.

func (*Snapshot) String

func (s *Snapshot) String() (humanReadable string)

String returns a human-readable version of the Snapshot.

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.

func (*Storage) Prune

func (s *Storage) Prune() (err error)

Prune resets the database and deletes all entities.

func (*Storage) Shutdown

func (s *Storage) Shutdown()

Shutdown shuts down the KVStores used to persist data.

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

func (t *TestFramework) AssertBranchIDs(expectedBranches map[string][]string)

AssertBranchIDs asserts that the given transactions and their outputs are booked into the specified branches.

func (*TestFramework) AssertConflictDAG

func (t *TestFramework) AssertConflictDAG(expectedParents map[string][]string)

AssertConflictDAG asserts the structure of the branch DAG as specified in expectedParents. "branch3": {"branch1","branch2"} asserts that "branch3" should have "branch1" and "branch2" as parents. It also verifies the reverse mapping, that there is a child reference (conflictdag.ChildBranch) from "branch1"->"branch3" and "branch2"->"branch3".

func (*TestFramework) AssertConflicts

func (t *TestFramework) AssertConflicts(expectedConflictsAliases map[string][]string)

AssertConflicts asserts conflict membership from conflictID -> branches but also the reverse mapping branch -> conflictIDs. expectedConflictAliases should be specified as "output.0": {"branch1", "branch2"}

func (*TestFramework) BranchIDs

func (t *TestFramework) BranchIDs(txAliases ...string) (branchIDs *set.AdvancedSet[utxo.TransactionID])

BranchIDs gets all conflictdag.BranchIDs given by txAliases. Panics if an alias doesn't exist.

func (*TestFramework) ConsumeBranch

func (t *TestFramework) ConsumeBranch(branchID utxo.TransactionID, consumer func(branch *conflictdag.Conflict[utxo.TransactionID, utxo.OutputID]))

ConsumeBranch 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 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 TransactionBranchIDUpdatedEvent

type TransactionBranchIDUpdatedEvent struct {
	// TransactionID contains the identifier of the Transaction whose BranchIDs were updated.
	TransactionID utxo.TransactionID

	// AddedBranchID contains the identifier of the Branch that was added to the BranchIDs of the Transaction.
	AddedBranchID utxo.TransactionID

	// RemovedBranchIDs contains the set of the BranchIDs that were removed while updating the Transaction.
	RemovedBranchIDs *set.AdvancedSet[utxo.TransactionID]

	// Context contains a Context provided by the caller that triggered this event.
	Context context.Context
}

TransactionBranchIDUpdatedEvent is a container that acts as a dictionary for the TransactionBranchIDUpdated event related parameters.

type TransactionConfirmedEvent

type TransactionConfirmedEvent struct {
	// TransactionID contains the identifier of the confirmed Transaction.
	TransactionID utxo.TransactionID
}

TransactionConfirmedEvent is a container that acts as a dictionary for the TransactionConfirmed event related parameters.

type TransactionForkedEvent

type TransactionForkedEvent struct {
	// TransactionID contains the identifier of the forked Transaction.
	TransactionID utxo.TransactionID

	// ParentConflicts contains the set of BranchIDs that form the parent Branches 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) BranchIDs

func (t *TransactionMetadata) BranchIDs() (branchIDs *set.AdvancedSet[utxo.TransactionID])

BranchIDs returns the conflicting BranchIDs that the Transaction depends on.

func (*TransactionMetadata) GradeOfFinality

func (t *TransactionMetadata) GradeOfFinality() (gradeOfFinality gof.GradeOfFinality)

GradeOfFinality returns the confirmation status of the Transaction.

func (*TransactionMetadata) GradeOfFinalityTime

func (t *TransactionMetadata) GradeOfFinalityTime() (gradeOfFinalityTime time.Time)

GradeOfFinalityTime returns the last time the GradeOfFinality was updated.

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

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

func (t *TransactionMetadata) SetBranchIDs(branchIDs *set.AdvancedSet[utxo.TransactionID]) (modified bool)

SetBranchIDs sets the conflicting BranchIDs that this Transaction depends on.

func (*TransactionMetadata) SetGradeOfFinality

func (t *TransactionMetadata) SetGradeOfFinality(gradeOfFinality gof.GradeOfFinality) (modified bool)

SetGradeOfFinality sets the confirmation status of the Transaction.

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

func (u *Utils) BranchGradeOfFinality(branchID utxo.TransactionID) (gradeOfFinality gof.GradeOfFinality, err error)

BranchGradeOfFinality returns the GradeOfFinality of the Conflict with the given BranchID.

func (*Utils) BranchIDsInFutureCone

func (u *Utils) BranchIDsInFutureCone(branchIDs utxo.TransactionIDs) (branchIDsInFutureCone 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) ReferencedTransactions

func (u *Utils) ReferencedTransactions(tx utxo.Transaction) (transactionIDs utxo.TransactionIDs)

func (*Utils) ResolveInputs

func (u *Utils) ResolveInputs(inputs []utxo.Input) (outputIDs utxo.OutputIDs)

ResolveInputs returns the OutputIDs that were referenced by the given Inputs.

func (*Utils) TransactionBranchIDs

func (u *Utils) TransactionBranchIDs(txID utxo.TransactionID) (branchIDs *set.AdvancedSet[utxo.TransactionID], err error)

TransactionBranchIDs returns the BranchIDs of the given TransactionID.

func (*Utils) TransactionGradeOfFinality

func (u *Utils) TransactionGradeOfFinality(txID utxo.TransactionID) (gradeOfFinality gof.GradeOfFinality, err error)

TransactionGradeOfFinality returns the GradeOfFinality of the Transaction with 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.

Directories

Path Synopsis
vm

Jump to

Keyboard shortcuts

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