Constructor
new Chain(options)
Create a blockchain.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
db |
ChainDB | ||
tip |
ChainEntry |
<nullable> |
|
height |
Number | ||
state |
DeploymentState |
- Source:
Methods
(async, private) _add(block, flagsnullable, idnullable) → {Promise.<?ChainEntry>}
Add a block to the chain without a lock.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
block |
Block | ||
flags |
Number |
<nullable> |
|
id |
Number |
<nullable> |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async, private) _getLocator(startnullable) → {Promise.<Array.<Hash>>}
Calculate chain locator without a lock.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
start |
Hash |
<nullable> |
- Source:
Returns:
- Type
- Promise.<Array.<Hash>>
(async) _invalidate(hash) → {Promise}
Invalidate block (no lock).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise
(async, private) _replay(block, silent) → {Promise}
Reset the chain without a lock.
Parameters:
Name | Type | Description |
---|---|---|
block |
Hash | Number | hash/height |
silent |
Boolean |
- Source:
Returns:
- Type
- Promise
(async, private) _reset(block, silent) → {Promise}
Reset the chain to the desired block without a lock.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
block |
Hash | Number | ||
silent |
Boolean | false | don't emit reset. |
- Source:
Returns:
- Type
- Promise
(async) _scanInteractive(start, filter, iter, lockPerScanopt) → {Promise.<void>}
Interactive scan the blockchain for transactions containing specified address hashes. Allows repeat and abort.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Hash | Number | Block hash or height to start at. |
||
filter |
BloomFilter | Starting bloom filter containing tx, address and name hashes. |
||
iter |
ScanInteractiveIterCB | Iterator. |
||
lockPerScan |
Boolean |
<optional> |
true | if we should lock per block scan. |
- Source:
Returns:
- Type
- Promise.<void>
(async, private) _verifyBlock(block) → {Promise.<Array>}
Perform all necessary contextual verification on a block, without POW check (no lock).
Parameters:
Name | Type | Description |
---|---|---|
block |
Block |
- Source:
Returns:
- [CoinView, DeploymentState]
- Type
- Promise.<Array>
(async) add(block, flagsnullable, idnullable) → {Promise.<?ChainEntry>}
Add a block to the chain, perform all necessary verification.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
block |
Block | ||
flags |
Number |
<nullable> |
|
id |
Number |
<nullable> |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(private) addOrphan(orphan) → {Orphan}
Add an orphan.
Parameters:
Name | Type | Description |
---|---|---|
orphan |
Orphan |
- Source:
Returns:
- Type
- Orphan
(async) close() → {Promise.<void>}
Close the chain, wait for the database to close.
- Source:
Returns:
- Type
- Promise.<void>
(async) compactTree() → {Promise}
Compact the Urkel Tree. Removes all historical state and all data not linked directly to the provided root node hash.
- Source:
Returns:
- Type
- Promise
(async) computeBlockVersion(prev) → {Promise.<Number>}
Compute the version for a new block (BIP9: versionbits).
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | Previous chain entry (usually the tip). |
- Source:
- See:
Returns:
- Type
- Promise.<Number>
(async, private) connect(prev, block, flags) → {Promise.<?ChainEntry>}
Connect block to chain.
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | |
block |
Block | |
flags |
Number |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) disconnect(entry) → {Promise}
Disconnect an entry from the chain (updates the tip).
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise
(async, private) findFork(fork, longer) → {Promise.<ChainEntry>}
Find the block at which a fork ocurred.
Parameters:
Name | Type | Description |
---|---|---|
fork |
ChainEntry | The current chain. |
longer |
ChainEntry | The competing chain. |
- Source:
Returns:
- Type
- Promise.<ChainEntry>
(async) findLocator(locator) → {Promise.<Hash>}
Find a locator. Analagous to bitcoind's FindForkInGlobalIndex()
.
Parameters:
Name | Type | Description |
---|---|---|
locator |
Array.<Hash> | Hashes. |
- Source:
Returns:
(the hash of the latest known block).
- Type
- Promise.<Hash>
getAncestor(entry, height) → {Promise.<?ChainEntry>}
Get ancestor by height
.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
height |
Number |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
(async) getBIP9Stats(prev, deployment) → {Promise.<Object>}
Get signalling statistics for BIP9/versionbits soft fork
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | Previous chain entry. |
deployment |
Object | Deployment. |
- Source:
Returns:
- Type
- Promise.<Object>
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>
getBlockView(block) → {Promise.<CoinView>}
Get a historical block coin viewpoint.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block |
- Source:
Returns:
- Type
- Promise.<CoinView>
getCoin(hash, index) → {Promise.<?Coin>}
Get a coin (unspents only).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
index |
Number |
- Source:
Returns:
- Type
- Promise.<?Coin>
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>>
getCoinView(tx) → {Promise.<CoinView>}
Get coin viewpoint.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async) getCompactionHeights() → {Promise.<Object>}
Get compaction heights.
- Source:
Returns:
- Type
- Promise.<Object>
(async) getCurrentTarget() → {Promise}
Calculate the next target based on the chain tip.
- Source:
Returns:
- returns Number (target is in compact/mantissa form).
- Type
- Promise
(async) getDeployments(time, prev) → {Promise.<DeploymentState>}
Check all deployments on a chain.
Parameters:
Name | Type | Description |
---|---|---|
time |
Number | |
prev |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<DeploymentState>
(async, private) getDeploymentState() → {Promise.<DeploymentState>}
Get the current deployment state of the chain. Called on load.
- Source:
Returns:
- Type
- Promise.<DeploymentState>
getEntries(startopt, endopt) → {Promise.<Array.<ChainEntry>>}
Get range of entries.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Number |
<optional> |
-1 | |
end |
Number |
<optional> |
-1 |
- Source:
Returns:
- Type
- Promise.<Array.<ChainEntry>>
getEntry(hash) → {Promise.<?ChainEntry>}
Find the corresponding block entry by hash or height.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | Number |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
getEntryByHash(hash) → {Promise.<?ChainEntry>}
Retrieve a chain entry by hash.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
getEntryByHeight(height) → {Promise.<?ChainEntry>}
Retrieve a chain entry by height.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
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 |
Number |
- Source:
Returns:
- Type
- Promise.<Hash>
getHashes(startopt, endopt) → {Promise.<Array.<Hash>>}
Get range of hashes.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Number |
<optional> |
-1 | |
end |
Number |
<optional> |
-1 |
- Source:
Returns:
- Type
- Promise.<Array.<Hash>>
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>>
getHeight(hash) → {Promise.<Number>}
Get the height of a block by hash.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Number>
(async) getLocator(startnullable) → {Promise.<Array.<Hash>>}
Calculate chain locator (an array of hashes).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
start |
Hash |
<nullable> |
Height or hash to treat as the tip. The current tip will be used if not present. Note that this can be a non-existent hash, which is useful for headers-first locators. |
- Source:
Returns:
- Type
- Promise.<Array.<Hash>>
(async) getLocks(prev, tx, view, flags) → {Promise}
Get the necessary minimum time and height sequence locks for a transaction.
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | |
tx |
TX | |
view |
CoinView | |
flags |
LockFlags |
- Source:
Returns:
- Type
- Promise
(async) getMainHeight(hash) → {Promise.<Number>}
Get main chain height for hash.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Number>
(async) getMedianTime(prev) → {Promise.<Number>}
Calculate median time past.
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<Number>
getMeta(hash) → {Promise.<TXMeta>}
Get a transaction with metadata.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<TXMeta>
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>>
getNext(entry) → {Promise.<?ChainEntry>}
Get next entry.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
getNextEntry(entry) → {Promise.<?ChainEntry>}
Get next entry.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<?ChainEntry>
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>
(async) getNextState() → {Promise.<DeploymentState>}
Get the next deployment state of the chain.
- Source:
Returns:
- Type
- Promise.<DeploymentState>
getOrphan(hash) → (nullable) {Block}
Get an orphan block.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Block
getOrphanRoot(hash) → {Hash}
Calculate the orphan root of the hash (if it is an orphan).
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- 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>
getProgress() → {Number}
Get the fill percentage.
- Source:
Returns:
percent - Ranges from 0.0 to 1.0.
- Type
- Number
getProofTime(to, from) → {Number}
Calculate the time difference (in seconds) between two blocks by examining chainworks.
Parameters:
Name | Type | Description |
---|---|---|
to |
ChainEntry | |
from |
ChainEntry |
- Source:
Returns:
- Type
- Number
getRawBlock(hashHeight) → {Promise.<(Buffer|null)>}
Retrieve a block from the database (not filled with coins).
Parameters:
Name | Type | Description |
---|---|---|
hashHeight |
Hash | Number |
- Source:
Returns:
- Type
- Promise.<(Buffer|null)>
(async) getSafeRoot() → {Promise.<Hash>}
Get safe tree root.
- Source:
Returns:
- Type
- Promise.<Hash>
(async) getSpentView(tx) → {Promise.<CoinView>}
Get coin viewpoint (spent).
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async) getState(prev, deployment) → {Promise.<Number>}
Get chain entry state for a deployment (BIP9: versionbits).
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | Previous chain entry. |
deployment |
Object | Deployment. |
- Source:
- See:
Returns:
- Type
- Promise.<Number>
Example
await chain.getState(tip, deployments.segwit);
(async) getSuitableBlock(prev) → {Promise.<ChainEntry>}
Get median block by timestamp.
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<ChainEntry>
(async) getTarget(time, prev) → {Promise.<Number>}
Calculate the next target.
Parameters:
Name | Type | Description |
---|---|---|
time |
Number | Next block timestamp. |
prev |
ChainEntry | Previous entry. |
- Source:
Returns:
- returns Number (target is in compact/mantissa form).
- Type
- Promise.<Number>
getTips() → {Promise.<Array.<Hash>>}
Get all tip hashes.
- Source:
Returns:
- Type
- Promise.<Array.<Hash>>
getTX(hash) → {Promise.<TX>}
Retrieve a transaction.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<TX>
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, private) handleOrphans(entry) → {Promise}
Handle orphans.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise
(async) has(hash) → {Promise}
Test the chain to see if it contains a block, or has recently seen a block.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Returns Boolean.
- Type
- Promise
hasChainwork() → {Boolean}
Test the chain to see if it has the minimum required chainwork for the network.
- Source:
Returns:
- Type
- Boolean
hasCoins(tx) → {Promise.<Boolean>}
Check whether coins are still unspent.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
- Source:
Returns:
- Type
- Promise.<Boolean>
hasEntry(hash) → {Promise.<Boolean>}
Test the chain to see if it contains a block.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(private) hasInvalid(block) → {Boolean}
Test whether an invalid block hash has been seen.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block |
- Source:
Returns:
- Type
- Boolean
(private) hasNextOrphan(hash) → {Boolean}
Test whether a hash would resolve the next orphan.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | Previous block hash. |
- Source:
Returns:
- Type
- Boolean
hasOrphan(hash) → {Boolean}
Test the chain to see if it contains an orphan.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Boolean
hasPending(hash) → {Boolean}
Test the chain to see if it contains a pending block in its queue.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Returns Boolean.
- Type
- Boolean
hasTX(hash) → {Promise.<Boolean>}
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(async) invalidate(hash) → {Promise}
Invalidate block.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise
(async) isActive(prev, deployment) → {Promise.<Boolean>}
Check whether a versionbits deployment is active (BIP9: versionbits).
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | Previous chain entry. |
deployment |
Object | Deployment. |
- Source:
- See:
Returns:
- Type
- Promise.<Boolean>
Example
await chain.isActive(tip, deployments.segwit);
isFull() → {Boolean}
Test the chain to see if it is synced.
- Source:
Returns:
- Type
- Boolean
isHistorical(prev) → {Boolean}
Test whether the entry is potentially an ancestor of a checkpoint.
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry |
- Source:
Returns:
- Type
- Boolean
isHistoricalHeight(height) → {Boolean}
Test whether the height is potentially an ancestor of a checkpoint.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number |
- Source:
Returns:
- Type
- Boolean
isMainChain(entry) → {Promise.<Boolean>}
Test whether the entry is in the main chain.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<Boolean>
isMainHash(hash) → {Promise.<Boolean>}
Test whether the hash is in the main chain.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(private) isSlow() → {Boolean}
Test whether the chain has reached its slow height.
- Source:
Returns:
- Type
- Boolean
limitOrphans()
Prune orphans, only keep the orphan with the highest coinbase height (likely to be the peer's tip).
- Source:
(private) logStatus(start, block, entry)
Calculate the time difference from start time and log block.
Parameters:
Name | Type | Description |
---|---|---|
start |
Array | |
block |
Block | |
entry |
ChainEntry |
- Source:
(private) maybeSync()
Potentially emit a full
event.
- Source:
(async) open() → {Promise.<void>}
Open the chain, wait for the database to load.
- Source:
Returns:
- Type
- Promise.<void>
(async) prune() → {Promise.<Boolean>}
Retroactively prune the database.
- Source:
Returns:
- Type
- Promise.<Boolean>
purgeOrphans()
Purge any waiting orphans.
- Source:
readCoin(prevout) → {Promise.<?CoinEntry>}
Get a coin (unspents only).
Parameters:
Name | Type | Description |
---|---|---|
prevout |
Outpoint |
- Source:
Returns:
- Type
- Promise.<?CoinEntry>
(async, private) readDeploymentState(tip) → {Promise.<DeploymentState>}
Get deployment state.
Parameters:
Name | Type | Description |
---|---|---|
tip |
ChainEntry |
- Source:
Returns:
- Type
- Promise.<DeploymentState>
(async) reconnect(entry) → {Promise}
Reconnect an entry to the chain (updates the tip). This will do contextual-verification on the block (necessary because we cannot validate the inputs in alternate chains when they come in).
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry |
- Source:
Returns:
- Type
- Promise
(async) reconstructTree() → {Promise}
Reconstruct the Urkel Tree.
- Source:
Returns:
- Type
- Promise
(private) removeInvalid(hash)
Forget an invalid block hash.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
(private) removeOrphan(orphan) → {Orphan}
Remove an orphan.
Parameters:
Name | Type | Description |
---|---|---|
orphan |
Orphan |
- Source:
Returns:
- Type
- Orphan
(async, private) reorganize(competitor) → {Promise.<ChainEntry>}
Reorganize the blockchain (connect and disconnect inputs). Called when a competing chain with a higher chainwork is received.
Parameters:
Name | Type | Description |
---|---|---|
competitor |
ChainEntry | The competing chain's tip. |
- Source:
Returns:
- Fork block.
- Type
- Promise.<ChainEntry>
(async, private) reorganizeSPV(competitor) → {Promise}
Reorganize the blockchain for SPV. This will reset the chain to the fork block.
Parameters:
Name | Type | Description |
---|---|---|
competitor |
ChainEntry | The competing chain's tip. |
- Source:
Returns:
- Type
- Promise
(async) replay(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) reset(block) → {Promise}
Reset the chain to the desired block. This is useful for replaying the blockchain download for SPV.
Parameters:
Name | Type | Description |
---|---|---|
block |
Hash | Number |
- Source:
Returns:
- Type
- Promise
(private) resolveOrphan(hash) → {Orphan}
Resolve an orphan.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | Previous block hash. |
- Source:
Returns:
- Type
- Orphan
retarget(first, last) → {Number}
Calculate the next target.
Parameters:
Name | Type | Description |
---|---|---|
first |
ChainEntry | Suitable block from 1 day prior. |
last |
ChainEntry | Last suitable block. |
- Source:
Returns:
target - Target in compact/mantissa form.
- Type
- Number
(async, private) saveAlternate(entry, block, prev, flags) → {Promise}
Save block on an alternate chain.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block | |
prev |
ChainEntry | |
flags |
Number |
- Source:
Returns:
- Type
- Promise
(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) scanInteractive(start, filter, iter, fullLockopt) → {Promise.<void>}
Interactive scan the blockchain for transactions containing specified address hashes. Allows repeat and abort.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Hash | Number | Block hash or height to start at. |
||
filter |
BloomFilter | Starting bloom filter containing tx, address and name hashes. |
||
iter |
ScanInteractiveIterCB | Iterator. |
||
fullLock |
Boolean |
<optional> |
false |
- Source:
Returns:
- Type
- Promise.<void>
(async, private) setBestChain(entry, block, prev, flags) → {Promise}
Set the best chain. This is called on every incoming block with greater chainwork than the current tip.
Parameters:
Name | Type | Description |
---|---|---|
entry |
ChainEntry | |
block |
Block | |
prev |
ChainEntry | |
flags |
Number |
- Source:
Returns:
- Type
- Promise
setDeploymentState(state)
Set a new deployment state.
Parameters:
Name | Type | Description |
---|---|---|
state |
DeploymentState |
- Source:
(private) setInvalid(hash)
Mark a block as invalid.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- Source:
(private) storeOrphan(block, flagsnullable, idnullable)
Store an orphan.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
block |
Block | ||
flags |
Number |
<nullable> |
|
id |
Number |
<nullable> |
- Source:
(async) syncTree()
Sync tree state.
- Source:
(async) tryCompact() → {Promise.<Boolean>}
Check if we need to compact tree data.
- Source:
Returns:
- Should we sync
- Type
- Promise.<Boolean>
(async, private) unreorganize(fork, last) → {Promise}
Revert a failed reorganization.
Parameters:
Name | Type | Description |
---|---|---|
fork |
ChainEntry | The common ancestor. |
last |
ChainEntry | The previous valid tip. |
- Source:
Returns:
- Type
- Promise
(async, private) updateInputs(block, prev, state) → {Promise.<CoinView>}
Spend and update inputs (checkpoints only).
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
prev |
ChainEntry | |
state |
DeploymentState |
- Source:
Returns:
- Type
- Promise.<CoinView>
(async, private) verify(block, prev, flags) → {Promise.<DeploymentState>}
Contextual verification for a block, including version deployments (IsSuperMajority), versionbits, coinbase height, finality checks.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
prev |
ChainEntry | |
flags |
Number |
- Source:
Returns:
- Type
- Promise.<DeploymentState>
(async) verifyBlock(block) → {Promise.<Array>}
Perform all necessary contextual verification on a block, without POW check.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block |
- Source:
Returns:
- [CoinView, DeploymentState]
- Type
- Promise.<Array>
(private) verifyCheckpoint(prev, hash) → {Boolean}
Verify a block hash and height against the checkpoints.
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | |
hash |
Hash |
- Source:
Returns:
- Type
- Boolean
(async, private) verifyContext(block, prev, flags) → {Promise.<Array>}
Perform all necessary contextual verification on a block.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
prev |
ChainEntry | |
flags |
Number |
- Source:
Returns:
- [CoinView, DeploymentState]
- Type
- Promise.<Array>
(async) verifyCovenants(tx, view, height, nameFlags)
Verify covenants.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX | |
view |
CoinView | |
height |
Number | |
nameFlags |
Number |
- Source:
(async) verifyFinal(prev, tx, flags) → {Promise}
Check transaction finality, taking into account MEDIAN_TIME_PAST if it is present in the lock flags.
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | Previous chain entry. |
tx |
TX | |
flags |
LockFlags |
- Source:
Returns:
- Returns Boolean.
- Type
- Promise
(async, private) verifyInputs(block, prev, state) → {Promise.<CoinView>}
Check block transactions for all things pertaining
to inputs. This function is important because it is
what actually fills the coins into the block. This
function will check the block reward, the sigops,
the tx values, and execute and verify the scripts (it
will attempt to do this on the worker pool). If
checkpoints
is enabled, it will skip verification
for historical data.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | |
prev |
ChainEntry | |
state |
DeploymentState |
- Source:
- See:
-
- TX#verifyInputs
- TX#verify
Returns:
- Type
- Promise.<CoinView>
(async) verifyLocks(prev, tx, view, flags) → {Promise}
Verify sequence locks.
Parameters:
Name | Type | Description |
---|---|---|
prev |
ChainEntry | |
tx |
TX | |
view |
CoinView | |
flags |
LockFlags |
- Source:
Returns:
- Returns Boolean.
- Type
- Promise
(async) verifyRenewal(hash, height) → {Promise.<Boolean>}
Verify a renewal.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash | |
height |
Number |
- Source:
Returns:
- Type
- Promise.<Boolean>