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 ¶
- Variables
- func CreateDB(args ...interface{}) (database.Db, error)
- func OpenDB(args ...interface{}) (database.Db, error)
- type LevelDb
- func (db *LevelDb) Close() error
- func (db *LevelDb) DropAddrIndexForBlock(blkSha *chainhash.Hash, blkHeight int64, addrIndexes database.BlockAddrIndex) (rerr error)
- func (db *LevelDb) DropAfterBlockBySha(sha *chainhash.Hash) (rerr error)
- func (db *LevelDb) ExistsSha(sha *chainhash.Hash) (bool, error)
- func (db *LevelDb) ExistsTxSha(txsha *chainhash.Hash) (bool, error)
- func (db *LevelDb) FetchAddrIndexTip() (*chainhash.Hash, int64, error)
- func (db *LevelDb) FetchBlockBySha(sha *chainhash.Hash) (blk *dcrutil.Block, err error)
- func (db *LevelDb) FetchBlockHeaderBySha(sha *chainhash.Hash) (bh *wire.BlockHeader, err error)
- func (db *LevelDb) FetchBlockHeightBySha(sha *chainhash.Hash) (int64, error)
- func (db *LevelDb) FetchBlockShaByHeight(height int64) (sha *chainhash.Hash, err error)
- func (db *LevelDb) FetchHeightRange(startHeight, endHeight int64) (rshalist []chainhash.Hash, err error)
- func (db *LevelDb) FetchTxBySha(txsha *chainhash.Hash) ([]*database.TxListReply, error)
- func (db *LevelDb) FetchTxByShaList(txShaList []*chainhash.Hash) []*database.TxListReply
- func (db *LevelDb) FetchTxsForAddr(addr dcrutil.Address, skip int, limit int, reverse bool) ([]*database.TxListReply, int, error)
- func (db *LevelDb) FetchUnSpentTxByShaList(txShaList []*chainhash.Hash) []*database.TxListReply
- func (db *LevelDb) InsertBlock(block *dcrutil.Block) (height int64, rerr error)
- func (db *LevelDb) InsertTx(txsha *chainhash.Hash, height int64, idx uint32, txoff int, txlen int, ...) (err error)
- func (db *LevelDb) NewestSha() (rsha *chainhash.Hash, rblkid int64, err error)
- func (db *LevelDb) PurgeAddrIndex() error
- func (db *LevelDb) RollbackClose() error
- func (db *LevelDb) Sync() error
- func (db *LevelDb) UpdateAddrIndexForBlock(blkSha *chainhash.Hash, blkHeight int64, addrIndexes database.BlockAddrIndex) error
Constants ¶
This section is empty.
Variables ¶
var CurrentDBVersion int32 = 1
CurrentDBVersion is the database version.
Functions ¶
Types ¶
type LevelDb ¶
type LevelDb struct {
// contains filtered or unexported fields
}
LevelDb holds internal state for databse.
func (*LevelDb) DropAddrIndexForBlock ¶
func (db *LevelDb) DropAddrIndexForBlock(blkSha *chainhash.Hash, blkHeight int64, addrIndexes database.BlockAddrIndex) (rerr error)
DropAddrIndexForBlock drops the address index db for a given block/height.
func (*LevelDb) DropAfterBlockBySha ¶
DropAfterBlockBySha will remove any blocks from the database after the given block.
func (*LevelDb) ExistsSha ¶
ExistsSha looks up the given block hash returns true if it is present in the database.
func (*LevelDb) ExistsTxSha ¶
ExistsTxSha returns if the given tx sha exists in the database
func (*LevelDb) FetchAddrIndexTip ¶
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 ¶
FetchBlockBySha - return a dcrutil Block
func (*LevelDb) FetchBlockHeaderBySha ¶
FetchBlockHeaderBySha - return a ShaHash
func (*LevelDb) FetchBlockHeightBySha ¶
FetchBlockHeightBySha returns the block height for the given hash. This is part of the database.Db interface implementation.
func (*LevelDb) FetchBlockShaByHeight ¶
FetchBlockShaByHeight returns a block hash based on its height in the block chain.
func (*LevelDb) FetchHeightRange ¶
func (db *LevelDb) FetchHeightRange(startHeight, endHeight int64) (rshalist []chainhash.Hash, 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 ¶
FetchTxBySha returns some data for the given Tx Sha.
func (*LevelDb) FetchTxByShaList ¶
func (db *LevelDb) FetchTxByShaList(txShaList []*chainhash.Hash) []*database.TxListReply
FetchTxByShaList returns the most recent tx of the name fully spent or not
func (*LevelDb) FetchTxsForAddr ¶
func (db *LevelDb) FetchTxsForAddr(addr dcrutil.Address, skip int, limit int, reverse bool) ([]*database.TxListReply, int, 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 []*chainhash.Hash) []*database.TxListReply
FetchUnSpentTxByShaList given a array of ShaHash, look up the transactions and return them in a TxListReply array.
func (*LevelDb) 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.
func (*LevelDb) InsertTx ¶
func (db *LevelDb) InsertTx(txsha *chainhash.Hash, height int64, idx uint32, txoff int, txlen int, spentbuf []byte) (err error)
InsertTx inserts a tx hash and its associated data into the database.
func (*LevelDb) 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.
func (*LevelDb) PurgeAddrIndex ¶
PurgeAddrIndex deletes the entire addrindex stored within the DB. It also resets the cached in-memory metadata about the addr index.
func (*LevelDb) RollbackClose ¶
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 ¶
Sync verifies that the database is coherent on disk, and no outstanding transactions are in flight.
func (*LevelDb) UpdateAddrIndexForBlock ¶
func (db *LevelDb) UpdateAddrIndexForBlock(blkSha *chainhash.Hash, blkHeight int64, addrIndexes 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 committed 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.