ldb

package
v0.0.0-...-7dd6d26 Latest Latest
Warning

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

Go to latest
Published: May 11, 2015 License: ISC Imports: 15 Imported by: 4

Documentation

Overview

Package ldb implements an instance of the database package backed by leveldb.

Database version number is stored in a flat file <dbname>.ver Currently a single (littlendian) integer in the file. If there is additional data to save in the future, the presence of additional data can be indicated by changing the version number, then parsing the file differently.

Index

Constants

This section is empty.

Variables

View Source
var CurrentDBVersion int32 = 1

CurrentDBVersion is the database version.

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 LevelDb

type LevelDb struct {
	// contains filtered or unexported fields
}

LevelDb holds internal state for databse.

func (*LevelDb) Close

func (db *LevelDb) Close() error

Close cleanly shuts down database, syncing all data.

func (*LevelDb) DeleteAddrIndex

func (db *LevelDb) DeleteAddrIndex() error

DeleteAddrIndex deletes the entire addrindex stored within the DB. It also resets the cached in-memory metadata about the addr index.

func (*LevelDb) DropAfterBlockBySha

func (db *LevelDb) DropAfterBlockBySha(sha *btcwire.ShaHash) (rerr error)

DropAfterBlockBySha will remove any blocks from the database after the given block.

func (*LevelDb) ExistsSha

func (db *LevelDb) ExistsSha(sha *btcwire.ShaHash) (bool, error)

ExistsSha looks up the given block hash returns true if it is present in the database.

func (*LevelDb) ExistsTxSha

func (db *LevelDb) ExistsTxSha(txsha *btcwire.ShaHash) (bool, error)

ExistsTxSha returns if the given tx sha exists in the database

func (*LevelDb) FetchAddrIndexTip

func (db *LevelDb) FetchAddrIndexTip() (*btcwire.ShaHash, int64, error)

FetchAddrIndexTip returns the hash and block height of the most recent block whose transactions have been indexed by address. It will return ErrAddrIndexDoesNotExist along with a zero hash, and -1 if the addrindex hasn't yet been built up.

func (*LevelDb) FetchBlockBySha

func (db *LevelDb) FetchBlockBySha(sha *btcwire.ShaHash) (blk *btcutil.Block, err error)

FetchBlockBySha - return a btcutil Block

func (*LevelDb) FetchBlockHeaderBySha

func (db *LevelDb) FetchBlockHeaderBySha(sha *btcwire.ShaHash) (bh *btcwire.BlockHeader, err error)

FetchBlockHeaderBySha - return a btcwire ShaHash

func (*LevelDb) FetchBlockHeightBySha

func (db *LevelDb) FetchBlockHeightBySha(sha *btcwire.ShaHash) (int64, error)

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

func (*LevelDb) FetchBlockShaByHeight

func (db *LevelDb) FetchBlockShaByHeight(height int64) (sha *btcwire.ShaHash, err error)

FetchBlockShaByHeight returns a block hash based on its height in the block chain.

func (*LevelDb) FetchHeightRange

func (db *LevelDb) FetchHeightRange(startHeight, endHeight int64) (rshalist []btcwire.ShaHash, err 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'.

func (*LevelDb) FetchTxBySha

func (db *LevelDb) FetchTxBySha(txsha *btcwire.ShaHash) ([]*database.TxListReply, error)

FetchTxBySha returns some data for the given Tx Sha.

func (*LevelDb) FetchTxByShaList

func (db *LevelDb) FetchTxByShaList(txShaList []*btcwire.ShaHash) []*database.TxListReply

FetchTxByShaList returns the most recent tx of the name fully spent or not

func (*LevelDb) FetchTxsForAddr

func (db *LevelDb) FetchTxsForAddr(addr btcutil.Address, skip int,
	limit int) ([]*database.TxListReply, error)

FetchTxsForAddr looks up and returns all transactions which either spend from a previously created output of the passed address, or create a new output locked to the passed address. The, `limit` parameter should be the max number of transactions to be returned. Additionally, if the caller wishes to seek forward in the results some amount, the 'seek' represents how many results to skip.

func (*LevelDb) FetchUnSpentTxByShaList

func (db *LevelDb) FetchUnSpentTxByShaList(txShaList []*btcwire.ShaHash) []*database.TxListReply

FetchUnSpentTxByShaList given a array of ShaHash, look up the transactions and return them in a TxListReply array.

func (*LevelDb) InsertBlock

func (db *LevelDb) InsertBlock(block *btcutil.Block) (height int64, rerr 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.

func (*LevelDb) InsertTx

func (db *LevelDb) InsertTx(txsha *btcwire.ShaHash, height int64, txoff int, txlen int, spentbuf []byte) (err error)

InsertTx inserts a tx hash and its associated data into the database.

func (*LevelDb) NewestSha

func (db *LevelDb) NewestSha() (rsha *btcwire.ShaHash, rblkid int64, err 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.

func (*LevelDb) RollbackClose

func (db *LevelDb) RollbackClose() error

RollbackClose this is part of the database.Db interface and should discard recent changes to the db and the close the db. This currently just does a clean shutdown.

func (*LevelDb) Sync

func (db *LevelDb) Sync() error

Sync verifies that the database is coherent on disk, and no outstanding transactions are in flight.

func (*LevelDb) UpdateAddrIndexForBlock

func (db *LevelDb) UpdateAddrIndexForBlock(blkSha *btcwire.ShaHash, blkHeight int64, addrIndex database.BlockAddrIndex) error

UpdateAddrIndexForBlock updates the stored addrindex with passed index information for a particular block height. Additionally, it will update the stored meta-data related to the curent tip of the addr index. These two operations are performed in an atomic transaction which is commited before the function returns. Transactions indexed by address are stored with the following format:

  • prefix || hash160 || blockHeight || txoffset || txlen

Indexes are stored purely in the key, with blank data for the actual value in order to facilitate ease of iteration by their shared prefix and also to allow limiting the number of returned transactions (RPC). Alternatively, indexes for each address could be stored as an append-only list for the stored value. However, this add unnecessary overhead when storing and retrieving since the entire list must be fetched each time.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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