Class: ChainDB

blockchain~ChainDB()

ChainDB

Constructor

new ChainDB()

Create a chaindb.

Source:

Methods

(async, private) _disconnect(entry, block) → {Promise}

Disconnect block.

Parameters:
Name Type Description
entry ChainEntry
block Block
Source:
Returns:
  • Returns CoinView.
Type
Promise

(async, private) _reconnect(entry, block, view) → {Promise}

Reconnect block.

Parameters:
Name Type Description
entry ChainEntry
block Block
view CoinView
Source:
Returns:
Type
Promise

(async, private) _removeChain(hash) → {Promise}

Remove an alternate chain.

Parameters:
Name Type Description
hash Hash

Alternate chain tip.

Source:
Returns:
Type
Promise

(async, private) _save(entry, block, viewnullable) → {Promise}

Save an entry.

Parameters:
Name Type Attributes Description
entry ChainEntry
block Block
view CoinView <nullable>
Source:
Returns:
Type
Promise

batch() → {Batch}

Get current batch.

Source:
Returns:
Type
Batch

(async, private) checkDeployments() → {Promise}

Check for outdated deployments.

Source:
Returns:
Type
Promise

(async) close() → {Promise}

Close and wait for the database to close.

Source:
Returns:
Type
Promise

(async) commit() → {Promise}

Commit current batch.

Source:
Returns:
Type
Promise

(async) connectBlock(entry, block, view) → {Promise}

Connect block inputs.

Parameters:
Name Type Description
entry ChainEntry
block Block
view CoinView
Source:
Returns:
  • Returns Block.
Type
Promise

(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 String
Source:

(async) disconnect(entry, block) → {Promise}

Disconnect block from the chain.

Parameters:
Name Type Description
entry ChainEntry
block Block
Source:
Returns:
Type
Promise

(async) disconnectBlock(entry, block) → {Promise}

Disconnect block inputs.

Parameters:
Name Type Description
entry ChainEntry
block Block
Source:
Returns:
  • Returns CoinView.
Type
Promise

(async, private) disconnectNames(view, entry)

Disconnect names from tree.

Parameters:
Name Type Description
view CoinView
entry ChainEntry
Source:

drop() → {Batch}

Drop current batch.

Source:
Returns:
Type
Batch

(async) getAncestor(entry, height) → {Promise}

Get ancestor by height.

Parameters:
Name Type Description
entry ChainEntry
height Number
Source:
Returns:
  • Returns ChainEntry.
Type
Promise

(async) getBlock(hash) → {Promise}

Retrieve a block from the database (not filled with coins).

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Block.
Type
Promise

(async) getBlockView(hash) → {Promise}

Get a historical block coin viewpoint.

Parameters:
Name Type Description
hash Block
Source:
Returns:
  • Returns CoinView.
Type
Promise

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}

Get a coin (unspents only).

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
  • Returns Coin.
Type
Promise

(async) getCoinsByAddress(addrs) → {Promise}

Get all coins pertinent to an address.

Parameters:
Name Type Description
addrs Array.<Address>
Source:
Returns:
  • Returns Coin[].
Type
Promise

(async) getCoinView(tx) → {Promise}

Get coin viewpoint.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns CoinView.
Type
Promise

(async) getEntries() → {Promise}

Get all entries.

Source:
Returns:
  • Returns ChainEntry[].
Type
Promise

getEntry(block) → {Promise}

Retrieve a chain entry.

Parameters:
Name Type Description
block Number | Hash

Height or hash.

Source:
Returns:
  • Returns ChainEntry.
Type
Promise

(async) getEntryByHash(hash) → {Promise}

Retrieve a chain entry by hash.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns ChainEntry.
Type
Promise

(async) getEntryByHeight(height) → {Promise}

Retrieve a chain entry by height.

Parameters:
Name Type Description
height Number
Source:
Returns:
  • Returns ChainEntry.
Type
Promise

(async) getField() → {Buffer}

Get bitfield.

Source:
Returns:
Type
Buffer

(async) getFlags() → {Promise}

Retrieve the database flags.

Source:
Returns:
Type
Promise

(async) getHash(height) → {Promise}

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
Source:
Returns:
Type
Promise

(async) getHashes(startopt, endopt) → {Promise}

Get hash range.

Parameters:
Name Type Attributes Default Description
start Number <optional>
-1
end Number <optional>
-1
Source:
Returns:
Type
Promise

(async) getHashesByAddress(addrs) → {Promise}

Get all transaction hashes to an address.

Parameters:
Name Type Description
addrs Array.<Address>
Source:
Returns:
Type
Promise

(async) getHeight(hash) → {Promise}

Get the height of a block by hash.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Number.
Type
Promise

(async) getMeta(hash) → {Promise}

Get a transaction with metadata.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns TXMeta.
Type
Promise

(async) getMetaByAddress(addrs) → {Promise}

Get all transactions pertinent to an address.

Parameters:
Name Type Description
addrs Array.<Address>
Source:
Returns:
  • Returns TXMeta[].
Type
Promise

(async) getNameState(nameHash) → {NameState}

Get name state.

Parameters:
Name Type Description
nameHash Buffer
Source:
Returns:
Type
NameState

(async) getNameStateByName(name) → {NameState}

Get name state by name.

Parameters:
Name Type Description
name Buffer
Source:
Returns:
Type
NameState

(async) getNameStatus(nameHash) → {NameState}

Get name status.

Parameters:
Name Type Description
nameHash Buffer
Source:
Returns:
Type
NameState

(async) getNext(entry) → {Promise}

Get next entry.

Parameters:
Name Type Description
entry ChainEntry
Source:
Returns:
  • Returns ChainEntry.
Type
Promise

(async) getNextEntry(entry) → {Promise}

