Class: BlockTemplate

mining~BlockTemplate(options)

Block Template

Constructor

new BlockTemplate(options)

Create a block template.

Parameters:
Name Type Description
options Object
Source:

Methods

(static) fromOptions(options) → {BlockTemplate}

Instantiate block template from options.

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

addTX(tx, view)

Add a transaction to the template.

Parameters:
Name Type Description
tx TX
view CoinView
Source:

commit(proof) → {Block}

Create block from calculated proof.

Parameters:
Name Type Description
proof BlockProof
Source:
Returns:
Type
Block

createCoinbase(hash) → {TX}

Initialize the default coinbase.

Parameters:
Name Type Description
hash Buffer

Witness commitment hash.

Source:
Returns:
Type
TX

(private) fromOptions(options) → {BlockTemplate}

Inject properties from options.

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

getCoinbase(nonce1, nonce2) → {TX}

Create coinbase from given parameters.

Parameters:
Name Type Description
nonce1 Number
nonce2 Number
Source:
Returns:
Type
TX

getDifficulty() → {Number}

Calculate the target difficulty.

Source:
Returns:
Type
Number

getHeader(root, time, nonce) → {Buffer}

Create raw block header with given parameters.

Parameters:
Name Type Description
root Buffer
time Number
nonce Number
Source:
Returns:
Type
Buffer

getProof(nonce1, nonce2, time, nonce) → {BlockProof}

Calculate proof with given parameters.

Parameters:
Name Type Description
nonce1 Number
nonce2 Number
time Number
nonce Number
Source:
Returns:
Type
BlockProof

getRawCoinbase(nonce1, nonce2) → {Buffer}

Get raw coinbase with desired nonces.

Parameters:
Name Type Description
nonce1 Number
nonce2 Number
Source:
Returns:
Type
Buffer

getReward() → {Amount}

Calculate the block reward.

Source:
Returns:
Type
Amount

getRoot(nonce1, nonce2) → {Buffer}

Calculate the merkle root with given nonces.

Parameters:
Name Type Description
nonce1 Number
nonce2 Number
Source:
Returns:
Type
Buffer

getWitnessHash() → {Buffer}

Create witness commitment hash.

Source:
Returns:
Type
Buffer

getWitnessScript() → {Script}

Create witness commitment script.

Source:
Returns:
Type
Script

pushTX(tx, viewnullable)

Add a transaction to the template (less verification than addTX).

Parameters:
Name Type Attributes Description
tx TX
view CoinView <nullable>
Source:

refresh()

Refresh the coinbase and merkle tree.

Source:

setAddress(address)

Set the reward output address and refresh.

Parameters:
Name Type Description
address Address
Source:

setBits(bits)

Set the target (bits).

Parameters:
Name Type Description
bits Number
Source:

setTarget(target)

Set the target (uint256le).

Parameters:
Name Type Description
target Buffer
Source:

toBlock() → {Block}

Quick and dirty way to get a block object (most likely to be an invalid one).

Source:
Returns:
Type
Block

toCoinbase() → {TX}

Quick and dirty way to get a coinbase tx object.

Source:
Returns:
Type
TX