Skip to content

Commit

Permalink
fix: coinbase serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Nesopie committed Mar 25, 2024
1 parent ccefc93 commit 2cfc78d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
output.txt
4 changes: 2 additions & 2 deletions output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
040000000000ffff00000000000000000000000000000000000000000000000000000000644fbf96c3029092bc313552afed1d20bf61e3e874ff09ec696496a1dd2d0e2854220166ffff001f68450000
00000000010000000000000000000000000000000000000000000000000000000000000000ffffffff040323370800000000028651da4d000000001976a914edf10a7fac6b32e24daa5305c723f3de58db1bc888ac0000000000000000266a24aa21a9edf600a0667d8eef335e2f4cd9eaf746ce287bb6f62e9b0ef94869c65420a959a100000000
040000000000ffff00000000000000000000000000000000000000000000000000000000644fbf96c3029092bc313552afed1d20bf61e3e874ff09ec696496a1dd2d0e28c5250166ffff001f8e190000
000000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff040323370800000000028651da4d000000001976a914edf10a7fac6b32e24daa5305c723f3de58db1bc888ac0000000000000000266a24aa21a9edf600a0667d8eef335e2f4cd9eaf746ce287bb6f62e9b0ef94869c65420a959a10120000000000000000000000000000000000000000000000000000000000000000000000000
66de1e6c0437305764ab5ba0104bb5bdb6dc4a48b83323aeff155d2684cabccc
a9f1f2279711f476c30e2e1382a0e99358c662a48fbd1774d7e5e7f8ea27d98d
b9ea7324bf46de83ff81f0876dd8e6e8485318165cf9c5073549dd8824c7c2d3
Expand Down
2 changes: 1 addition & 1 deletion src/features/block/coinbaseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const coinbaseTemplate = {
prevout: null,
scriptsig: "03233708",
scriptsig_asm: "OP_PUSHBYTES_3 233708",
witness: [Buffer.from(ZEROS, "hex")],
witness: [ZEROS],
},
],
vout: [
Expand Down
6 changes: 1 addition & 5 deletions src/features/encoding/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ export const txSerializer = (tx: Transaction) => {

return {
serializedTx,
serializedWTx: isWitness
? tx.vin[0].txid === ZEROS
? ZEROS
: serializedWTx
: serializedTx,
serializedWTx: isWitness ? serializedWTx : serializedTx,
};
};

Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { txSerializer, txWeight } from "./features/encoding/serializer";
import { feePerByte } from "./features/block/fee";
import { mine } from "./features/block/mine";
import * as path from "path";
import * as bitcoin from "bitcoinjs-lib";

(async () => {
const files = fs.readdirSync("./mempool");
Expand Down Expand Up @@ -38,6 +39,10 @@ import * as path from "path";

const { serializedBlock, blockHash, coinbaseTransaction } = mine(txs);

const ct = bitcoin.Transaction.fromHex(
txSerializer(coinbaseTransaction).serializedWTx
);

fs.writeFileSync(outputFile, serializedBlock);
fs.appendFileSync(outputFile, "\n");
fs.appendFileSync(
Expand Down

0 comments on commit 2cfc78d

Please sign in to comment.