Documentation ¶
Index ¶
- Constants
- func BigIntGet(ctx context.Context, key []byte, txn database.Transaction) (bool, *big.Int, error)
- func GetAccountKey(namespace string, account *types.AccountIdentifier, currency *types.Currency) []byte
- func GetHistoricalBalanceKey(account *types.AccountIdentifier, currency *types.Currency, blockIndex int64) []byte
- func GetHistoricalBalancePrefix(account *types.AccountIdentifier, currency *types.Currency) []byte
- type BalanceStorage
- func (b *BalanceStorage) AddingBlock(ctx context.Context, block *types.Block, transaction database.Transaction) (database.CommitWorker, error)
- func (b *BalanceStorage) BootstrapBalances(ctx context.Context, bootstrapBalancesFile string, ...) error
- func (b *BalanceStorage) EstimatedReconciliationCoverage(ctx context.Context) (float64, error)
- func (b *BalanceStorage) GetAllAccountCurrency(ctx context.Context) ([]*types.AccountCurrency, error)
- func (b *BalanceStorage) GetBalance(ctx context.Context, account *types.AccountIdentifier, ...) (*types.Amount, error)
- func (b *BalanceStorage) GetBalanceTransactional(ctx context.Context, dbTx database.Transaction, ...) (*types.Amount, error)
- func (b *BalanceStorage) GetOrSetBalance(ctx context.Context, account *types.AccountIdentifier, ...) (*types.Amount, error)
- func (b *BalanceStorage) GetOrSetBalanceTransactional(ctx context.Context, dbTx database.Transaction, ...) (*types.Amount, error)
- func (b *BalanceStorage) Initialize(helper BalanceStorageHelper, handler BalanceStorageHandler)
- func (b *BalanceStorage) OrphanBalance(ctx context.Context, dbTransaction database.Transaction, ...) (bool, error)
- func (b *BalanceStorage) PruneBalances(ctx context.Context, account *types.AccountIdentifier, ...) error
- func (b *BalanceStorage) Reconciled(ctx context.Context, account *types.AccountIdentifier, ...) error
- func (b *BalanceStorage) ReconciliationCoverage(ctx context.Context, minimumIndex int64) (float64, error)
- func (b *BalanceStorage) RemovingBlock(ctx context.Context, block *types.Block, transaction database.Transaction) (database.CommitWorker, error)
- func (b *BalanceStorage) SetBalance(ctx context.Context, dbTransaction database.Transaction, ...) error
- func (b *BalanceStorage) SetBalanceImported(ctx context.Context, helper BalanceStorageHelper, ...) error
- func (b *BalanceStorage) UpdateBalance(ctx context.Context, dbTransaction database.Transaction, ...) (bool, error)
- type BalanceStorageHandler
- type BalanceStorageHelper
- type BlockStorage
- func (b *BlockStorage) AddBlock(ctx context.Context, block *types.Block) error
- func (b *BlockStorage) AtTip(ctx context.Context, tipDelay int64) (bool, *types.BlockIdentifier, error)
- func (b *BlockStorage) AtTipTransactional(ctx context.Context, tipDelay int64, txn database.Transaction) (bool, *types.BlockIdentifier, error)
- func (b *BlockStorage) CanonicalBlock(ctx context.Context, blockIdentifier *types.BlockIdentifier) (bool, error)
- func (b *BlockStorage) CanonicalBlockTransactional(ctx context.Context, blockIdentifier *types.BlockIdentifier, ...) (bool, error)
- func (b *BlockStorage) CreateBlockCache(ctx context.Context, blocks int) []*types.BlockIdentifier
- func (b *BlockStorage) FindTransaction(ctx context.Context, transactionIdentifier *types.TransactionIdentifier, ...) (*types.BlockIdentifier, *types.Transaction, error)
- func (b *BlockStorage) GetBlock(ctx context.Context, blockIdentifier *types.PartialBlockIdentifier) (*types.Block, error)
- func (b *BlockStorage) GetBlockLazy(ctx context.Context, blockIdentifier *types.PartialBlockIdentifier) (*types.BlockResponse, error)
- func (b *BlockStorage) GetBlockLazyTransactional(ctx context.Context, blockIdentifier *types.PartialBlockIdentifier, ...) (*types.BlockResponse, error)
- func (b *BlockStorage) GetBlockTransaction(ctx context.Context, blockIdentifier *types.BlockIdentifier, ...) (*types.Transaction, error)
- func (b *BlockStorage) GetBlockTransactional(ctx context.Context, dbTx database.Transaction, ...) (*types.Block, error)
- func (b *BlockStorage) GetHeadBlockIdentifier(ctx context.Context) (*types.BlockIdentifier, error)
- func (b *BlockStorage) GetHeadBlockIdentifierTransactional(ctx context.Context, transaction database.Transaction) (*types.BlockIdentifier, error)
- func (b *BlockStorage) GetOldestBlockIndex(ctx context.Context) (int64, error)
- func (b *BlockStorage) GetOldestBlockIndexTransactional(ctx context.Context, dbTx database.Transaction) (int64, error)
- func (b *BlockStorage) IndexAtTip(ctx context.Context, tipDelay int64, index int64) (bool, error)
- func (b *BlockStorage) Initialize(workers []BlockWorker)
- func (b *BlockStorage) Prune(ctx context.Context, index int64, minDepth int64) (int64, int64, error)
- func (b *BlockStorage) RemoveBlock(ctx context.Context, blockIdentifier *types.BlockIdentifier) error
- func (b *BlockStorage) SetNewStartIndex(ctx context.Context, startIndex int64) error
- func (b *BlockStorage) StoreHeadBlockIdentifier(ctx context.Context, transaction database.Transaction, ...) error
- type BlockWorker
- type BootstrapBalance
- type Broadcast
- type BroadcastStorage
- func (b *BroadcastStorage) AddingBlock(ctx context.Context, block *types.Block, transaction database.Transaction) (database.CommitWorker, error)
- func (b *BroadcastStorage) Broadcast(ctx context.Context, dbTx database.Transaction, identifier string, ...) error
- func (b *BroadcastStorage) BroadcastAll(ctx context.Context, onlyEligible bool) error
- func (b *BroadcastStorage) ClearBroadcasts(ctx context.Context) ([]*Broadcast, error)
- func (b *BroadcastStorage) GetAllBroadcasts(ctx context.Context) ([]*Broadcast, error)
- func (b *BroadcastStorage) Initialize(helper BroadcastStorageHelper, handler BroadcastStorageHandler)
- func (b *BroadcastStorage) LockedAccounts(ctx context.Context, dbTx database.Transaction) ([]*types.AccountIdentifier, error)
- func (b *BroadcastStorage) RemovingBlock(ctx context.Context, block *types.Block, transaction database.Transaction) (database.CommitWorker, error)
- type BroadcastStorageHandler
- type BroadcastStorageHelper
- type CoinStorage
- func (c *CoinStorage) AddCoins(ctx context.Context, accountCoins []*types.AccountCoin) error
- func (c *CoinStorage) AddingBlock(ctx context.Context, block *types.Block, transaction database.Transaction) (database.CommitWorker, error)
- func (c *CoinStorage) GetCoin(ctx context.Context, coinIdentifier *types.CoinIdentifier) (*types.Coin, *types.AccountIdentifier, error)
- func (c *CoinStorage) GetCoinTransactional(ctx context.Context, dbTx database.Transaction, ...) (*types.Coin, *types.AccountIdentifier, error)
- func (c *CoinStorage) GetCoins(ctx context.Context, accountIdentifier *types.AccountIdentifier) ([]*types.Coin, *types.BlockIdentifier, error)
- func (c *CoinStorage) GetCoinsTransactional(ctx context.Context, dbTx database.Transaction, ...) ([]*types.Coin, *types.BlockIdentifier, error)
- func (c *CoinStorage) GetLargestCoin(ctx context.Context, accountIdentifier *types.AccountIdentifier, ...) (*big.Int, *types.CoinIdentifier, *types.BlockIdentifier, error)
- func (c *CoinStorage) RemovingBlock(ctx context.Context, block *types.Block, transaction database.Transaction) (database.CommitWorker, error)
- func (c *CoinStorage) SetCoinsImported(ctx context.Context, accountBalances []*utils.AccountBalance) error
- type CoinStorageHelper
- type CounterStorage
- func (c *CounterStorage) AddingBlock(ctx context.Context, block *types.Block, transaction database.Transaction) (database.CommitWorker, error)
- func (c *CounterStorage) Get(ctx context.Context, counter string) (*big.Int, error)
- func (c *CounterStorage) GetTransactional(ctx context.Context, dbTx database.Transaction, counter string) (*big.Int, error)
- func (c *CounterStorage) RemovingBlock(ctx context.Context, block *types.Block, transaction database.Transaction) (database.CommitWorker, error)
- func (c *CounterStorage) Update(ctx context.Context, counter string, amount *big.Int) (*big.Int, error)
- func (c *CounterStorage) UpdateTransactional(ctx context.Context, dbTx database.Transaction, counter string, ...) (*big.Int, error)
- type JobStorage
- func (j *JobStorage) AllCompleted(ctx context.Context) ([]*job.Job, error)
- func (j *JobStorage) AllFailed(ctx context.Context) ([]*job.Job, error)
- func (j *JobStorage) AllProcessing(ctx context.Context) ([]*job.Job, error)
- func (j *JobStorage) Broadcasting(ctx context.Context, dbTx database.Transaction) ([]*job.Job, error)
- func (j *JobStorage) Completed(ctx context.Context, workflow string) ([]*job.Job, error)
- func (j *JobStorage) Failed(ctx context.Context, workflow string) ([]*job.Job, error)
- func (j *JobStorage) Get(ctx context.Context, dbTx database.Transaction, identifier string) (*job.Job, error)
- func (j *JobStorage) Processing(ctx context.Context, dbTx database.Transaction, workflow string) ([]*job.Job, error)
- func (j *JobStorage) Ready(ctx context.Context, dbTx database.Transaction) ([]*job.Job, error)
- func (j *JobStorage) Update(ctx context.Context, dbTx database.Transaction, v *job.Job) (string, error)
- type Key
- type KeyStorage
- func (k *KeyStorage) Get(ctx context.Context, account *types.AccountIdentifier) (*keys.KeyPair, error)
- func (k *KeyStorage) GetAllAccounts(ctx context.Context) ([]*types.AccountIdentifier, error)
- func (k *KeyStorage) GetAllAccountsTransactional(ctx context.Context, dbTx database.Transaction) ([]*types.AccountIdentifier, error)
- func (k *KeyStorage) GetTransactional(ctx context.Context, dbTx database.Transaction, ...) (*keys.KeyPair, error)
- func (k *KeyStorage) ImportAccounts(ctx context.Context, accounts []*PrefundedAccount) error
- func (k *KeyStorage) RandomAccount(ctx context.Context) (*types.AccountIdentifier, error)
- func (k *KeyStorage) Sign(ctx context.Context, payloads []*types.SigningPayload) ([]*types.Signature, error)
- func (k *KeyStorage) Store(ctx context.Context, account *types.AccountIdentifier, keyPair *keys.KeyPair) error
- func (k *KeyStorage) StoreTransactional(ctx context.Context, account *types.AccountIdentifier, keyPair *keys.KeyPair, ...) error
- type PrefundedAccount
Constants ¶
const ( // BlockCounter is the number of added blocks. BlockCounter = "blocks" // OrphanCounter is the number of orphaned blocks. OrphanCounter = "orphans" // TransactionCounter is the number of processed transactions. TransactionCounter = "transactions" // OperationCounter is the number of processed operations. OperationCounter = "operations" // AddressesCreatedCounter is the number of created addresses. AddressesCreatedCounter = "addresses_created" // TransactionsCreatedCounter is the number of created transactions. TransactionsCreatedCounter = "transactions_created" // TransactionsConfirmedCounter is the number of confirmed transactions. TransactionsConfirmedCounter = "transactions_confirmed" // StaleBroadcastsCounter is the number of transaction broadcasts that // never appeared on-chain. StaleBroadcastsCounter = "stale_broadcasts" // FailedBroadcastsCounter is the number of transaction broadcasts that // never made it on-chain after retries. FailedBroadcastsCounter = "failed_broadcasts" // ActiveReconciliationCounter is the number of active // reconciliations performed. ActiveReconciliationCounter = "active_reconciliations" // InactiveReconciliationCounter is the number of inactive // reconciliations performed. InactiveReconciliationCounter = "inactive_reconciliations" // ExemptReconciliationCounter is the number of reconciliation // failures that were exempt. ExemptReconciliationCounter = "exempt_reconciliations" // FailedReconciliationCounter is the number of reconciliation // failures that were not exempt. FailedReconciliationCounter = "failed_reconciliations" // SkippedReconciliationsCounter is the number of reconciliation // attempts that were skipped. This typically occurs because an // account balance has been updated since being marked for reconciliation // or the block where an account was updated has been orphaned. SkippedReconciliationsCounter = "skipped_reconciliations" // SeenAccounts is the total number of accounts seen. SeenAccounts = "seen_accounts" // ReconciledAccounts is the total number of accounts seen. ReconciledAccounts = "reconciled_accounts" )
Variables ¶
This section is empty.
Functions ¶
func BigIntGet ¶
func BigIntGet( ctx context.Context, key []byte, txn database.Transaction, ) (bool, *big.Int, error)
BigIntGet attempts to fetch a *big.Int from a given key in a database.Transaction.
func GetAccountKey ¶
func GetAccountKey( namespace string, account *types.AccountIdentifier, currency *types.Currency, ) []byte
GetAccountKey returns a deterministic hash of a types.Account + types.Currency.
func GetHistoricalBalanceKey ¶
func GetHistoricalBalanceKey( account *types.AccountIdentifier, currency *types.Currency, blockIndex int64, ) []byte
GetHistoricalBalanceKey returns a deterministic hash of a types.Account + types.Currency + block index.
func GetHistoricalBalancePrefix ¶
func GetHistoricalBalancePrefix(account *types.AccountIdentifier, currency *types.Currency) []byte
GetHistoricalBalancePrefix returns a deterministic hash of a types.Account + types.Currency to limit scan results.
Types ¶
type BalanceStorage ¶
type BalanceStorage struct {
// contains filtered or unexported fields
}
BalanceStorage implements block specific storage methods on top of a database.Database and database.Transaction interface.
func NewBalanceStorage ¶
func NewBalanceStorage( db database.Database, ) *BalanceStorage
NewBalanceStorage returns a new BalanceStorage.
func (*BalanceStorage) AddingBlock ¶
func (b *BalanceStorage) AddingBlock( ctx context.Context, block *types.Block, transaction database.Transaction, ) (database.CommitWorker, error)
AddingBlock is called by BlockStorage when adding a block to storage.
func (*BalanceStorage) BootstrapBalances ¶
func (b *BalanceStorage) BootstrapBalances( ctx context.Context, bootstrapBalancesFile string, genesisBlockIdentifier *types.BlockIdentifier, ) error
BootstrapBalances is utilized to set the balance of any number of AccountIdentifiers at the genesis blocks. This is particularly useful for setting the value of accounts that received an allocation in the genesis block.
func (*BalanceStorage) EstimatedReconciliationCoverage ¶
func (b *BalanceStorage) EstimatedReconciliationCoverage(ctx context.Context) (float64, error)
EstimatedReconciliationCoverage returns an estimated reconciliation coverage metric. This can be used to get an idea of the reconciliation coverage without doing an expensive DB scan across all accounts.
func (*BalanceStorage) GetAllAccountCurrency ¶
func (b *BalanceStorage) GetAllAccountCurrency( ctx context.Context, ) ([]*types.AccountCurrency, error)
GetAllAccountCurrency scans the db for all balances and returns a slice of reconciler.AccountCurrency. This is useful for bootstrapping the reconciler after restart.
func (*BalanceStorage) GetBalance ¶
func (b *BalanceStorage) GetBalance( ctx context.Context, account *types.AccountIdentifier, currency *types.Currency, index int64, ) (*types.Amount, error)
GetBalance returns the balance of a types.AccountIdentifier at the canonical block of a certain index.
func (*BalanceStorage) GetBalanceTransactional ¶
func (b *BalanceStorage) GetBalanceTransactional( ctx context.Context, dbTx database.Transaction, account *types.AccountIdentifier, currency *types.Currency, index int64, ) (*types.Amount, error)
GetBalanceTransactional returns all the balances of a types.AccountIdentifier and the types.BlockIdentifier it was last updated at in a database transaction.
func (*BalanceStorage) GetOrSetBalance ¶
func (b *BalanceStorage) GetOrSetBalance( ctx context.Context, account *types.AccountIdentifier, currency *types.Currency, block *types.BlockIdentifier, ) (*types.Amount, error)
GetOrSetBalance returns the balance of a types.AccountIdentifier at the canonical block of a certain index, setting it if it doesn't exist.
func (*BalanceStorage) GetOrSetBalanceTransactional ¶
func (b *BalanceStorage) GetOrSetBalanceTransactional( ctx context.Context, dbTx database.Transaction, account *types.AccountIdentifier, currency *types.Currency, block *types.BlockIdentifier, ) (*types.Amount, error)
GetOrSetBalanceTransactional returns the balance of a types.AccountIdentifier at the canonical block of a certain index, setting it if it doesn't exist.
func (*BalanceStorage) Initialize ¶
func (b *BalanceStorage) Initialize( helper BalanceStorageHelper, handler BalanceStorageHandler, )
Initialize adds a BalanceStorageHelper and BalanceStorageHandler to BalanceStorage. This must be called prior to syncing!
func (*BalanceStorage) OrphanBalance ¶
func (b *BalanceStorage) OrphanBalance( ctx context.Context, dbTransaction database.Transaction, change *parser.BalanceChange, ) (bool, error)
OrphanBalance removes all saved states for a *types.Account and *types.Currency at blocks >= the provided block.
func (*BalanceStorage) PruneBalances ¶
func (b *BalanceStorage) PruneBalances( ctx context.Context, account *types.AccountIdentifier, currency *types.Currency, index int64, ) error
PruneBalances removes all historical balance states <= some index. This can significantly reduce storage usage in scenarios where historical balances are only retrieved once (like reconciliation).
func (*BalanceStorage) Reconciled ¶
func (b *BalanceStorage) Reconciled( ctx context.Context, account *types.AccountIdentifier, currency *types.Currency, block *types.BlockIdentifier, ) error
Reconciled updates the LastReconciled field on a particular balance. Tracking reconciliation coverage is an important end condition.
func (*BalanceStorage) ReconciliationCoverage ¶
func (b *BalanceStorage) ReconciliationCoverage( ctx context.Context, minimumIndex int64, ) (float64, error)
ReconciliationCoverage returns the proportion of accounts [0.0, 1.0] that have been reconciled at an index >= to a minimumIndex.
func (*BalanceStorage) RemovingBlock ¶
func (b *BalanceStorage) RemovingBlock( ctx context.Context, block *types.Block, transaction database.Transaction, ) (database.CommitWorker, error)
RemovingBlock is called by BlockStorage when removing a block from storage.
func (*BalanceStorage) SetBalance ¶
func (b *BalanceStorage) SetBalance( ctx context.Context, dbTransaction database.Transaction, account *types.AccountIdentifier, amount *types.Amount, block *types.BlockIdentifier, ) error
SetBalance allows a client to set the balance of an account in a database transaction (removing all historical states). This is particularly useful for bootstrapping balances.
func (*BalanceStorage) SetBalanceImported ¶
func (b *BalanceStorage) SetBalanceImported( ctx context.Context, helper BalanceStorageHelper, accountBalances []*utils.AccountBalance, ) error
SetBalanceImported sets the balances of a set of addresses by getting their balances from the tip block, and populating the database. This is used when importing prefunded addresses.
func (*BalanceStorage) UpdateBalance ¶
func (b *BalanceStorage) UpdateBalance( ctx context.Context, dbTransaction database.Transaction, change *parser.BalanceChange, parentBlock *types.BlockIdentifier, ) (bool, error)
UpdateBalance updates a types.AccountIdentifer by a types.Amount and sets the account's most recent accessed block.
type BalanceStorageHandler ¶
type BalanceStorageHandler interface { BlockAdded(ctx context.Context, block *types.Block, changes []*parser.BalanceChange) error BlockRemoved(ctx context.Context, block *types.Block, changes []*parser.BalanceChange) error AccountsReconciled(ctx context.Context, dbTx database.Transaction, count int) error AccountsSeen(ctx context.Context, dbTx database.Transaction, count int) error }
BalanceStorageHandler is invoked after balance changes are committed to the database.
type BalanceStorageHelper ¶
type BalanceStorageHelper interface { AccountBalance( ctx context.Context, account *types.AccountIdentifier, currency *types.Currency, block *types.BlockIdentifier, ) (*types.Amount, error) ExemptFunc() parser.ExemptOperation BalanceExemptions() []*types.BalanceExemption Asserter() *asserter.Asserter AccountsReconciled(ctx context.Context, dbTx database.Transaction) (*big.Int, error) AccountsSeen(ctx context.Context, dbTx database.Transaction) (*big.Int, error) }
BalanceStorageHelper functions are used by BalanceStorage to process balances. Defining an interface allows the client to determine if they wish to query the node for certain information or use another datastore.
type BlockStorage ¶
type BlockStorage struct {
// contains filtered or unexported fields
}
BlockStorage implements block specific storage methods on top of a database.Database and database.Transaction interface.
func NewBlockStorage ¶
func NewBlockStorage( db database.Database, ) *BlockStorage
NewBlockStorage returns a new BlockStorage.
func (*BlockStorage) AtTip ¶
func (b *BlockStorage) AtTip( ctx context.Context, tipDelay int64, ) (bool, *types.BlockIdentifier, error)
AtTip returns a boolean indicating if we are at tip (provided some acceptable tip delay).
func (*BlockStorage) AtTipTransactional ¶
func (b *BlockStorage) AtTipTransactional( ctx context.Context, tipDelay int64, txn database.Transaction, ) (bool, *types.BlockIdentifier, error)
AtTipTransactional returns a boolean indicating if we are at tip (provided some acceptable tip delay) in a database transaction.
func (*BlockStorage) CanonicalBlock ¶
func (b *BlockStorage) CanonicalBlock( ctx context.Context, blockIdentifier *types.BlockIdentifier, ) (bool, error)
CanonicalBlock returns a boolean indicating if a block with the provided *types.BlockIdentifier is in the canonical chain (regardless if it has been pruned).
func (*BlockStorage) CanonicalBlockTransactional ¶
func (b *BlockStorage) CanonicalBlockTransactional( ctx context.Context, blockIdentifier *types.BlockIdentifier, dbTx database.Transaction, ) (bool, error)
CanonicalBlockTransactional returns a boolean indicating if a block with the provided *types.BlockIdentifier is in the canonical chain (regardless if it has been pruned) in a single storage.database.Transaction.
func (*BlockStorage) CreateBlockCache ¶
func (b *BlockStorage) CreateBlockCache(ctx context.Context, blocks int) []*types.BlockIdentifier
CreateBlockCache populates a slice of blocks with the most recent ones in storage.
func (*BlockStorage) FindTransaction ¶
func (b *BlockStorage) FindTransaction( ctx context.Context, transactionIdentifier *types.TransactionIdentifier, txn database.Transaction, ) (*types.BlockIdentifier, *types.Transaction, error)
FindTransaction returns the most recent *types.BlockIdentifier containing the transaction and the transaction.
func (*BlockStorage) GetBlock ¶
func (b *BlockStorage) GetBlock( ctx context.Context, blockIdentifier *types.PartialBlockIdentifier, ) (*types.Block, error)
GetBlock returns a block, if it exists. GetBlock will fetch all transactions contained in a block automatically. If you don't wish to do this for performance reasons, use GetBlockLazy.
func (*BlockStorage) GetBlockLazy ¶
func (b *BlockStorage) GetBlockLazy( ctx context.Context, blockIdentifier *types.PartialBlockIdentifier, ) (*types.BlockResponse, error)
GetBlockLazy returns a *types.BlockResponse with populated OtherTransactions array containing all the transactions the caller must retrieve. This is typically used to serve /block queries.
func (*BlockStorage) GetBlockLazyTransactional ¶
func (b *BlockStorage) GetBlockLazyTransactional( ctx context.Context, blockIdentifier *types.PartialBlockIdentifier, transaction database.Transaction, ) (*types.BlockResponse, error)
GetBlockLazyTransactional returns a *types.BlockResponse with populated OtherTransactions array containing all the transactions the caller must retrieve in a provided database transaction.
func (*BlockStorage) GetBlockTransaction ¶
func (b *BlockStorage) GetBlockTransaction( ctx context.Context, blockIdentifier *types.BlockIdentifier, transactionIdentifier *types.TransactionIdentifier, ) (*types.Transaction, error)
GetBlockTransaction retrieves a transaction belonging to a certain block in a database transaction. This is usually used to implement /block/transaction.
func (*BlockStorage) GetBlockTransactional ¶
func (b *BlockStorage) GetBlockTransactional( ctx context.Context, dbTx database.Transaction, blockIdentifier *types.PartialBlockIdentifier, ) (*types.Block, error)
GetBlockTransactional gets a block in the context of a database transaction.
func (*BlockStorage) GetHeadBlockIdentifier ¶
func (b *BlockStorage) GetHeadBlockIdentifier( ctx context.Context, ) (*types.BlockIdentifier, error)
GetHeadBlockIdentifier returns the head block identifier, if it exists.
func (*BlockStorage) GetHeadBlockIdentifierTransactional ¶
func (b *BlockStorage) GetHeadBlockIdentifierTransactional( ctx context.Context, transaction database.Transaction, ) (*types.BlockIdentifier, error)
GetHeadBlockIdentifierTransactional returns the head block identifier, if it exists, in the context of a database.Transaction.
func (*BlockStorage) GetOldestBlockIndex ¶
func (b *BlockStorage) GetOldestBlockIndex( ctx context.Context, ) (int64, error)
GetOldestBlockIndex returns the oldest block index available in BlockStorage.
func (*BlockStorage) GetOldestBlockIndexTransactional ¶
func (b *BlockStorage) GetOldestBlockIndexTransactional( ctx context.Context, dbTx database.Transaction, ) (int64, error)
GetOldestBlockIndexTransactional returns the oldest block index available in BlockStorage in a single database transaction.
func (*BlockStorage) IndexAtTip ¶
func (b *BlockStorage) IndexAtTip( ctx context.Context, tipDelay int64, index int64, ) (bool, error)
IndexAtTip returns a boolean indicating if a block index is at tip (provided some acceptable tip delay). If the index is ahead of the head block and the head block is at tip, we consider the index at tip.
func (*BlockStorage) Initialize ¶
func (b *BlockStorage) Initialize(workers []BlockWorker)
Initialize adds a []BlockWorker to BlockStorage. Usually all block workers are not created by the time block storage is constructed.
This must be called prior to syncing!
func (*BlockStorage) Prune ¶
func (b *BlockStorage) Prune( ctx context.Context, index int64, minDepth int64, ) (int64, int64, error)
Prune removes block and transaction data from all blocks with index <= index. Pruning leaves all keys associated with pruned data but overwrites their data to be empty. If pruning is successful, we return the range of pruned blocks.
Prune is not invoked automatically because some applications prefer not to prune any block data.
func (*BlockStorage) RemoveBlock ¶
func (b *BlockStorage) RemoveBlock( ctx context.Context, blockIdentifier *types.BlockIdentifier, ) error
RemoveBlock removes a block or returns an error. RemoveBlock also removes the block hash and all its transaction hashes to not break duplicate detection. This is called within a re-org.
func (*BlockStorage) SetNewStartIndex ¶
func (b *BlockStorage) SetNewStartIndex( ctx context.Context, startIndex int64, ) error
SetNewStartIndex attempts to remove all blocks greater than or equal to the startIndex.
func (*BlockStorage) StoreHeadBlockIdentifier ¶
func (b *BlockStorage) StoreHeadBlockIdentifier( ctx context.Context, transaction database.Transaction, blockIdentifier *types.BlockIdentifier, ) error
StoreHeadBlockIdentifier stores a block identifier or returns an error.
type BlockWorker ¶
type BlockWorker interface { AddingBlock(context.Context, *types.Block, database.Transaction) (database.CommitWorker, error) RemovingBlock( context.Context, *types.Block, database.Transaction, ) (database.CommitWorker, error) }
BlockWorker is an interface that allows for work to be done while a block is added/removed from storage in the same database transaction as the change.
type BootstrapBalance ¶
type BootstrapBalance struct { Account *types.AccountIdentifier `json:"account_identifier,omitempty"` Currency *types.Currency `json:"currency,omitempty"` Value string `json:"value,omitempty"` }
BootstrapBalance represents a balance of a *types.AccountIdentifier and a *types.Currency in the genesis block.
type Broadcast ¶
type Broadcast struct { Identifier string `json:"identifier"` NetworkIdentifier *types.NetworkIdentifier `json:"network_identifier"` TransactionIdentifier *types.TransactionIdentifier `json:"transaction_identifier"` ConfirmationDepth int64 `json:"confirmation_depth"` Intent []*types.Operation `json:"intent"` Payload string `json:"payload"` LastBroadcast *types.BlockIdentifier `json:"broadcast_at"` Broadcasts int `json:"broadcasts"` }
Broadcast is persisted to the db to track transaction broadcast.
type BroadcastStorage ¶
type BroadcastStorage struct {
// contains filtered or unexported fields
}
BroadcastStorage implements storage methods for managing transaction broadcast.
func NewBroadcastStorage ¶
func NewBroadcastStorage( db database.Database, staleDepth int64, broadcastLimit int, tipDelay int64, broadcastBehindTip bool, blockBroadcastLimit int, ) *BroadcastStorage
NewBroadcastStorage returns a new BroadcastStorage.
func (*BroadcastStorage) AddingBlock ¶
func (b *BroadcastStorage) AddingBlock( ctx context.Context, block *types.Block, transaction database.Transaction, ) (database.CommitWorker, error)
AddingBlock is called by BlockStorage when adding a block.
func (*BroadcastStorage) Broadcast ¶
func (b *BroadcastStorage) Broadcast( ctx context.Context, dbTx database.Transaction, identifier string, network *types.NetworkIdentifier, intent []*types.Operation, transactionIdentifier *types.TransactionIdentifier, payload string, confirmationDepth int64, ) error
Broadcast is called when a caller wants a transaction to be broadcast and tracked. The caller SHOULD NOT broadcast the transaction before calling this function.
func (*BroadcastStorage) BroadcastAll ¶
func (b *BroadcastStorage) BroadcastAll(ctx context.Context, onlyEligible bool) error
BroadcastAll broadcasts all transactions in BroadcastStorage. If onlyEligible is set to true, then only transactions that should be broadcast again are actually broadcast.
func (*BroadcastStorage) ClearBroadcasts ¶
func (b *BroadcastStorage) ClearBroadcasts(ctx context.Context) ([]*Broadcast, error)
ClearBroadcasts deletes all in-progress broadcasts from BroadcastStorage. This is useful when there is some construction error and all pending broadcasts will fail and should be cleared instead of re-attempting.
func (*BroadcastStorage) GetAllBroadcasts ¶
func (b *BroadcastStorage) GetAllBroadcasts(ctx context.Context) ([]*Broadcast, error)
GetAllBroadcasts returns all currently in-process broadcasts.
func (*BroadcastStorage) Initialize ¶
func (b *BroadcastStorage) Initialize( helper BroadcastStorageHelper, handler BroadcastStorageHandler, )
Initialize adds a BroadcastStorageHelper and BroadcastStorageHandler to BroadcastStorage. This must be called prior to syncing!
func (*BroadcastStorage) LockedAccounts ¶
func (b *BroadcastStorage) LockedAccounts( ctx context.Context, dbTx database.Transaction, ) ([]*types.AccountIdentifier, error)
LockedAccounts returns all *types.AccountIdentifier currently active in transaction broadcasts. The caller SHOULD NOT broadcast a transaction from an account if it is considered locked!
func (*BroadcastStorage) RemovingBlock ¶
func (b *BroadcastStorage) RemovingBlock( ctx context.Context, block *types.Block, transaction database.Transaction, ) (database.CommitWorker, error)
RemovingBlock is called by BlockStorage when removing a block. TODO: error if transaction removed after confirmed (means confirmation depth not deep enough)
type BroadcastStorageHandler ¶
type BroadcastStorageHandler interface { // TransactionConfirmed is called when a transaction is observed on-chain for the // last time at a block height < current block height - confirmationDepth. TransactionConfirmed( context.Context, database.Transaction, string, *types.BlockIdentifier, *types.Transaction, []*types.Operation, ) error // can use locked account again + confirm matches intent + update logger // TransactionStale is called when a transaction has not yet been // seen on-chain and is considered stale. This occurs when // current block height - last broadcast > staleDepth. TransactionStale( context.Context, database.Transaction, string, *types.TransactionIdentifier, ) error // log in counter (rebroadcast should occur here) // BroadcastFailed is called when another transaction broadcast would // put it over the provided broadcast limit. BroadcastFailed( context.Context, database.Transaction, string, *types.TransactionIdentifier, []*types.Operation, ) error }
BroadcastStorageHandler is invoked when a transaction is confirmed on-chain or when a transaction is considered stale.
type BroadcastStorageHelper ¶
type BroadcastStorageHelper interface { // CurrentBlockIdentifier is called before transaction broadcast and is used // to determine if a transaction broadcast is stale. CurrentBlockIdentifier( context.Context, ) (*types.BlockIdentifier, error) // used to determine if should rebroadcast // AtTip is called before transaction broadcast to determine if we are at tip. AtTip( context.Context, int64, ) (bool, error) // FindTransaction looks for the provided TransactionIdentifier in processed // blocks and returns the block identifier containing the most recent sighting // and the transaction seen in that block. FindTransaction( context.Context, *types.TransactionIdentifier, database.Transaction, ) (*types.BlockIdentifier, *types.Transaction, error) // used to confirm // BroadcastTransaction broadcasts a transaction to a Rosetta implementation // and returns the *types.TransactionIdentifier returned by the implementation. BroadcastTransaction( context.Context, *types.NetworkIdentifier, string, ) (*types.TransactionIdentifier, error) // handle initial broadcast + confirm matches provided + rebroadcast if stale }
BroadcastStorageHelper is used by BroadcastStorage to submit transactions and find said transaction in blocks on-chain.
type CoinStorage ¶
type CoinStorage struct {
// contains filtered or unexported fields
}
CoinStorage implements storage methods for storing UTXOs.
func NewCoinStorage ¶
func NewCoinStorage( db database.Database, helper CoinStorageHelper, asserter *asserter.Asserter, ) *CoinStorage
NewCoinStorage returns a new CoinStorage.
func (*CoinStorage) AddCoins ¶
func (c *CoinStorage) AddCoins( ctx context.Context, accountCoins []*types.AccountCoin, ) error
AddCoins takes an array of AccountCoins and saves them to the database. It returns an error if the transaction fails.
func (*CoinStorage) AddingBlock ¶
func (c *CoinStorage) AddingBlock( ctx context.Context, block *types.Block, transaction database.Transaction, ) (database.CommitWorker, error)
AddingBlock is called by BlockStorage when adding a block.
func (*CoinStorage) GetCoin ¶
func (c *CoinStorage) GetCoin( ctx context.Context, coinIdentifier *types.CoinIdentifier, ) (*types.Coin, *types.AccountIdentifier, error)
GetCoin returns a *types.Coin by its identifier.
func (*CoinStorage) GetCoinTransactional ¶
func (c *CoinStorage) GetCoinTransactional( ctx context.Context, dbTx database.Transaction, coinIdentifier *types.CoinIdentifier, ) (*types.Coin, *types.AccountIdentifier, error)
GetCoinTransactional returns a *types.Coin by its identifier in a database transaction.
func (*CoinStorage) GetCoins ¶
func (c *CoinStorage) GetCoins( ctx context.Context, accountIdentifier *types.AccountIdentifier, ) ([]*types.Coin, *types.BlockIdentifier, error)
GetCoins returns all unspent coins for a provided *types.AccountIdentifier.
func (*CoinStorage) GetCoinsTransactional ¶
func (c *CoinStorage) GetCoinsTransactional( ctx context.Context, dbTx database.Transaction, accountIdentifier *types.AccountIdentifier, ) ([]*types.Coin, *types.BlockIdentifier, error)
GetCoinsTransactional returns all unspent coins for a provided *types.AccountIdentifier.
func (*CoinStorage) GetLargestCoin ¶
func (c *CoinStorage) GetLargestCoin( ctx context.Context, accountIdentifier *types.AccountIdentifier, currency *types.Currency, ) (*big.Int, *types.CoinIdentifier, *types.BlockIdentifier, error)
GetLargestCoin returns the largest Coin for a *types.AccountIdentifier and *types.Currency. If no Coins are available, a 0 balance is returned.
func (*CoinStorage) RemovingBlock ¶
func (c *CoinStorage) RemovingBlock( ctx context.Context, block *types.Block, transaction database.Transaction, ) (database.CommitWorker, error)
RemovingBlock is called by BlockStorage when removing a block.
func (*CoinStorage) SetCoinsImported ¶
func (c *CoinStorage) SetCoinsImported( ctx context.Context, accountBalances []*utils.AccountBalance, ) error
SetCoinsImported sets coins of a set of addresses by getting their coins from the tip block, and populating the database. This is used when importing prefunded addresses.
type CoinStorageHelper ¶
type CoinStorageHelper interface { // CurrentBlockIdentifier is called while fetching coins in a single // database transaction to return the *types.BlockIdentifier where // the Coin set is valid. CurrentBlockIdentifier( context.Context, database.Transaction, ) (*types.BlockIdentifier, error) }
CoinStorageHelper is used by CoinStorage to determine at which block a Coin set is valid.
type CounterStorage ¶
type CounterStorage struct {
// contains filtered or unexported fields
}
CounterStorage implements counter-specific storage methods on top of a database.Database and database.Transaction interface.
func NewCounterStorage ¶
func NewCounterStorage( db database.Database, ) *CounterStorage
NewCounterStorage returns a new CounterStorage.
func (*CounterStorage) AddingBlock ¶
func (c *CounterStorage) AddingBlock( ctx context.Context, block *types.Block, transaction database.Transaction, ) (database.CommitWorker, error)
AddingBlock is called by BlockStorage when adding a block.
func (*CounterStorage) GetTransactional ¶
func (c *CounterStorage) GetTransactional( ctx context.Context, dbTx database.Transaction, counter string, ) (*big.Int, error)
GetTransactional returns the current value of a counter in a database.Transaction.
func (*CounterStorage) RemovingBlock ¶
func (c *CounterStorage) RemovingBlock( ctx context.Context, block *types.Block, transaction database.Transaction, ) (database.CommitWorker, error)
RemovingBlock is called by BlockStorage when removing a block.
func (*CounterStorage) Update ¶
func (c *CounterStorage) Update( ctx context.Context, counter string, amount *big.Int, ) (*big.Int, error)
Update updates the value of a counter by amount and returns the new value.
func (*CounterStorage) UpdateTransactional ¶
func (c *CounterStorage) UpdateTransactional( ctx context.Context, dbTx database.Transaction, counter string, amount *big.Int, ) (*big.Int, error)
UpdateTransactional updates the value of a counter by amount and returns the new value in a transaction.
type JobStorage ¶
type JobStorage struct {
// contains filtered or unexported fields
}
JobStorage implements storage methods for managing jobs.
func NewJobStorage ¶
func NewJobStorage(db database.Database) *JobStorage
NewJobStorage returns a new instance of *JobStorage.
func (*JobStorage) AllCompleted ¶
AllCompleted gets all successfully completed *job.Jobs.
func (*JobStorage) AllProcessing ¶
AllProcessing gets all processing *job.Jobs.
func (*JobStorage) Broadcasting ¶
func (j *JobStorage) Broadcasting( ctx context.Context, dbTx database.Transaction, ) ([]*job.Job, error)
Broadcasting returns all broadcasting *job.Job.
func (*JobStorage) Completed ¶
Completed gets all successfully completed *job.Job of a certain workflow.
func (*JobStorage) Get ¶
func (j *JobStorage) Get( ctx context.Context, dbTx database.Transaction, identifier string, ) (*job.Job, error)
Get returns a *job.Job by its identifier.
func (*JobStorage) Processing ¶
func (j *JobStorage) Processing( ctx context.Context, dbTx database.Transaction, workflow string, ) ([]*job.Job, error)
Processing gets all processing *job.Job of a certain workflow.
func (*JobStorage) Ready ¶
func (j *JobStorage) Ready(ctx context.Context, dbTx database.Transaction) ([]*job.Job, error)
Ready returns all ready *job.Job.
type Key ¶
type Key struct { Account *types.AccountIdentifier `json:"account"` KeyPair *keys.KeyPair `json:"keypair"` }
Key is the struct stored in key storage. This is public so that accounts can be loaded from a configuration file.
type KeyStorage ¶
type KeyStorage struct {
// contains filtered or unexported fields
}
KeyStorage implements key storage methods on top of a database.Database and database.Transaction interface.
func NewKeyStorage ¶
func NewKeyStorage( db database.Database, ) *KeyStorage
NewKeyStorage returns a new KeyStorage.
func (*KeyStorage) Get ¶
func (k *KeyStorage) Get( ctx context.Context, account *types.AccountIdentifier, ) (*keys.KeyPair, error)
Get returns a *keys.KeyPair for an AccountIdentifier, if it exists.
func (*KeyStorage) GetAllAccounts ¶
func (k *KeyStorage) GetAllAccounts(ctx context.Context) ([]*types.AccountIdentifier, error)
GetAllAccounts returns all AccountIdentifiers in key storage.
func (*KeyStorage) GetAllAccountsTransactional ¶
func (k *KeyStorage) GetAllAccountsTransactional( ctx context.Context, dbTx database.Transaction, ) ([]*types.AccountIdentifier, error)
GetAllAccountsTransactional returns all AccountIdentifiers in key storage.
func (*KeyStorage) GetTransactional ¶
func (k *KeyStorage) GetTransactional( ctx context.Context, dbTx database.Transaction, account *types.AccountIdentifier, ) (*keys.KeyPair, error)
GetTransactional returns a *keys.KeyPair for an AccountIdentifier in a database.Transaction, if it exists.
func (*KeyStorage) ImportAccounts ¶
func (k *KeyStorage) ImportAccounts(ctx context.Context, accounts []*PrefundedAccount) error
ImportAccounts loads a set of prefunded accounts into key storage.
func (*KeyStorage) RandomAccount ¶
func (k *KeyStorage) RandomAccount(ctx context.Context) (*types.AccountIdentifier, error)
RandomAccount returns a random account from all accounts.
func (*KeyStorage) Sign ¶
func (k *KeyStorage) Sign( ctx context.Context, payloads []*types.SigningPayload, ) ([]*types.Signature, error)
Sign attempts to sign a slice of *types.SigningPayload with the keys in KeyStorage.
func (*KeyStorage) Store ¶
func (k *KeyStorage) Store( ctx context.Context, account *types.AccountIdentifier, keyPair *keys.KeyPair, ) error
Store saves a keys.KeyPair for a given address. If the address already exists, an error is returned.
func (*KeyStorage) StoreTransactional ¶
func (k *KeyStorage) StoreTransactional( ctx context.Context, account *types.AccountIdentifier, keyPair *keys.KeyPair, dbTx database.Transaction, ) error
StoreTransactional stores a key in a database transaction.
type PrefundedAccount ¶
type PrefundedAccount struct { PrivateKeyHex string `json:"privkey"` AccountIdentifier *types.AccountIdentifier `json:"account_identifier"` CurveType types.CurveType `json:"curve_type"` Currency *types.Currency `json:"currency"` }
PrefundedAccount is used to load prefunded addresses into key storage.