Constructor
new ChainDB(options)
Create a chaindb.
Parameters:
Name | Type | Description |
---|---|---|
options |
ChainOptions |
- Source:
Members
cacheHash :LRU.<Buffer, ChainEntry>
Type:
- LRU.<Buffer, ChainEntry>
- Source:
cacheHeight :LRU.<Number, ChainEntry>
Type:
- LRU.<Number, ChainEntry>
- Source:
Methods
(async, private) _disconnect(entry, block) → {Promise.<CoinView>}
Disconnect block.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async) _initialize() → {Promise.<void>}
Initialize fresh database.
- Source:
Returns:
- Type
- Promise.<void>
(async, private) _reconnect(entry, block, view) → {Promise.<void>}
Reconnect block.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block | |
view |
CoinView |
- Source:
Returns:
- Type
- Promise.<void>
(async, private) _removeChain(hash) → {Promise.<void>}
Remove an alternate chain.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | Alternate chain tip. |
- Source:
Returns:
- Type
- Promise.<void>
(async, private) _save(entry, block, viewopt, nullable) → {Promise.<void>}
Save an entry.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
entry |
ChainEntry | ||
block |
Block | ||
view |
CoinView |
<optional> <nullable> |
- Source:
Returns:
- Type
- Promise.<void>
(async, private) _saveNames(view, entry, revert) → {Promise.<void>}
Commit names to tree, assuming batch is started.
Parameters:
Name | Type | Description |
---|---|---|
view |
CoinView | |
entry |
ChainEntry | |
revert |
Boolean |
- Source:
Returns:
- Type
- Promise.<void>
batch() → {Batch}
Get current batch.
- Source:
Returns:
- Type
- Batch
(async, private) checkDeployments() → {Promise.<Array.<Number>>}
Check for outdated deployments.
- Source:
Returns:
- Type
- Promise.<Array.<Number>>
(async) close() → {Promise.<void>}
Close and wait for the database to close.
- Source:
Returns:
- Type
- Promise.<void>
(async) commit() → {Promise.<void>}
Commit current batch.
- Source:
Returns:
- Type
- Promise.<void>
(async) compactTree(entry) → {Promise.<void>}
Compact the Urkel Tree. Removes all historical state and all data not linked directly to the provided root node hash.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<void>
(async) connectBlock(entry, block, view) → {Promise.<void>}
Connect block inputs.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block | |
view |
CoinView |
- Source:
Returns:
- Type
- Promise.<void>
(async, private) connectNames(view, entry)
Connect names to tree.
Parameters:
Name | Type | Description |
---|---|---|
view |
CoinView | |
entry |
ChainEntry |
- Source:
del(key)
Delete key from current batch.
Parameters:
Name | Type | Description |
---|---|---|
key |
Buffer |
- Source:
(async) disconnect(entry, block) → {Promise.<CoinView>}
Disconnect block from the chain.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async) disconnectBlock(entry, block) → {Promise.<CoinView>}
Disconnect block inputs.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async, private) disconnectNames(view, entry) → {Promise.<void>}
Disconnect names from tree.
Parameters:
Name | Type | Description |
---|---|---|
view |
CoinView | |
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<void>
drop()
Drop current batch.
- Source:
(async) getAncestor(entry, height) → {Promise.<?ChainEntry>}
Get ancestor by height
.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
height |
Number |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getBlock(hash) → {Promise.<?Block>}
Retrieve a block from the database (not filled with coins).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<?Block>
(async) getBlockView(block) → {Promise.<CoinView>}
Get a historical block coin viewpoint.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block |
- Source:
Returns:
- Type
- Promise.<CoinView>
getCache(block)
Get an entry directly from the LRU cache.
Parameters:
Name | Type | Description |
---|---|---|
block |
Hash | Number | Hash or height. |
- Source:
(async) getCoin(hash, index) → {Promise.<?Coin>}
Get a coin (unspents only).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
index |
Number |
- Source:
Returns:
- Type
- Promise.<?Coin>
(async) getCoinsByAddress(addrs) → {Promise.<Array.<Coin>>}
Get all coins pertinent to an address.
Parameters:
Name | Type | Description |
---|---|---|
addrs |
Array.<Address> |
- Source:
Returns:
- Type
- Promise.<Array.<Coin>>
(async) getCoinView(tx) → {Promise.<CoinView>}
Get coin viewpoint.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async) getEntries(startopt, endopt) → {Promise.<Array.<ChainEntry>>}
Get entries range.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Number |
<optional> |
-1 | |
end |
Number |
<optional> |
-1 |
- Source:
Returns:
- Type
- Promise.<Array.<ChainEntry>>
getEntry(block) → {Promise.<?ChainEntry>}
Retrieve a chain entry.
Parameters:
Name | Type | Description |
---|---|---|
block |
Number | Hash | Height or hash. |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getEntryByHash(hash) → {Promise.<?ChainEntry>}
Retrieve a chain entry by hash.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getEntryByHeight(height) → {Promise.<?ChainEntry>}
Retrieve a chain entry by height.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getField() → {Promise.<BitField>}
Get bitfield.
- Source:
Returns:
- Type
- Promise.<BitField>
(async) getFlags() → {Promise.<?ChainFlags>}
Retrieve the database flags.
- Source:
Returns:
- Type
- Promise.<?ChainFlags>
(async) getHash(height) → {Promise.<Hash>}
Get the hash of a block by height. Note that this will only return hashes in the main chain.
Parameters:
Name | Type | Description |
---|---|---|
height |
Hash | Number |
- Source:
Returns:
- Type
- Promise.<Hash>
(async) getHashes(startopt, endopt) → {Promise.<Array.<Hash>>}
Get hash range.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Number |
<optional> |
-1 | |
end |
Number |
<optional> |
-1 |
- Source:
Returns:
- Type
- Promise.<Array.<Hash>>
(async) getHashesByAddress(addrs) → {Promise.<Array.<Hash>>}
Get all transaction hashes to an address.
Parameters:
Name | Type | Description |
---|---|---|
addrs |
Array.<Address> |
- Source:
Returns:
- Type
- Promise.<Array.<Hash>>
(async) getHeight(hash) → {Promise.<Number>}
Get the height of a block by hash.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Number>
(async) getMeta(hash) → {Promise.<?TXMeta>}
Get a transaction with metadata.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<?TXMeta>
(async) getMetaByAddress(addrs) → {Promise.<Array.<TXMeta>>}
Get all transactions pertinent to an address.
Parameters:
Name | Type | Description |
---|---|---|
addrs |
Array.<Address> |
- Source:
Returns:
- Type
- Promise.<Array.<TXMeta>>
(async) getNameState(nameHash) → {Promise.<NameState>}
Get name state.
Parameters:
Name | Type | Description |
---|---|---|
nameHash |
Buffer |
- Source:
Returns:
- Type
- Promise.<NameState>
(async) getNameStateByName(name) → {Promise.<NameState>}
Get name state by name.
Parameters:
Name | Type | Description |
---|---|---|
name |
Buffer |
- Source:
Returns:
- Type
- Promise.<NameState>
(async) getNameStatus(nameHash, height) → {Promise.<NameState>}
Get name status.
Parameters:
Name | Type | Description |
---|---|---|
nameHash |
Buffer | |
height |
Number | used for expiration checks. |
- Source:
Returns:
- Type
- Promise.<NameState>
(async) getNext(entry) → {Promise.<?ChainEntry>}
Get next entry.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getNextEntry(entry) → {Promise.<?ChainEntry>}
Get next entry.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getNextHash(hash) → {Promise.<Hash>}
Get the next block hash (does not work by height).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Hash>
getPrevCache(entry) → (nullable) {ChainEntry}
Get previous cached entry.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- ChainEntry
getPrevious(entry) → {Promise.<?ChainEntry>}
Get previous entry.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getRawBlock(hashHeight) → {Promise.<?Buffer>}
Retrieve a block from the database (not filled with coins).
Parameters:
Name | Type | Description |
---|---|---|
hashHeight |
Hash | Number |
- Source:
Returns:
- Type
- Promise.<?Buffer>
(async) getSpentView(tx) → {Promise.<CoinView>}
Get coin viewpoint (historical).
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async) getState() → {Promise.<?ChainState>}
Retrieve the tip entry from the tip record.
- Source:
Returns:
- Type
- Promise.<?ChainState>
(async) getStateCache() → {Promise.<StateCache>}
Get state caches.
- Source:
Returns:
- Type
- Promise.<StateCache>
getTip() → {Promise.<?ChainEntry>}
Retrieve the tip entry from the tip record.
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getTips() → {Promise.<Array.<Hash>>}
Get all tip hashes.
- Source:
Returns:
- Type
- Promise.<Array.<Hash>>
(async) getTreeState() → {Promise.<?TreeState>}
Retrieve tree state from the tree record.
- Source:
Returns:
- Type
- Promise.<?TreeState>
(async) getTX(hash) → {Promise.<?TX>}
Retrieve a transaction.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<?TX>
(async) getTXByAddress(addrs) → {Promise.<Array.<TX>>}
Get all transactions pertinent to an address.
Parameters:
Name | Type | Description |
---|---|---|
addrs |
Array.<Address> |
- Source:
Returns:
- Type
- Promise.<Array.<TX>>
(async) getUndoCoins(hash) → {Promise.<UndoCoins>}
Get coins necessary to be resurrected during a reorg.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<UndoCoins>
hasCache(block)
Test the cache for a present entry hash or height.
Parameters:
Name | Type | Description |
---|---|---|
block |
Hash | Number | Hash or height. |
- Source:
(async) hasCoins(tx) → {Promise.<Boolean>}
Check whether coins are still unspent. Necessary for bip30.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
Returns:
- Type
- Promise.<Boolean>
(async) hasEntry(hash) → {Promise.<Boolean>}
Test whether the chain contains a block.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(async) hasTX(hash) → {Promise.<Boolean>}
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(private) indexTX(tx, view, entry, index)
Index a transaction by txid and address.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX | |
view |
CoinView | |
entry |
ChainEntry | |
index |
Number |
- Source:
(async) initialize() → {Promise}
Initialize fresh database.
- Source:
Returns:
- Type
- Promise
(async, private) invalidateCache(bit, b) → {Promise.<void>}
Invalidate state cache.
Parameters:
Name | Type | Description |
---|---|---|
bit |
Number | |
b |
Batch |
- Source:
Returns:
- Type
- Promise.<void>
(async) isMainChain(entry) → {Promise.<Boolean>}
Test whether the entry is in the main chain.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<Boolean>
(async) isMainHash(hash) → {Promise.<Boolean>}
Check to see if a block is on the main chain.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(async) lookup(root, key) → {Promise.<Buffer>}
Lookup a name tree value.
Parameters:
Name | Type | Description |
---|---|---|
root |
Hash | |
key |
Hash |
- Source:
Returns:
- Type
- Promise.<Buffer>
(async) open() → {Promise.<void>}
Open and wait for the database to load.
- Source:
Returns:
- Type
- Promise.<void>
(async) prove(root, key) → {Promise.<Proof>}
Create a name tree proof.
Parameters:
Name | Type | Description |
---|---|---|
root |
Hash | |
key |
Hash |
- Source:
Returns:
nodes
- Type
- Promise.<Proof>
(async) prune() → {Promise.<Boolean>}
Retroactively prune the database.
- Source:
Returns:
- Type
- Promise.<Boolean>
(async, private) pruneBlock(entry) → {Promise.<void>}
Prune a block from the chain and add current block to the prune queue.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<void>
put(key, value)
Put key and value to current batch.
Parameters:
Name | Type | Description |
---|---|---|
key |
Buffer | |
value |
Buffer |
- Source:
(async) readCoin(prevout) → {Promise.<?CoinEntry>}
Get a coin (unspents only).
Parameters:
Name | Type | Description |
---|---|---|
prevout |
Outpoint |
- Source:
Returns:
- Type
- Promise.<?CoinEntry>
(async) reconnect(entry, block, view) → {Promise.<void>}
Reconnect the block to the chain.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block | |
view |
CoinView |
- Source:
Returns:
- Type
- Promise.<void>
(async) removeBlock(entry) → {Promise.<CoinView>}
Remove a block (not an entry) to the database. Disconnect inputs.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async) removeChains() → {Promise.<void>}
Remove all alternate chains.
- Source:
Returns:
- Type
- Promise.<void>
(async) reset(block) → {Promise.<?ChainEntry>}
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 |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) save(entry, block, viewopt, nullable) → {Promise.<void>}
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 | Attributes | Description |
---|---|---|---|
entry |
ChainEntry | ||
block |
Block | ||
view |
CoinView |
<optional> <nullable> |
Will not connect if null. |
- Source:
Returns:
- Type
- Promise.<void>
(async) saveBlock(entry, block, viewopt, nullable) → {Promise.<void>}
Save a block (not an entry) to the database and potentially connect the inputs.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
entry |
ChainEntry | ||
block |
Block | ||
view |
CoinView |
<optional> <nullable> |
- Source:
Returns:
- Type
- Promise.<void>
saveDeployments() → {Promise.<void>}
Save deployment table.
- Source:
Returns:
- Type
- Promise.<void>
saveFlags() → {Promise.<void>}
Save database options.
- Source:
Returns:
- Type
- Promise.<void>
(async) saveNames(view, entry, revert)
Commit names to tree.
Parameters:
Name | Type | Description |
---|---|---|
view |
CoinView | |
entry |
ChainEntry | |
revert |
Boolean |
- Source:
(private) saveUpdates() → {void}
Save state cache updates.
- Source:
Returns:
- Type
- void
(private) saveView(view)
Commit coin view to database.
Parameters:
Name | Type | Description |
---|---|---|
view |
CoinView |
- Source:
(async) scan(start, filter, iter) → {Promise.<void>}
Scan the blockchain for transactions containing specified address hashes.
Parameters:
Name | Type | Description |
---|---|---|
start |
Hash | Number | Block hash or height to start at. |
filter |
BloomFilter | Bloomfilter containing tx and address hashes. |
iter |
function | Iterator. |
- Source:
Returns:
- Type
- Promise.<void>
(async) scanBlock(blockID, filteropt) → {Promise.<ScanBlockResult>}
Interactive scans block checks.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
blockID |
Hash | Number | Block hash or height to start at. |
|
filter |
BloomFilter |
<optional> |
Starting bloom filter containing tx, address and name hashes. |
- Source:
Returns:
- Type
- Promise.<ScanBlockResult>
start() → {Batch}
Start a batch.
- Source:
Returns:
- Type
- Batch
treeRoot() → {Hash}
Get the current name tree root.
- Source:
Returns:
- Type
- Hash
(private) unindexTX(tx, view)
Remove transaction from index.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX | |
view |
CoinView |
- Source:
(async) verifyDeployments() → {Promise.<Boolean>}
Potentially invalidate state cache.
- Source:
Returns:
- Type
- Promise.<Boolean>
(async) verifyFlags() → {Promise.<void>}
Verify current options against db options.
- Source:
Returns:
- Type
- Promise.<void>
(async) verifyVersion(version) → {Promise.<void>}
Verify version
Parameters:
Name | Type | Description |
---|---|---|
version |
Number |
- Source:
Returns:
- Type
- Promise.<void>
writeDeployments(b)
Save deployment table.
Parameters:
Name | Type | Description |
---|---|---|
b |
Batch |
- Source:
writeFlags(b)
Write database options.
Parameters:
Name | Type | Description |
---|---|---|
b |
Batch |
- Source:
(async) writeGenesis() → {Promise.<void>}
Write genesis block to database.
- Source:
Returns:
- Type
- Promise.<void>
writeVersion(b, version)
Write chaindb version.
Parameters:
Name | Type | Description |
---|---|---|
b |
Batch | |
version |
Number |
- Source: