mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
fix the coinbase tx
This commit is contained in:
@@ -47,14 +47,16 @@ export class MiningJob {
|
|||||||
// 32-byte - Commitment hash: Double-SHA256(witness root hash|witness reserved value)
|
// 32-byte - Commitment hash: Double-SHA256(witness root hash|witness reserved value)
|
||||||
const commitmentHash = this.sha256(this.sha256(this.block.witnessCommit));
|
const commitmentHash = this.sha256(this.sha256(this.block.witnessCommit));
|
||||||
// 39th byte onwards: Optional data with no consensus meaning
|
// 39th byte onwards: Optional data with no consensus meaning
|
||||||
coinbaseTransaction.outs[0].script = bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.concat([segwitMagicBits, commitmentHash])]);
|
coinbaseTransaction.ins[0].script = bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.concat([segwitMagicBits, commitmentHash, Buffer.from('00000000' + '00000000', 'hex')])]);
|
||||||
|
|
||||||
// get the non-witness coinbase tx
|
// get the non-witness coinbase tx
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const serializedCoinbaseTx = coinbaseTransaction.__toBuffer().toString('hex');
|
const serializedCoinbaseTx = coinbaseTransaction.__toBuffer().toString('hex');
|
||||||
|
|
||||||
const blockHeightScript = `03${this.blockTemplate.height.toString(16).padStart(8, '0')}` + '00000000' + '00000000';
|
const inputScript = coinbaseTransaction.ins[0].script.toString('hex');
|
||||||
const partOneIndex = serializedCoinbaseTx.indexOf(blockHeightScript) + blockHeightScript.length;
|
|
||||||
|
|
||||||
|
const partOneIndex = serializedCoinbaseTx.indexOf(inputScript) + inputScript.length;
|
||||||
|
|
||||||
const coinbasePart1 = serializedCoinbaseTx.slice(0, partOneIndex);
|
const coinbasePart1 = serializedCoinbaseTx.slice(0, partOneIndex);
|
||||||
const coinbasePart2 = serializedCoinbaseTx.slice(partOneIndex);
|
const coinbasePart2 = serializedCoinbaseTx.slice(partOneIndex);
|
||||||
@@ -87,9 +89,7 @@ export class MiningJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set the nonces
|
// set the nonces
|
||||||
const blockHeightScript = `03${this.blockTemplate.height.toString(16).padStart(8, '0')}${extraNonce}${extraNonce2}`;
|
testBlock.transactions[0].ins[0].script = Buffer.from(testBlock.transactions[0].ins[0].script.toString('hex').replace('0000000000000000', `${extraNonce}${extraNonce2}`), 'hex');
|
||||||
const inputScript = bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.from(blockHeightScript, 'hex')]);
|
|
||||||
testBlock.transactions[0].ins[0].script = inputScript;
|
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
//recompute the root
|
//recompute the root
|
||||||
@@ -124,12 +124,11 @@ export class MiningJob {
|
|||||||
// Set the version of the transaction
|
// Set the version of the transaction
|
||||||
coinbaseTransaction.version = 2;
|
coinbaseTransaction.version = 2;
|
||||||
|
|
||||||
const blockHeightScript = `03${blockHeight.toString(16).padStart(8, '0')}` + '00000000' + '00000000';
|
|
||||||
|
|
||||||
const inputScript = bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.from(blockHeightScript, 'hex')])
|
// const inputScript = bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.from('00000000' + '00000000', 'hex')])
|
||||||
|
|
||||||
// Add the coinbase input (input with no previous output)
|
// Add the coinbase input (input with no previous output)
|
||||||
coinbaseTransaction.addInput(Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'), 0xffffffff, 0xffffffff, inputScript);
|
coinbaseTransaction.addInput(Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'), 0xffffffff, 0xffffffff);
|
||||||
|
|
||||||
// Add an output
|
// Add an output
|
||||||
let rewardBalance = reward;
|
let rewardBalance = reward;
|
||||||
|
|||||||
Reference in New Issue
Block a user