Documentation ¶
Overview ¶
Package memdb implements an instance of the database package that uses memory for the block storage.
This is primary used for testing purposes as normal operations require a persistent block storage mechanism which this is not.
Index ¶
- Variables
- func CreateDB(args ...interface{}) (database.Db, error)
- func OpenDB(args ...interface{}) (database.Db, error)
- type MemDb
- func (db *MemDb) Close() error
- func (db *MemDb) DeleteAddrIndex() error
- func (db *MemDb) DropAfterBlockBySha(sha *btcwire.ShaHash) error
- func (db *MemDb) ExistsSha(sha *btcwire.ShaHash) (bool, error)
- func (db *MemDb) ExistsTxSha(sha *btcwire.ShaHash) (bool, error)
- func (db *MemDb) FetchAddrIndexTip() (*btcwire.ShaHash, int64, error)
- func (db *MemDb) FetchBlockBySha(sha *btcwire.ShaHash) (*btcutil.Block, error)
- func (db *MemDb) FetchBlockHeaderBySha(sha *btcwire.ShaHash) (*btcwire.BlockHeader, error)
- func (db *MemDb) FetchBlockHeightBySha(sha *btcwire.ShaHash) (int64, error)
- func (db *MemDb) FetchBlockShaByHeight(height int64) (*btcwire.ShaHash, error)
- func (db *MemDb) FetchHeightRange(startHeight, endHeight int64) ([]btcwire.ShaHash, error)
- func (db *MemDb) FetchTxBySha(txHash *btcwire.ShaHash) ([]*database.TxListReply, error)
- func (db *MemDb) FetchTxByShaList(txShaList []*btcwire.ShaHash) []*database.TxListReply
- func (db *MemDb) FetchTxsForAddr(btcutil.Address, int, int) ([]*database.TxListReply, error)
- func (db *MemDb) FetchUnSpentTxByShaList(txShaList []*btcwire.ShaHash) []*database.TxListReply
- func (db *MemDb) InsertBlock(block *btcutil.Block) (int64, error)
- func (db *MemDb) NewestSha() (*btcwire.ShaHash, int64, error)
- func (db *MemDb) RollbackClose() error
- func (db *MemDb) Sync() error
- func (db *MemDb) UpdateAddrIndexForBlock(*btcwire.ShaHash, int64, database.BlockAddrIndex) error
Constants ¶
This section is empty.
Variables ¶
var (
ErrDbClosed = errors.New("database is closed")
)
Errors that the various database functions may return.
Functions ¶
Types ¶
type MemDb ¶
type MemDb struct { // Embed a mutex for safe concurrent access. sync.Mutex // contains filtered or unexported fields }
MemDb is a concrete implementation of the database.Db interface which provides a memory-only database. Since it is memory-only, it is obviously not persistent and is mostly only useful for testing purposes.
func (*MemDb) Close ¶
Close cleanly shuts down database. This is part of the database.Db interface implementation.
All data is purged upon close with this implementation since it is a memory-only database.
func (*MemDb) DeleteAddrIndex ¶
DeleteAddrIndex isn't currently implemented. This is a part of the database.Db interface implementation.
func (*MemDb) DropAfterBlockBySha ¶
DropAfterBlockBySha removes any blocks from the database after the given block. This is different than a simple truncate since the spend information for each block must also be unwound. This is part of the database.Db interface implementation.
func (*MemDb) ExistsSha ¶
ExistsSha returns whether or not the given block hash is present in the database. This is part of the database.Db interface implementation.
func (*MemDb) ExistsTxSha ¶
ExistsTxSha returns whether or not the given transaction hash is present in the database and is not fully spent. This is part of the database.Db interface implementation.
func (*MemDb) FetchAddrIndexTip ¶
FetchAddrIndexTip isn't currently implemented. This is a part of the database.Db interface implementation.
func (*MemDb) FetchBlockBySha ¶
FetchBlockBySha returns a btcutil.Block. The implementation may cache the underlying data if desired. This is part of the database.Db interface implementation.
This implementation does not use any additional cache since the entire database is already in memory.
func (*MemDb) FetchBlockHeaderBySha ¶
FetchBlockHeaderBySha returns a btcwire.BlockHeader for the given sha. The implementation may cache the underlying data if desired. This is part of the database.Db interface implementation.
This implementation does not use any additional cache since the entire database is already in memory.
func (*MemDb) FetchBlockHeightBySha ¶
FetchBlockHeightBySha returns the block height for the given hash. This is part of the database.Db interface implementation.
func (*MemDb) FetchBlockShaByHeight ¶
FetchBlockShaByHeight returns a block hash based on its height in the block chain. This is part of the database.Db interface implementation.
func (*MemDb) FetchHeightRange ¶
FetchHeightRange looks up a range of blocks by the start and ending heights. Fetch is inclusive of the start height and exclusive of the ending height. To fetch all hashes from the start height until no more are present, use the special id `AllShas'. This is part of the database.Db interface implementation.
func (*MemDb) FetchTxBySha ¶
FetchTxBySha returns some data for the given transaction hash. The implementation may cache the underlying data if desired. This is part of the database.Db interface implementation.
This implementation does not use any additional cache since the entire database is already in memory.
func (*MemDb) FetchTxByShaList ¶
func (db *MemDb) FetchTxByShaList(txShaList []*btcwire.ShaHash) []*database.TxListReply
FetchTxByShaList returns a TxListReply given an array of transaction hashes. This function differs from FetchUnSpentTxByShaList in that it returns the most recent version of fully spent transactions. Due to the increased number of transaction fetches, this function is typically more expensive than the unspent counterpart, however the specific performance details depend on the concrete implementation. The implementation may cache the underlying data if desired. This is part of the database.Db interface implementation.
To fetch all versions of a specific transaction, call FetchTxBySha.
This implementation does not use any additional cache since the entire database is already in memory.
func (*MemDb) FetchTxsForAddr ¶
FetchTxsForAddr isn't currently implemented. This is a part of the database.Db interface implementation.
func (*MemDb) FetchUnSpentTxByShaList ¶
func (db *MemDb) FetchUnSpentTxByShaList(txShaList []*btcwire.ShaHash) []*database.TxListReply
FetchUnSpentTxByShaList returns a TxListReply given an array of transaction hashes. Any transactions which are fully spent will indicate they do not exist by setting the Err field to TxShaMissing. The implementation may cache the underlying data if desired. This is part of the database.Db interface implementation.
To obtain results which do contain the most recent version of a fully spent transactions, call FetchTxByShaList. To fetch all versions of a specific transaction, call FetchTxBySha.
This implementation does not use any additional cache since the entire database is already in memory.
func (*MemDb) InsertBlock ¶
InsertBlock inserts raw block and transaction data from a block into the database. The first block inserted into the database will be treated as the genesis block. Every subsequent block insert requires the referenced parent block to already exist. This is part of the database.Db interface implementation.
func (*MemDb) NewestSha ¶
NewestSha returns the hash and block height of the most recent (end) block of the block chain. It will return the zero hash, -1 for the block height, and no error (nil) if there are not any blocks in the database yet. This is part of the database.Db interface implementation.
func (*MemDb) RollbackClose ¶
RollbackClose discards the recent database changes to the previously saved data at last Sync and closes the database. This is part of the database.Db interface implementation.
The database is completely purged on close with this implementation since the entire database is only in memory. As a result, this function behaves no differently than Close.
func (*MemDb) Sync ¶
Sync verifies that the database is coherent on disk and no outstanding transactions are in flight. This is part of the database.Db interface implementation.
This implementation does not write any data to disk, so this function only grabs a lock to ensure it doesn't return until other operations are complete.
func (*MemDb) UpdateAddrIndexForBlock ¶
UpdateAddrIndexForBlock isn't currently implemented. This is a part of the database.Db interface implementation.