Documentation
¶
Index ¶
- Constants
- Variables
- func GetBalanceKey(account *types.AccountIdentifier, currency *types.Currency) []byte
- type BadgerStorage
- func (b *BadgerStorage) Close(ctx context.Context) error
- func (b *BadgerStorage) Get(ctx context.Context, key []byte) (bool, []byte, error)
- func (b *BadgerStorage) NewDatabaseTransaction(ctx context.Context, write bool) DatabaseTransaction
- func (b *BadgerStorage) Scan(ctx context.Context, prefix []byte) ([][]byte, error)
- func (b *BadgerStorage) Set(ctx context.Context, key []byte, value []byte) error
- type BadgerTransaction
- func (b *BadgerTransaction) Commit(context.Context) error
- func (b *BadgerTransaction) Delete(ctx context.Context, key []byte) error
- func (b *BadgerTransaction) Discard(context.Context)
- func (b *BadgerTransaction) Get(ctx context.Context, key []byte) (bool, []byte, error)
- func (b *BadgerTransaction) Set(ctx context.Context, key []byte, value []byte) error
- type BalanceStorage
- func (b *BalanceStorage) AddingBlock(ctx context.Context, block *types.Block, transaction DatabaseTransaction) (CommitWorker, error)
- func (b *BalanceStorage) BootstrapBalances(ctx context.Context, bootstrapBalancesFile string, ...) error
- func (b *BalanceStorage) GetAllAccountCurrency(ctx context.Context) ([]*reconciler.AccountCurrency, error)
- func (b *BalanceStorage) GetBalance(ctx context.Context, account *types.AccountIdentifier, ...) (*types.Amount, *types.BlockIdentifier, error)
- func (b *BalanceStorage) Initialize(helper BalanceStorageHelper, handler BalanceStorageHandler)
- 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 DatabaseTransaction) (CommitWorker, error)
- func (b *BalanceStorage) SetBalance(ctx context.Context, dbTransaction DatabaseTransaction, ...) error
- func (b *BalanceStorage) UpdateBalance(ctx context.Context, dbTransaction DatabaseTransaction, ...) 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) CreateBlockCache(ctx context.Context) []*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) GetHeadBlockIdentifier(ctx context.Context) (*types.BlockIdentifier, error)
- func (b *BlockStorage) GetHeadBlockIdentifierTransactional(ctx context.Context, transaction DatabaseTransaction) (*types.BlockIdentifier, error)
- func (b *BlockStorage) Initialize(workers []BlockWorker)
- 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 DatabaseTransaction, ...) error
- type BlockWorker
- type BootstrapBalance
- type Broadcast
- type BroadcastStorage
- func (b *BroadcastStorage) AddingBlock(ctx context.Context, block *types.Block, transaction DatabaseTransaction) (CommitWorker, error)
- func (b *BroadcastStorage) Broadcast(ctx context.Context, sender string, intent []*types.Operation, ...) 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) LockedAddresses(ctx context.Context) ([]string, error)
- func (b *BroadcastStorage) RemovingBlock(ctx context.Context, block *types.Block, transaction DatabaseTransaction) (CommitWorker, error)
- type BroadcastStorageHandler
- type BroadcastStorageHelper
- type CoinStorage
- func (c *CoinStorage) AddingBlock(ctx context.Context, block *types.Block, transaction DatabaseTransaction) (CommitWorker, error)
- func (c *CoinStorage) GetCoins(ctx context.Context, accountIdentifier *types.AccountIdentifier) ([]*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 DatabaseTransaction) (CommitWorker, error)
- type CoinStorageHelper
- type CommitWorker
- type CounterStorage
- type Database
- type DatabaseTransaction
- type Key
- type KeyStorage
- func (k *KeyStorage) Get(ctx context.Context, address string) (*keys.KeyPair, error)
- func (k *KeyStorage) GetAllAddresses(ctx context.Context) ([]string, error)
- func (k *KeyStorage) ImportAccounts(ctx context.Context, accounts []*PrefundedAccount) error
- func (k *KeyStorage) RandomAddress(ctx context.Context) (string, error)
- func (k *KeyStorage) Sign(ctx context.Context, payloads []*types.SigningPayload) ([]*types.Signature, error)
- func (k *KeyStorage) Store(ctx context.Context, address string, keyPair *keys.KeyPair) error
- type PrefundedAccount
Constants ¶
const ( // DefaultCacheSize is 0 MB. DefaultCacheSize = 0 // DefaultBfCacheSize is 10 MB. DefaultBfCacheSize = 10 << 20 // DefaultValueLogFileSize is 100 MB. DefaultValueLogFileSize = 100 << 20 )
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" )
Variables ¶
var ( // ErrAccountNotFound is returned when an account // is not found in BalanceStorage. ErrAccountNotFound = errors.New("account not found") // ErrNegativeBalance is returned when an account // balance goes negative as the result of an operation. ErrNegativeBalance = errors.New("negative balance") )
var ( // ErrHeadBlockNotFound is returned when there is no // head block found in BlockStorage. ErrHeadBlockNotFound = errors.New("head block not found") // ErrBlockNotFound is returned when a block is not // found in BlockStorage. ErrBlockNotFound = errors.New("block not found") // ErrDuplicateKey is returned when a key // cannot be stored because it is a duplicate. ErrDuplicateKey = errors.New("duplicate key") // ErrDuplicateTransactionHash is returned when a transaction // hash cannot be stored because it is a duplicate. ErrDuplicateTransactionHash = errors.New("duplicate transaction hash") )
var ( // ErrAddrExists is returned when key storage already // contains an address. ErrAddrExists = errors.New("Address already exists") )
Functions ¶
func GetBalanceKey ¶
func GetBalanceKey(account *types.AccountIdentifier, currency *types.Currency) []byte
GetBalanceKey returns a deterministic hash of an types.Account + types.Currency.
Types ¶
type BadgerStorage ¶
type BadgerStorage struct {
// contains filtered or unexported fields
}
BadgerStorage is a wrapper around Badger DB that implements the Database interface.
func (*BadgerStorage) Close ¶
func (b *BadgerStorage) Close(ctx context.Context) error
Close closes the database to prevent corruption. The caller should defer this in main.
func (*BadgerStorage) NewDatabaseTransaction ¶
func (b *BadgerStorage) NewDatabaseTransaction( ctx context.Context, write bool, ) DatabaseTransaction
NewDatabaseTransaction creates a new BadgerTransaction. If the transaction will not modify any values, pass in false for the write parameter (this allows for optimization within the Badger DB).
type BadgerTransaction ¶
type BadgerTransaction struct {
// contains filtered or unexported fields
}
BadgerTransaction is a wrapper around a Badger DB transaction that implements the DatabaseTransaction interface.
func (*BadgerTransaction) Commit ¶
func (b *BadgerTransaction) Commit(context.Context) error
Commit attempts to commit and discard the transaction.
func (*BadgerTransaction) Delete ¶
func (b *BadgerTransaction) Delete(ctx context.Context, key []byte) error
Delete removes the key and its value within the transaction.
func (*BadgerTransaction) Discard ¶
func (b *BadgerTransaction) Discard(context.Context)
Discard discards an open transaction. All transactions must be either discarded or committed.
type BalanceStorage ¶
type BalanceStorage struct {
// contains filtered or unexported fields
}
BalanceStorage implements block specific storage methods on top of a Database and DatabaseTransaction interface.
func NewBalanceStorage ¶
func NewBalanceStorage( db Database, ) *BalanceStorage
NewBalanceStorage returns a new BalanceStorage.
func (*BalanceStorage) AddingBlock ¶
func (b *BalanceStorage) AddingBlock( ctx context.Context, block *types.Block, transaction DatabaseTransaction, ) (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) GetAllAccountCurrency ¶
func (b *BalanceStorage) GetAllAccountCurrency( ctx context.Context, ) ([]*reconciler.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, headBlock *types.BlockIdentifier, ) (*types.Amount, *types.BlockIdentifier, error)
GetBalance returns all the balances of a types.AccountIdentifier and the types.BlockIdentifier it was last updated at.
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) 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 DatabaseTransaction, ) (CommitWorker, error)
RemovingBlock is called by BlockStorage when removing a block from storage.
func (*BalanceStorage) SetBalance ¶
func (b *BalanceStorage) SetBalance( ctx context.Context, dbTransaction DatabaseTransaction, 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. This is particularly useful for bootstrapping balances.
func (*BalanceStorage) UpdateBalance ¶
func (b *BalanceStorage) UpdateBalance( ctx context.Context, dbTransaction DatabaseTransaction, change *parser.BalanceChange, parentBlock *types.BlockIdentifier, ) 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 }
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 Asserter() *asserter.Asserter }
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 and DatabaseTransaction interface.
func NewBlockStorage ¶
func NewBlockStorage( db 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) CreateBlockCache ¶
func (b *BlockStorage) CreateBlockCache(ctx context.Context) []*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 DatabaseTransaction, ) (*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.
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 DatabaseTransaction, ) (*types.BlockIdentifier, error)
GetHeadBlockIdentifierTransactional returns the head block identifier, if it exists, in the context of a DatabaseTransaction.
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) 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 DatabaseTransaction, blockIdentifier *types.BlockIdentifier, ) error
StoreHeadBlockIdentifier stores a block identifier or returns an error.
type BlockWorker ¶
type BlockWorker interface { AddingBlock(context.Context, *types.Block, DatabaseTransaction) (CommitWorker, error) RemovingBlock(context.Context, *types.Block, DatabaseTransaction) (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 *types.TransactionIdentifier `json:"identifier"` Sender string `json:"sender"` 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, confirmationDepth int64, 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 DatabaseTransaction, ) (CommitWorker, error)
AddingBlock is called by BlockStorage when adding a block.
func (*BroadcastStorage) Broadcast ¶
func (b *BroadcastStorage) Broadcast( ctx context.Context, sender string, intent []*types.Operation, transactionIdentifier *types.TransactionIdentifier, payload string, ) 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) LockedAddresses ¶
func (b *BroadcastStorage) LockedAddresses(ctx context.Context) ([]string, error)
LockedAddresses returns all addresses 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 DatabaseTransaction, ) (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, *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, *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, *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, DatabaseTransaction, ) (*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, 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, helper CoinStorageHelper, asserter *asserter.Asserter, ) *CoinStorage
NewCoinStorage returns a new CoinStorage.
func (*CoinStorage) AddingBlock ¶
func (c *CoinStorage) AddingBlock( ctx context.Context, block *types.Block, transaction DatabaseTransaction, ) (CommitWorker, error)
AddingBlock is called by BlockStorage when adding a block.
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) 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 DatabaseTransaction, ) (CommitWorker, error)
RemovingBlock is called by BlockStorage when removing a block.
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, DatabaseTransaction, ) (*types.BlockIdentifier, error) }
CoinStorageHelper is used by CoinStorage to determine at which block a Coin set is valid.
type CommitWorker ¶
CommitWorker is returned by a BlockWorker to be called after changes have been committed. It is common to put logging activities in here (that shouldn't be printed until the block is committed).
type CounterStorage ¶
type CounterStorage struct {
// contains filtered or unexported fields
}
CounterStorage implements counter-specific storage methods on top of a Database and DatabaseTransaction interface.
func NewCounterStorage ¶
func NewCounterStorage( db Database, ) *CounterStorage
NewCounterStorage returns a new CounterStorage.
type Database ¶
type Database interface { NewDatabaseTransaction(context.Context, bool) DatabaseTransaction Close(context.Context) error Set(context.Context, []byte, []byte) error Get(context.Context, []byte) (bool, []byte, error) Scan(ctx context.Context, prefix []byte) ([][]byte, error) }
Database is an interface that provides transactional access to a KV store.
type DatabaseTransaction ¶
type DatabaseTransaction interface { Set(context.Context, []byte, []byte) error Get(context.Context, []byte) (bool, []byte, error) Delete(context.Context, []byte) error Commit(context.Context) error Discard(context.Context) }
DatabaseTransaction is an interface that provides access to a KV store within some transaction context provided by a Database.
type Key ¶
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 and DatabaseTransaction interface.
func NewKeyStorage ¶
func NewKeyStorage( db Database, ) *KeyStorage
NewKeyStorage returns a new KeyStorage.
func (*KeyStorage) GetAllAddresses ¶
func (k *KeyStorage) GetAllAddresses(ctx context.Context) ([]string, error)
GetAllAddresses returns all addresses in key storage.
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) RandomAddress ¶
func (k *KeyStorage) RandomAddress(ctx context.Context) (string, error)
RandomAddress returns a random address from all addresses.
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.