Skip to content

Commit

Permalink
📈 Coinbase Txid to Output.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishu0 committed May 7, 2024
1 parent 3cecdec commit e49c9f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/features/block/mine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
}

Expand All @@ -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,
Expand Down
9 changes: 1 addition & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
// )
// );

0 comments on commit e49c9f7

Please sign in to comment.