memdb

package
v0.0.0-...-aea6043 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2015 License: ISC Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	ErrDbClosed = errors.New("database is closed")
)

Errors that the various database functions may return.

Functions

func CreateDB

func CreateDB(args ...interface{}) (database.Db, error)

CreateDB creates, initializes, and opens a database for use.

func OpenDB

func OpenDB(args ...interface{}) (database.Db, error)

OpenDB opens an existing database for use.

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

func (db *MemDb) Close() error

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

func (db *MemDb) DeleteAddrIndex() error

DeleteAddrIndex isn't currently implemented. This is a part of the database.Db interface implementation.

func (*MemDb) DropAfterBlockBySha

func (db *MemDb) DropAfterBlockBySha(sha *wire.ShaHash) error

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

func (db *MemDb) ExistsSha(sha *wire.ShaHash) (bool, error)

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

func (db *MemDb) ExistsTxSha(sha *wire.ShaHash) (bool, error)

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

func (db *MemDb) FetchAddrIndexTip() (*wire.ShaHash, int32, error)

FetchAddrIndexTip isn't currently implemented. This is a part of the database.Db interface implementation.

func (*MemDb) FetchBlockBySha

func (db *MemDb) FetchBlockBySha(sha *wire.ShaHash) (*btcutil.Block, error)

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

func (db *MemDb) FetchBlockHeaderBySha(sha *wire.ShaHash) (*wire.BlockHeader, error)

FetchBlockHeaderBySha returns a wire.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

func (db *MemDb) FetchBlockHeightBySha(sha *wire.ShaHash) (int32, error)

FetchBlockHeightBySha returns the block height for the given hash. This is part of the database.Db interface implementation.

func (*MemDb) FetchBlockShaByHeight

func (db *MemDb) FetchBlockShaByHeight(height int32) (*wire.ShaHash, error)

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

func (db *MemDb) FetchHeightRange(startHeight, endHeight int32) ([]wire.ShaHash, error)

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

func (db *MemDb) FetchTxBySha(txHash *wire.ShaHash) ([]*database.TxListReply, error)

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 []*wire.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

func (db *MemDb) FetchTxsForAddr(btcutil.Address, int, int) ([]*database.TxListReply, error)

FetchTxsForAddr isn't currently implemented. This is a part of the database.Db interface implementation.

func (*MemDb) FetchUnSpentTxByShaList

func (db *MemDb) FetchUnSpentTxByShaList(txShaList []*wire.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

func (db *MemDb) InsertBlock(block *btcutil.Block) (int32, error)

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

func (db *MemDb) NewestSha() (*wire.ShaHash, int32, error)

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

func (db *MemDb) RollbackClose() error

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

func (db *MemDb) Sync() error

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

func (db *MemDb) UpdateAddrIndexForBlock(*wire.ShaHash, int32,
	database.BlockAddrIndex) error

UpdateAddrIndexForBlock isn't currently implemented. This is a part of the database.Db interface implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL