Class: ChainEntry

blockchain.ChainEntry

new ChainEntry(chain, options, prev)

Represents an entry in the chain. Unlike other bitcoin fullnodes, we store the chainwork with the entry in order to avoid reading the entire chain index on boot and recalculating the chainworks.

Parameters:
Name Type Description
chain Chain
options Object
prev ChainEntry
Properties:
Name Type Description
hash Hash
version Number

Transaction version. Note that Bcoin reads versions as unsigned even though they are signed at the protocol level. This value will never be negative.

prevBlock Hash
merkleRoot Hash
ts Number
bits Number
nonce Number
height Number
chainwork BN
rhash ReversedHash

Reversed block hash (uint256le).

Source:

Members

(static, constant) MAX_CHAINWORK :BN

The max chainwork (1 << 256).

Type:
Source:

(static, constant) MEDIAN_TIMESPAN :Number

Size of set to pick median time from.

Type:
  • Number
Default Value:
  • 11
Source:

Methods

(static) fromBlock(chain, block, prev) → {ChainEntry}

Instantiate chainentry from block.

Parameters:
Name Type Description
chain Chain
block Block | MerkleBlock
prev ChainEntry

Previous entry.

Source:
Returns:
Type
ChainEntry

(static) fromJSON(chain, json) → {ChainEntry}

Instantiate block from jsonified object.

Parameters:
Name Type Description
chain Chain
json Object
Source:
Returns:
Type
ChainEntry

(static) fromOptions(chain, options, prev) → {ChainEntry}

Instantiate chainentry from options.

Parameters:
Name Type Description
chain Chain
options Object
prev ChainEntry

Previous entry.

Source:
Returns:
Type
ChainEntry

(static) fromRaw(chain, data) → {ChainEntry}

Deserialize the entry.

Parameters:
Name Type Description
chain Chain
data Buffer
Source:
Returns:
Type
ChainEntry

(static) isChainEntry(obj) → {Boolean}

Test whether an object is a ChainEntry.

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Boolean

(private) fromBlock(block, prev)

Inject properties from block.

Parameters:
Name Type Description
block Block | MerkleBlock
prev ChainEntry

Previous entry.

Source:

(private) fromJSON(json)

Inject properties from json object.

Parameters:
Name Type Description
json Object
Source:

(private) fromOptions(options, prev)

Inject properties from options.

Parameters:
Name Type Description
options Object
prev ChainEntry

Previous entry.

Source:

(private) fromRaw(data)

Inject properties from serialized data.

Parameters:
Name Type Description
data Buffer
Source:

getAncestor(height) → {Promise}

Get ancestor by height.

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

getAncestors(max) → {Promise}

Collect ancestors.

Parameters:
Name Type Description
max Number

Number of ancestors.

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

getChainwork() → {BN}

Calculate the chainwork by adding proof to previous chainwork.

Source:
Returns:

chainwork

Type
BN

getMedianTime(ancestors) → {Number}

Get median time past.

Parameters:
Name Type Description
ancestors Array:.<ChainEntry:>

Note that index 0 is the same entry.

Source:
See:
  • GetMedianTimePast().
Returns:

Median time past.

Type
Number

getMedianTimeAsync() → {Promise}

Get median time past asynchronously (see ChainEntry#getMedianTime).

Source:
Returns:
  • Returns Number.
Type
Promise

getNext() → {Promise}

Get next entry.

Source:
Returns:
  • Returns ChainEntry.
Type
Promise

getNextEntry() → {Promise}

Get next entry.

Source:
Returns:
  • Returns ChainEntry.
Type
Promise

getPrevious() → {Promise}

Get previous entry.

Source:
Returns:
  • Returns ChainEntry.
Type
Promise

getProof() → {BN}

Calculate the proof: (1 << 256) / (target + 1)

Source:
Returns:

proof

Type
BN

getRetargetAncestors() → {Promise}

Allocate ancestors based on retarget interval and majority window. These ancestors will be stored in the ancestors array and enable use of synchronous ChainEntry methods.

Source:
Returns:
Type
Promise

hasBit(deployment) → {Boolean}

Test whether the entry contains a version bit.

Parameters:
Name Type Description
deployment Object
Source:
Returns:
Type
Boolean

hasUnknown() → {Boolean}

Test whether the entry contains an unknown version bit.

Source:
Returns:
Type
Boolean

inspect() → {Object}

Return a more user-friendly object.

Source:
Returns:
Type
Object

isGenesis() → {Boolean}

Test against the genesis block.

Source:
Returns:
Type
Boolean

isHistorical() → {Boolean}

Test whether the entry is potentially an ancestor of a checkpoint.

Source:
Returns:
Type
Boolean

isMainChain() → {Promise}

Test whether the entry is in the main chain.

Source:
Returns:
  • Return Boolean.
Type
Promise

rhash() → {Hash}

Get little-endian block hash.

Source:
Returns:
Type
Hash

toHeaders() → {Headers}

Convert the entry to a headers object.

Source:
Returns:
Type
Headers

toInv() → {InvItem}

Convert the entry to an inv item.

Source:
Returns:
Type
InvItem

toJSON() → {Object}

Serialize the entry to an object more suitable for JSON serialization.

Source:
Returns:
Type
Object

toRaw() → {Buffer}

Serialize the entry to internal database format.

Source:
Returns:
Type
Buffer