Get next entry.

Parameters:
Name Type Description
entry ChainEntry
Source:
Returns:
  • Returns ChainEntry.
Type
Promise

(async) getNextHash(hash) → {Promise}

Get the next block hash (does not work by height).

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Promise

getPrevCache(entry) → {ChainEntry|null}

Get previous cached entry.

Parameters:
Name Type Description
entry ChainEntry
Source:
Returns:
Type
ChainEntry | null

getPrevious(entry) → {Promise}

Get previous entry.

Parameters:
Name Type Description
entry ChainEntry
Source:
Returns:
  • Returns ChainEntry.
Type
Promise

(async) getRawBlock(hash) → {Promise}

Retrieve a block from the database (not filled with coins).

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Block.
Type
Promise

(async) getSpentView(tx) → {Promise}

Get coin viewpoint (historical).

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns CoinView.
Type
Promise

(async) getState() → {Promise}

Retrieve the tip entry from the tip record.

Source:
Returns:
Type
Promise

(async) getStateCache() → {Promise}

Get state caches.

Source:
Returns:
Type
Promise

getTip() → {Promise}

Retrieve the tip entry from the tip record.

Source:
Returns:
  • Returns ChainEntry.
Type
Promise

(async) getTips() → {Promise}

Get all tip hashes.

Source:
Returns:
Type
Promise

(async) getTX(hash) → {Promise}

Retrieve a transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns TX.
Type
Promise

(async) getTXByAddress(addrs) → {Promise}

Get all transactions pertinent to an address.

Parameters:
Name Type Description
addrs Array.<Address>
Source:
Returns:
  • Returns TX[].
Type
Promise

(async) getUndoCoins(hash) → {Promise}

Get coins necessary to be resurrected during a reorg.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Coin[].
Type
Promise

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}

Check whether coins are still unspent. Necessary for bip30.

Parameters:
Name Type Description
tx TX
Source:
See:
Returns:
  • Returns Boolean.
Type
Promise

(async) hasEntry(hash) → {Promise}

Test whether the chain contains a block.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) hasTX(hash) → {Promise}

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Boolean.
Type
Promise

(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, private) invalidateCache() → {Promise}

Invalidate state cache.

Source:
Returns:
Type
Promise

(async) isMainChain(entry) → {Promise}

Test whether the entry is in the main chain.

Parameters:
Name Type Description
entry ChainEntry
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) isMainHash(hash) → {Promise}

Check to see if a block is on the main chain.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
  • Returns Boolean.
Type
Promise

(async) lookup(root, key) → {Buffer}

Lookup a name tree value.

Parameters:
Name Type Description
root Hash
key Hash
Source:
Returns:
Type
Buffer

(async) open() → {Promise}

Open and wait for the database to load.

Source:
Returns:
Type
Promise

(async) prove(root, key) → {Array.<Buffer>}

Create a name tree proof.

Parameters:
Name Type Description
root Hash
key Hash
Source:
Returns:

nodes

Type
Array.<Buffer>

(async) prune() → {Promise}

Retroactively prune the database.

Source:
Returns:
Type
Promise

(async, private) pruneBlock(entry) → {Promise}

Prune a block from the chain and add current block to the prune queue.

Parameters:
Name Type Description
entry ChainEntry
Source:
Returns:
Type
Promise

put(key, value)

Put key and value to current batch.

Parameters:
Name Type Description
key String
value Buffer
Source:

(async, private) readCoin(prevout) → {Promise}

Get a coin (unspents only).

Parameters:
Name Type Description
prevout Outpoint
Source:
Returns:
  • Returns CoinEntry.
Type
Promise

(async) reconnect(entry, block, view) → {Promise}

Reconnect the block to the chain.

Parameters:
Name Type Description
entry ChainEntry
block Block
view CoinView
Source:
Returns:
Type
Promise

(async) removeBlock(entry) → {Promise}

Remove a block (not an entry) to the database. Disconnect inputs.

Parameters:
Name Type Description
entry ChainEntry
Source:
Returns:
  • Returns Block.
Type
Promise

(async) removeChains() → {Promise}

Remove all alternate chains.

Source:
Returns:
Type
Promise

(async) reset(block) → {Promise}

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

(async) save(entry, block, viewnullable) → {Promise}

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 <nullable>

Will not connect if null.

Source:
Returns:
Type
Promise

(async) saveBlock(entry, block, viewnullable) → {Promise}

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 <nullable>
Source:
Returns:
  • Returns Block.
Type
Promise

saveDeployments() → {Promise}

Save deployment table.

Source:
Returns:
Type
Promise

saveFlags() → {Promise}

Save database options.

Source:
Returns:
Type
Promise

(async) saveGenesis() → {Promise}

Write genesis block to database.

Source:
Returns:
Type
Promise

(async, private) saveNames(view, entry, revert)

Commit names to tree.

Parameters:
Name Type Description
view CoinView
entry ChainEntry
revert Boolean
Source:

(private) saveUpdates()

Save state cache updates.

Source:

(private) saveView(view)

Commit coin view to database.

Parameters:
Name Type Description
view CoinView
Source:

(async) scan(start, filter, iter) → {Promise}

Scan the blockchain for transactions containing specified address hashes.

Parameters:
Name Type Description
start Hash

Block hash to start at.

filter Bloom

Bloom filter containing tx and address hashes.

iter function

Iterator.

Source:
Returns:
Type
Promise

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}

Potentially invalidate state cache.

Source:
Returns:
Type
Promise

(async) verifyFlags(state) → {Promise}

Verify current options against db options.

Parameters:
Name Type Description
state ChainState
Source:
Returns:
Type
Promise

writeDeployments() → {Promise}

Save deployment table.

Source:
Returns:
Type
Promise