Skip to content

Commit

Permalink
Merge branch 'feat/utxovm' of github.com:iotaledger/goshimmer into fe…
Browse files Browse the repository at this point in the history
…at/utxovm
  • Loading branch information
jonastheis committed Apr 7, 2022
2 parents 7a31915 + c754a30 commit 16060c6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/ledger/branchdag/branchdag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/iotaledger/hive.go/generics/walker"
)

// BranchDAG is an entity that manages conflicting versions of a quadruple-entry-accounting ledger and their causal
// BranchDAG is an entity that manages conflicting versions of a quadruple-entry accounting ledger and their causal
// relationships.
type BranchDAG struct {
// Events is a dictionary for BranchDAG related events.
Expand Down
2 changes: 1 addition & 1 deletion packages/ledger/dataflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// region dataFlow /////////////////////////////////////////////////////////////////////////////////////////////////////

// dataFlow is a Ledger component that defines the data flow (h)ow the different commands are chained together).
// dataFlow is a Ledger component that defines the data flow (how the different commands are chained together).
type dataFlow struct {
// ledger contains a reference to the Ledger that created the Utils.
ledger *Ledger
Expand Down
36 changes: 29 additions & 7 deletions packages/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,35 @@ import (
// 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.
type Ledger struct {
Events *Events
Storage *storage
Utils *Utils
// 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

// BranchDAG is a reference to the BranchDAG that is used by this Ledger.
BranchDAG *branchdag.BranchDAG

dataFlow *dataFlow
// dataFlow is a Ledger component that defines the data flow (how the different commands are chained together)
dataFlow *dataFlow

// validator is a Ledger component that bundles the API that is used to check the validity of a Transaction
validator *validator
booker *booker
options *options
mutex *syncutils.DAGMutex[utxo.TransactionID]

// booker is a Ledger component that bundles the booking related API.
booker *booker

// options is a dictionary for configuration parameters of the Ledger.
options *options

// mutex is a DAGMutex that is used to make the Ledger thread safe.
mutex *syncutils.DAGMutex[utxo.TransactionID]
}

// New returns a new Ledger from the given options.
func New(options ...Option) (ledger *Ledger) {
ledger = &Ledger{
Events: newEvents(),
Expand All @@ -46,24 +63,29 @@ func New(options ...Option) (ledger *Ledger) {
return ledger
}

// CheckTransaction checks the validity of a Transaction.
func (l *Ledger) CheckTransaction(tx utxo.Transaction) (err error) {
return l.dataFlow.checkTransaction().Run(newDataFlowParams(NewTransaction(tx)))
}

// StoreAndProcessTransaction stores and processes the given Transaction.
func (l *Ledger) StoreAndProcessTransaction(tx utxo.Transaction) (err error) {
l.mutex.Lock(tx.ID())
defer l.mutex.Unlock(tx.ID())

return l.dataFlow.storeAndProcessTransaction().Run(newDataFlowParams(NewTransaction(tx)))
}

// processTransaction tries to book a single Transaction.
func (l *Ledger) processTransaction(tx *Transaction) (err error) {
l.mutex.Lock(tx.ID())
defer l.mutex.Unlock(tx.ID())

return l.dataFlow.processTransaction().Run(newDataFlowParams(tx))
}

// processConsumingTransactions tries to book the transactions approving the given OutputIDs (it is used to propagate
// solidity).
func (l *Ledger) processConsumingTransactions(outputIDs utxo.OutputIDs) {
for it := l.Utils.UnprocessedConsumingTransactions(outputIDs).Iterator(); it.HasNext(); {
consumingTransactionID := it.Next()
Expand Down

0 comments on commit 16060c6

Please sign in to comment.