Class: Block

primitives.Block

new Block(options)

Represents a full block.

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

Extends

  • AbstractBlock

Methods

(static) fromJSON(json) → {Block}

Instantiate a block from a jsonified block object.

Parameters:
Name Type Description
json Object

The jsonified block object.

Source:
Returns:
Type
Block

(static) fromOptions(options) → {Block}

Instantiate block from options.

Parameters:
Name Type Description
options Object
Source:
Returns:
Type
Block

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

Instantiate a block from a serialized Buffer.

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

Encoding, can be 'hex' or null.

Source:
Returns:
Type
Block

(static) fromReader(data, encnullable) → {Block}

Instantiate a block from a serialized Buffer.

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

Encoding, can be 'hex' or null.

Source:
Returns:
Type
Block

(static) isBlock(obj) → {Boolean}

Test whether an object is a Block.

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

createCommitmentHash(encnullable) → {Hash}

Calculate commitment hash (the root of the witness merkle tree hashed with the witnessNonce).

Parameters:
Name Type Attributes Description
enc String <nullable>

Encoding, can be 'hex' or null.

Source:
Returns:
Type
Hash

createMerkleRoot(encnullable) → {Hash|null}

Calculate merkle root. Returns null if merkle tree has been malleated.

Parameters:
Name Type Attributes Description
enc String <nullable>

Encoding, can be 'hex' or null.

Source:
Returns:
Type
Hash | null

createWitnessNonce() → {Buffer}

Create a witness nonce (for mining).

Source:
Returns:
Type
Buffer

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) frame() → {RawBlock}

Get the raw block serialization. Include witnesses if present.

Source:
Returns:
Type
RawBlock

(private) frameNormal(witness, writernullable) → {Buffer}

Serialze block with or without witness data.

Parameters:
Name Type Attributes Description
witness Boolean
writer BufferWriter <nullable>
Source:
Returns:
Type
Buffer

(private) frameWitness(writernullable) → {Buffer}

Serialze block without witness data.

Parameters:
Name Type Attributes Description
writer BufferWriter <nullable>
Source:
Returns:
Type
Buffer

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

(private) fromRaw(data)

Inject properties from serialized data.

Parameters:
Name Type Description
data Buffer
Source:

(private) fromReader(data)

Inject properties from serialized data.

Parameters:
Name Type Description
data Buffer
Source:

getBaseSize() → {Number}

Get base block size (without witness).

Source:
Returns:

size

Type
Number

getClaimed() → {Amount}

Get the "claimed" reward by the coinbase.

Source:
Returns:

claimed

Type
Amount

getCoinbaseHeight() → {Number}

Retrieve the coinbase height from the coinbase input script.

Source:
Returns:

height (-1 if not present).

Type
Number

getCommitmentHash(encnullable) → {Hash|null}

Retrieve the commitment hash from the coinbase's outputs.

Parameters:
Name Type Attributes Description
enc String <nullable>
Source:
Returns:
Type
Hash | null

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

getMerkleRoot(encnullable) → {Hash}

Retrieve the merkle root from the block header.

Parameters:
Name Type Attributes Description
enc String <nullable>
Source:
Returns:
Type
Hash

getNormalSizes() → {RawBlock}

Get real block size without witness.

Source:
Returns:
Type
RawBlock

getPrevout() → {Array:.<Hash:>}

Get all unique outpoint hashes in the block. Coinbases are ignored.

Source:
Returns:

Outpoint hashes.

Type
Array:.<Hash:>

getReward() → {Amount}

Calculate the block reward.

Source:
Returns:

reward

Type
Amount

getSize() → {Number}

Get real block size.

Source:
Returns:

size

Type
Number

getSizes() → {Object}

Calculate real size and size of the witness bytes.

Source:
Returns:

Contains total and witness.

Type
Object

getVirtualSize() → {Number}

Calculate virtual block size.

Source:
Returns:

Virtual size.

Type
Number

getWeight() → {Number}

Calculate block weight.

Source:
Returns:

weight

Type
Number

getWitnessNonce() → {Buffer|null}

Retrieve the witness nonce from the coinbase's witness vector (if present).

Source:
Returns:
Type
Buffer | null

getWitnessSizes() → {RawBlock}

Get real block size with witness.

Source:
Returns:
Type
RawBlock

hasTX(hash) → {Boolean}

Test the block's transaction vector against a hash.

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

hasWitness() → {Boolean}

Test whether the block contains a transaction with a non-empty witness.

Source:
Returns:
Type
Boolean

indexOf(hash) → {Number}

Find the index of a transaction in the block.

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

index (-1 if not present).

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

toMerkle(filter) → {MerkleBlock}

Convert the Block to a MerkleBlock.

Parameters:
Name Type Description
filter Bloom

Bloom filter for transactions to match. The merkle block will contain only the matched transactions.

Source:
Returns:
Type
MerkleBlock

toNormal() → {Buffer}

Serialize the block, do not include witnesses.

Source:
Returns:
Type
Buffer

toNormalWriter(bw)

Serialize the block, do not include witnesses.

Parameters:
Name Type Description
bw BufferWriter
Source:

toRaw() → {Buffer}

Serialize the block. Include witnesses if present.

Source:
Returns:
Type
Buffer

toWriter(bw)

Serialize the block. Include witnesses if present.

Parameters:
Name Type Description
bw BufferWriter
Source:

(private) writeNormal(witness, writernullable) → {Buffer}

Serialze block with or without witness data.

Parameters:
Name Type Attributes Description
witness Boolean
writer BufferWriter <nullable>
Source:
Returns:
Type
Buffer

(private) writeWitness(witness, writernullable) → {Buffer}

Serialze block with or without witness data.

Parameters:
Name Type Attributes Description
witness Boolean
writer BufferWriter <nullable>
Source:
Returns:
Type
Buffer