witness commit

This commit is contained in:
Ben
2023-07-09 16:40:30 -04:00
parent b6ddca5a8f
commit 80e8b38d24
+5 -6
View File
@@ -37,7 +37,7 @@ export class MiningJob {
const coinbaseTransaction = this.createCoinbaseTransaction(payoutInformation, this.blockTemplate.coinbasevalue); const coinbaseTransaction = this.createCoinbaseTransaction(payoutInformation, this.blockTemplate.coinbasevalue);
this.block.transactions.unshift(coinbaseTransaction); this.block.transactions.unshift(coinbaseTransaction);
// this.block.witnessCommit = bitcoinjs.Block.calculateMerkleRoot(this.block.transactions, true); this.block.witnessCommit = bitcoinjs.Block.calculateMerkleRoot(this.block.transactions, true);
@@ -51,12 +51,12 @@ export class MiningJob {
// 1-byte - OP_RETURN (0x6a) // 1-byte - OP_RETURN (0x6a)
// 1-byte - Push the following 36 bytes (0x24) // 1-byte - Push the following 36 bytes (0x24)
// 4-byte - Commitment header (0xaa21a9ed) // 4-byte - Commitment header (0xaa21a9ed)
//const segwitMagicBits = Buffer.from('aa21a9ed', 'hex'); const segwitMagicBits = Buffer.from('aa21a9ed', 'hex');
// 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(Buffer.concat([this.block.witnessCommit, coinbaseTransaction.ins[0].witness[0]]))); const commitmentHash = this.sha256(this.sha256(Buffer.concat([this.block.witnessCommit, coinbaseTransaction.ins[0].witness[0]])));
// 39th byte onwards: Optional data with no consensus meaning // 39th byte onwards: Optional data with no consensus meaning
coinbaseTransaction.ins[0].script = Buffer.concat([Buffer.from([littleEndianBlockHeight.byteLength]), littleEndianBlockHeight, Buffer.from('00000000' + '00000000', 'hex')]); coinbaseTransaction.ins[0].script = Buffer.concat([Buffer.from([littleEndianBlockHeight.byteLength]), littleEndianBlockHeight, Buffer.from('00000000' + '00000000', 'hex')]);
//coinbaseTransaction.addOutput(bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.concat([segwitMagicBits, commitmentHash])]), 0); coinbaseTransaction.addOutput(bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.concat([segwitMagicBits, commitmentHash])]), 0);
// get the non-witness coinbase tx // get the non-witness coinbase tx
//@ts-ignore //@ts-ignore
@@ -108,9 +108,8 @@ export class MiningJob {
const segwitMagicBits = Buffer.from('aa21a9ed', 'hex'); const segwitMagicBits = Buffer.from('aa21a9ed', 'hex');
// 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(Buffer.concat([testBlock.witnessCommit, testBlock.transactions[0].ins[0].witness[0]]))); const commitmentHash = this.sha256(this.sha256(Buffer.concat([testBlock.witnessCommit, testBlock.transactions[0].ins[0].witness[0]])));
// testBlock.transactions[0].outs[testBlock.transactions[0].outs.length - 1].script = bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.concat([segwitMagicBits, commitmentHash])]) testBlock.transactions[0].outs[testBlock.transactions[0].outs.length - 1].script = bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.concat([segwitMagicBits, commitmentHash])])
testBlock.transactions[0].addOutput(bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.concat([segwitMagicBits, commitmentHash])]), 0)
testBlock.timestamp = timestamp; testBlock.timestamp = timestamp;
return testBlock; return testBlock;