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 BlockStorage
- func (b *BlockStorage) BootstrapBalances(ctx context.Context, bootstrapBalancesFile string, ...) error
- func (b *BlockStorage) CreateBlockCache(ctx context.Context) []*types.BlockIdentifier
- func (b *BlockStorage) GetAllAccountCurrency(ctx context.Context) ([]*reconciler.AccountCurrency, error)
- func (b *BlockStorage) GetBalance(ctx context.Context, account *types.AccountIdentifier, ...) (*types.Amount, *types.BlockIdentifier, error)
- func (b *BlockStorage) GetBlock(ctx context.Context, blockIdentifier *types.BlockIdentifier) (*types.Block, error)
- func (b *BlockStorage) GetHeadBlockIdentifier(ctx context.Context) (*types.BlockIdentifier, error)
- func (b *BlockStorage) RemoveBlock(ctx context.Context, blockIdentifier *types.BlockIdentifier) ([]*parser.BalanceChange, error)
- func (b *BlockStorage) SetBalance(ctx context.Context, dbTransaction DatabaseTransaction, ...) error
- func (b *BlockStorage) SetNewStartIndex(ctx context.Context, startIndex int64) error
- func (b *BlockStorage) StoreBlock(ctx context.Context, block *types.Block) ([]*parser.BalanceChange, error)
- func (b *BlockStorage) StoreHeadBlockIdentifier(ctx context.Context, transaction DatabaseTransaction, ...) error
- func (b *BlockStorage) UpdateBalance(ctx context.Context, dbTransaction DatabaseTransaction, ...) error
- type BootstrapBalance
- type CounterStorage
- type Database
- type DatabaseTransaction
- type Helper
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" // ActiveReconciliationCounter is the number of active // reconciliations performed. ActiveReconciliationCounter = "active_reconciliations" // InactiveReconciliationCounter is the number of inactive // reconciliations performed. InactiveReconciliationCounter = "inactive_reconciliations" )
Variables ¶
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") // ErrAccountNotFound is returned when an account // is not found in BlockStorage. 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") // ErrDuplicateBlockHash is returned when a block hash // cannot be stored because it is a duplicate. ErrDuplicateBlockHash = errors.New("duplicate block hash") // ErrDuplicateTransactionHash is returned when a transaction // hash cannot be stored because it is a duplicate. ErrDuplicateTransactionHash = errors.New("duplicate transaction hash") // ErrDuplicateKey is returned when trying to store a key that // already exists (this is used by storeHash). ErrDuplicateKey = errors.New("duplicate key") )
Functions ¶
func GetBalanceKey ¶ added in v0.2.0
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 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, helper Helper, ) *BlockStorage
NewBlockStorage returns a new BlockStorage.
func (*BlockStorage) BootstrapBalances ¶
func (b *BlockStorage) 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 (*BlockStorage) CreateBlockCache ¶ added in v0.2.0
func (b *BlockStorage) CreateBlockCache(ctx context.Context) []*types.BlockIdentifier
CreateBlockCache populates a slice of blocks with the most recent ones in storage.
func (*BlockStorage) GetAllAccountCurrency ¶ added in v0.2.1
func (b *BlockStorage) 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 (*BlockStorage) GetBalance ¶
func (b *BlockStorage) 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 (*BlockStorage) GetBlock ¶
func (b *BlockStorage) GetBlock( ctx context.Context, blockIdentifier *types.BlockIdentifier, ) (*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) RemoveBlock ¶
func (b *BlockStorage) RemoveBlock( ctx context.Context, blockIdentifier *types.BlockIdentifier, ) ([]*parser.BalanceChange, 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) SetBalance ¶ added in v0.2.0
func (b *BlockStorage) 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 (*BlockStorage) SetNewStartIndex ¶ added in v0.2.0
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) StoreBlock ¶
func (b *BlockStorage) StoreBlock( ctx context.Context, block *types.Block, ) ([]*parser.BalanceChange, error)
StoreBlock stores a block or returns an error. StoreBlock also stores the block hash and all its transaction hashes for duplicate detection.
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.
func (*BlockStorage) UpdateBalance ¶
func (b *BlockStorage) 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 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. TODO: Must be exported for use
type CounterStorage ¶ added in v0.3.0
type CounterStorage struct {
// contains filtered or unexported fields
}
CounterStorage implements counter-specific storage methods on top of a Database and DatabaseTransaction interface.
func NewCounterStorage ¶ added in v0.3.0
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 Helper ¶ added in v0.2.0
type Helper interface {
AccountBalance(
ctx context.Context,
account *types.AccountIdentifier,
currency *types.Currency,
block *types.BlockIdentifier,
) (*types.Amount, error)
ExemptFunc() parser.ExemptOperation
Asserter() *asserter.Asserter
}
Helper functions are used by BlockStorage to process blocks. Defining an interface allows the client to determine if they wish to query the node for certain information or use another datastore.