Constructor
new Block(options)
Create a block.
Extends:
- AbstractBlock
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- 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 |
- 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 |
- 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
checkBody() → {Array}
Do non-contextual verification on the block. Including checking the block size, the coinbase and the merkle root. This is consensus-critical.
- Source:
Returns:
[valid, reason, score]
- Type
- Array
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 |
- 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 |
- 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, depth) → {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 | |
depth |
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>
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 size
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
hasRaw() → {Buffer}
Check if block has been serialized.
- Source:
Returns:
- Type
- Buffer
hasTX(hash) → {Boolean}
Test the block's transaction vector against a hash.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Hash |
- 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 |
- Source:
Returns:
index (-1 if not present).
- Type
- Number
inspectSymbol() → {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:
verifyBody() → {Boolean}
Do non-contextual verification on the block. Including checking the block size, the coinbase and the merkle root. This is consensus-critical.
- Source:
Returns:
- Type
- Boolean
(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