From e49c9f73382c70bae45c36e2f8178560fade3c2a Mon Sep 17 00:00:00 2001 From: Nisarg Thakkar <89217455+Nishu0@users.noreply.github.com> Date: Tue, 7 May 2024 20:33:36 +0530 Subject: [PATCH] :chart_with_upwards_trend: Coinbase Txid to Output.txt --- src/features/block/mine.ts | 4 +++- src/index.ts | 15 +++++++-------- src/utils.ts | 9 +-------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/features/block/mine.ts b/src/features/block/mine.ts index b1a3fa9..6381920 100644 --- a/src/features/block/mine.ts +++ b/src/features/block/mine.ts @@ -34,7 +34,9 @@ export const mine = ( const prevBlockHash = "0000ffff00000000000000000000000000000000000000000000000000000000"; //make it the same as the difficulty const merkleRootHash = merkleRoot( - txs.map((tx) => reversify(sha256(sha256(txSerializer(tx).serializedTx)))) + [coinbaseTransaction, ...txs].map((tx) => + reversify(sha256(sha256(txSerializer(tx).serializedTx))) + ) ); const time = Buffer.alloc(4); diff --git a/src/index.ts b/src/index.ts index ac95ffe..d714523 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,6 @@ import * as fs from "fs"; import { Transaction } from "./types"; -// import { mempool } from "./store/mempool"; -import { utxos } from "./store/utxos"; -import { LengthValidator } from "./features/validator/length"; -import { HashValidator } from "./features/validator/hash"; + import { reversify, sha256 } from "./utils"; import { txSerializer, txWeight } from "./features/encoding/serializer"; import { feePerByte } from "./features/block/fee"; @@ -19,10 +16,7 @@ import * as path from "path"; for (const file of files) { const tx = JSON.parse(fs.readFileSync(`./mempool/${file}`, "utf8")); - // mempool.set(`${file}`.split(".")[0], { - // ...tx, - // txid: `${file}`.split(".")[0], - // }); + mempool.push(tx); } @@ -41,6 +35,11 @@ import * as path from "path"; fs.appendFileSync(outputFile, "\n"); fs.appendFileSync(outputFile, txSerializer(coinbaseTransaction).serializedTx); fs.appendFileSync(outputFile, "\n"); + fs.appendFileSync( + outputFile, + reversify(sha256(sha256(txSerializer(coinbaseTransaction).serializedTx))) + ); + fs.appendFileSync(outputFile, "\n"); for (const tx of txs) { fs.appendFileSync( outputFile, diff --git a/src/utils.ts b/src/utils.ts index f8693b1..bb1b2cf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -31,11 +31,4 @@ export const reversify = (str: string) => { .join(""); }; -// const asm = "OP_0 OP_PUSHBYTES_20 15ff0337937ecadd10ce56ffdfd4674817613223"; -// const hex = asmToHex(asm); -// console.log(hex); -// console.log( -// sha256( -// "201dda24da0b91e0eed9770878c504aeb07628ca4ccae9a7bd5347b96ee85dac52ac0063036f726401010a746578742f706c61696e00357b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a22646f6765222c22616d74223a2234323030227d68" -// ) -// ); +