Class: MerkleBlock

primitives.MerkleBlock

new MerkleBlock(options)

Represents a merkle (filtered) block.

Extends:
  • AbstractBlock
Parameters:
Name Type Description
options NakedBlock
Source:

Extends

  • AbstractBlock

Methods

(static) fromBlock(block, filter) → {MerkleBlock}

Create a merkleblock from a Block object, passing it through a filter first. This will build the partial merkle tree.

Parameters:
Name Type Description
block Block
filter Bloom
Source:
Returns:
Type
MerkleBlock

(static) fromHashes(block, hashes) → {MerkleBlock}

Create a merkleblock from an array of txids. This will build the partial merkle tree.

Parameters:
Name Type Description
block Block
hashes Array:.<Hash:>
Source:
Returns:
Type
MerkleBlock

(static) fromJSON(json) → {MerkleBlock}

Instantiate a merkle block from a jsonified block object.

Parameters:
Name Type Description
json Object

The jsonified block object.

Source:
Returns:
Type
MerkleBlock

(static) fromMatches(block, matches) → {MerkleBlock}

Create a merkleblock from an array of matches. This will build the partial merkle tree.

Parameters:
Name Type Description
block Block
matches Array:.<Number:>
Source:
Returns:
Type
MerkleBlock

(static) fromOptions(options) → {MerkleBlock}

Instantiate merkle block from options object.

Parameters:
Name Type Description
options NakedBlock
Source:
Returns:
Type
MerkleBlock

(static) fromRaw(data, encnullable) → {MerkleBlock}

Instantiate a merkleblock from a serialized data.

Parameters:
Name Type Attributes Description
data Buffer
enc String <nullable>

Encoding, can be 'hex' or null.

Source:
Returns:
Type
MerkleBlock

(static) fromReader(br) → {MerkleBlock}

Instantiate a merkleblock from a buffer reader.

Parameters:
Name Type Description
br BufferReader
Source:
Returns:
Type
MerkleBlock

(static) isMerkleBlock(obj) → {Boolean}

Test whether an object is a MerkleBlock.

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

addTX(tx) → {Number}

Add a transaction to the block's tx vector.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Number

(private) extractTree() → {Object}

Extract the matches from partial merkle tree and calculate merkle root.

Source:
Returns:
Type
Object

format(view, height) → {Object}

Inspect the block and return a more user-friendly representation of the data.

Parameters:
Name Type Description
view CoinView
height Number
Source:
Returns:
Type
Object

(private) fromJSON(json)

Inject properties from json object.

Parameters:
Name Type Description
json Object
Source:

(private) fromOptions(options)

Inject properties from options object.

Parameters:
Name Type Description
options NakedBlock
Source:

(private) fromRaw(data)

Inject properties from serialized data.

Parameters:
Name Type Description
data Buffer
Source:

(private) fromReader(br)

Inject properties from buffer reader.

Parameters:
Name Type Description
br BufferReader
Source:

getCoinbaseHeight() → {Number}

Extract the coinbase height (always -1).

Source:
Returns:
Type
Number

getJSON(network, view, height) → {Object}

Convert the block to an object suitable for JSON serialization. Note that the hashes will be reversed to abide by bitcoind's legacy of little-endian uint256s.

Parameters:
Name Type Description
network Network
view CoinView
height Number
Source:
Returns:
Type
Object

getSize() → {Number}

Get merkleblock size.

Source:
Returns:

Size.

Type
Number

hasTX(hash) → {Boolean}

Test the block's matched transaction vector against a hash.

Parameters:
Name Type Description
hash Hash | TX
Source:
Returns:
Type
Boolean

indexOf(hash) → {Number}

Test the block's matched transaction vector against a hash.

Parameters:
Name Type Description
hash Hash | TX
Source:
Returns:

Index.

Type
Number

inspect() → {Object}

Inspect the block and return a more user-friendly representation of the data.

Source:
Returns:
Type
Object

refresh(allnullable)

Clear any cached values.

Parameters:
Name Type Attributes Description
all Boolean <nullable>

Clear transactions.

Source:

toHeaders() → {Headers}

Convert the block to a headers object.

Source:
Returns:
Type
Headers

toJSON() → {Object}

Convert the block to an object suitable for JSON serialization.

Source:
Returns:
Type
Object

toRaw(encnullable) → {Buffer|String}

Serialize the merkleblock.

Parameters:
Name Type Attributes Description
enc String <nullable>

Encoding, can be 'hex' or null.

Source:
Returns:
Type
Buffer | String

toWriter(bw)

Write the merkleblock to a buffer writer.

Parameters:
Name Type Description
bw BufferWriter
Source:

(private) verifyPartial() → {Boolean}

Verify the partial merkletree. Push leaves onto MerkleBlock#tx and into MerkleBlock#map.

Source:
Returns:
Type
Boolean