new ChainDB(options)
The database backend for the Chain object.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
Properties:
Name | Type | Description |
---|---|---|
prune |
Boolean | |
loaded |
Boolean | |
keepBlocks |
Number |
- Source:
Fires:
- ChainDB#event:open
- ChainDB#event:error
- ChainDB#event:add block
- ChainDB#event:remove block
- ChainDB#event:add entry
- ChainDB#event:remove entry
Methods
addCache(entry)
Add an entry to the LRU cache.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
close(callback)
Close the chain, wait for the database to close.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
- Source:
connect(block, callback)
Connect the block to the chain.
Parameters:
Name | Type | Description |
---|---|---|
block |
ChainEntry | Hash | Height | entry, height, or hash. |
callback |
function | Returns [Error, ChainEntry]. |
- Source:
connectBlock(block, batch, callback)
Connect block inputs.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
batch |
Batch | |
callback |
function | Returns [Error, Block]. |
- Source:
disconnect(block, callback)
Disconnect block from the chain.
Parameters:
Name | Type | Description |
---|---|---|
block |
ChainEntry | Hash | Height | Entry, height, or hash. |
callback |
function | Returns [Error, ChainEntry]. |
- Source:
disconnectBlock(block, batch, callback)
Disconnect block inputs.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | Hash | Block or hash. |
batch |
Batch | |
callback |
function | Returns [Error, Block]. |
- Source:
dump(callback)
Dump the database to a map for debugging.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Returns [Error, Object]. |
- Source:
fillBlock(block, callback)
Fill a block with coins (unspent only).
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
callback |
function | Returns [Error, Block]. |
- Source:
fillCoins(tx, callback)
Fill a transaction with coins (only unspents).
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX | |
callback |
function | Returns [Error, TX]. |
- Source:
fillHistory(tx, callback)
Fill a transaction with coins (all historical coins).
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX | |
callback |
function | Returns [Error, TX]. |
- Source:
fillHistoryBlock(block, callback)
Fill a block with coins necessary to be resurrected during a reorg.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
callback |
function | Returns [Error, Block]. |
- Source:
get(hash, callback)
Retrieve a chain entry and add it to the LRU cache.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, ChainEntry]. |
- Source:
getBlock(hash, callback)
Retrieve a block from the database (not filled with coins).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, Block]. |
- Source:
getBoth(block, callback)
Get both hash and height depending on the value passed in.
Parameters:
Name | Type | Description |
---|---|---|
block |
Hash | Number | Can be a has or height. |
callback |
function | Returns [Error, Hash, Number]. |
- Source:
getCache(hash)
Get an entry directly from the LRU cache. This is
useful for optimization if we don't want to wait on a
nextTick during a get()
call.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | Number | Hash or height. |
- Source:
getChainHeight(callback)
Get the current chain height from the tip record.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Returns [Error, Number]. |
- Source:
getCoin(hash, index, callback)
Get a coin (unspents only).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
index |
Number | |
callback |
function | Returns [Error, Coin]. |
- Source:
getCoinsByAddress(addresses, callback)
Get all coins pertinent to an address.
Parameters:
Name | Type | Description |
---|---|---|
addresses |
Base58Address | Array.<Base58Address> | |
callback |
function | Returns [Error, Coin[]]. |
- Source:
getEntry(hash, callback)
Retrieve a chain entry but do not add it to the LRU cache.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, ChainEntry]. |
- Source:
getFullBlock(hash, callback)
Get a block and fill it with coins (historical).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, Block]. |
- Source:
getFullTX(hash, callback)
Get a transaction and fill it with coins (historical).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, TX]. |
- Source:
getHash(height, callback)
Get the hash of a block by height. Note that this will only return hashes in the main chain.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number | |
callback |
function | Returns [Error, Hash]. |
- Source:
getHeight(hash, callback)
Get the height of a block by hash.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, Number]. |
- Source:
getNextHash(hash, callback)
Get the next block hash (does not work by height).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, Hash]. |
- Source:
getTip(callback)
Retrieve the tip entry from the tip record.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Returns [Error, ChainEntry]. |
- Source:
getTX(hash, callback)
Retrieve a transaction (not filled with coins).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, TX]. |
- Source:
getTXByAddress(addresses, callback)
Get all transactions pertinent to an address.
Parameters:
Name | Type | Description |
---|---|---|
addresses |
Base58Address | Array.<Base58Address> | |
callback |
function | Returns [Error, TX[]]. |
- Source:
getUndoCoins(hash, callback)
Get coins necessary to be resurrected during a reorg.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, Object]. |
- Source:
has(height, callback)
Test whether the chain contains a block in the main chain or an alternate chain. Alternate chains will only be tested if the lookup is done by hash.
Parameters:
Name | Type | Description |
---|---|---|
height |
Hash | Number | Hash or height. |
callback |
function | Returns [Error, Boolean]. |
- Source:
hasCache(hash)
Test the cache for a present entry hash or height.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | Number | Hash or height. |
- Source:
hasTX(hash, callback)
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, Boolean]. |
- Source:
isMainChain(hash, callback)
Check to see if a block is on the main chain.
Parameters:
Name | Type | Description |
---|---|---|
hash |
ChainEntry | Hash | |
callback |
function | Returns [Error, Boolean]. |
- Source:
isSpentTX(hash, callback)
Check whether a transaction is fully spent.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, Boolean]. |
isUnspentTX(hash, callback)
Check whether a transaction is unspent (i.e. not yet fully spent).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
callback |
function | Returns [Error, Boolean]. |
open(callback)
Open the chain, wait for the database to load.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
- Source:
removeBlock(block, batch, callback)
Remove a block (not an entry) to the database. Disconnect inputs.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | Hash | Block or hash. |
batch |
Batch | |
callback |
function | Returns [Error, Block]. |
- Source:
reset(block, callback)
Reset the chain to a height or hash. Useful for replaying the blockchain download for SPV.
Parameters:
Name | Type | Description |
---|---|---|
block |
Hash | Number | hash/height |
callback |
function |
- Source:
save(entry, block, connect, callback)
Save an entry to the database and optionally connect it as the tip. Note that this method does not perform any verification which is instead performed in Chain#add.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block | |
connect |
Boolean | Whether to connect the block's inputs and add it as a tip. |
callback |
function |
- Source:
saveBlock(block, batch, connect, callback)
Save a block (not an entry) to the database and potentially connect the inputs.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
batch |
Batch | |
connect |
Boolean | Whether to connect the inputs. |
callback |
function | Returns [Error, Block]. |
- Source: