memdb

package
Version: v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2016 License: ISC Imports: 9 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) DropAddrIndexForBlock

func (db *MemDb) DropAddrIndexForBlock(*chainhash.Hash, int64,
	database.BlockAddrIndex) error

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

func (*MemDb) DropAfterBlockBySha

func (db *MemDb) DropAfterBlockBySha(sha *chainhash.Hash) 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 *chainhash.Hash) (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 *chainhash.Hash) (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() (*chainhash.Hash, int64, error)

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

func (*MemDb) FetchBlockBySha

func (db *MemDb) FetchBlockBySha(sha *chainhash.Hash) (*dcrutil.Block, error)

FetchBlockBySha returns a dcrutil.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 *chainhash.Hash) (*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 *chainhash.Hash) (int64, 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 int64) (*chainhash.Hash, 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 int64) ([]chainhash.Hash, 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 *chainhash.Hash) ([]*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 []*chainhash.Hash) []*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(dcrutil.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 []*chainhash.Hash) []*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 *dcrutil.Block) (int64, 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() (*chainhash.Hash, int64, 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) PurgeAddrIndex

func (db *MemDb) PurgeAddrIndex() error

PurgeAddrIndex isn't currently implemented. This is a 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(*chainhash.Hash, int64,
	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
t or T : Toggle theme light dark auto
y or Y : Canonical URL