Constructor
new Block(optionsopt)
Create a block.
Extends:
- AbstractBlock
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> |
- Source:
Extends
- AbstractBlock
Members
(nullable) _raw :Buffer
Type:
- Buffer
- Source:
(nullable) _sizes :Sizes
Type:
- Sizes
- Source:
txs :Array.<TX>
Type:
- Array.<TX>
- Source:
Methods
(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
createMerkleRoot() → {Hash}
Calculate merkle root.
- Source:
Returns:
- Type
- Hash
createWitnessRoot() → {Hash}
Calculate witness root.
- Source:
Returns:
- Type
- Hash
encode() → {Buffer}
- Source:
Returns:
- Type
- Buffer
format(viewopt, heightopt) → {Object}
Inspect the block and return a more user-friendly representation of the data.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
view |
CoinView |
<optional> |
|
height |
Number |
<optional> |
- Source:
Returns:
- Type
- Object
fromJSON(json)
Inject properties from json object.
Parameters:
Name | Type | Description |
---|---|---|
json |
Object |
- Source:
fromOptions(options)
Inject properties from options object.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- Source:
getBaseSize() → {Number}
Get base block size (without witness).
- Source:
Returns:
size
- Type
- Number
getClaimed() → {AmountValue}
Get the "claimed" reward by the coinbase.
- Source:
Returns:
claimed
- Type
- AmountValue
getCoinbaseHeight() → {Number}
Retrieve the coinbase height from the coinbase input script.
- Source:
Returns:
height (-1 if not present).
- Type
- Number
getJSON(networkopt, viewopt, heightopt, depthopt) → {Object}
Convert the block to an object suitable for JSON serialization.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
network |
Network |
<optional> |
|
view |
CoinView |
<optional> |
|
height |
Number |
<optional> |
|
depth |
Number |
<optional> |
- Source:
Returns:
- Type
- Object
getMerkleRoot() → {Hash}
Retrieve the merkle root from the block header.
- Source:
Returns:
- Type
- Hash
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() → {Sizes}
Get real block size with witness.
- Source:
Returns:
- Type
- Sizes
getVirtualSize() → {Number}
Calculate virtual block size.
- Source:
Returns:
Virtual size.
- Type
- Number
getWeight() → {Number}
Calculate block weight.
- Source:
Returns:
weight
- Type
- Number
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
read(br)
Inject properties from serialized data.
Parameters:
Name | Type | Description |
---|---|---|
br |
bio.BufferReader |
- Source:
refresh(allopt, nullable) → {this}
Clear any cached values.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
all |
Boolean |
<optional> <nullable> |
Clear transactions. |
- Source:
Returns:
- Type
- this
toHeaders() → {Headers}
Convert the block to a headers object.
- Source:
Returns:
- Type
- Headers
toMerkle(filter) → {MerkleBlock}
Convert the Block to a MerkleBlock.
Parameters:
Name | Type | Description |
---|---|---|
filter |
BloomFilter | Bloom filter for transactions to match. The merkle block will contain only the matched transactions. |
- Source:
Returns:
- Type
- MerkleBlock
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
write(bw) → {BufioWriter}
Parameters:
Name | Type | Description |
---|---|---|
bw |
BufioWriter |
- Source:
Returns:
- Type
- BufioWriter