From 21c29a389a883bf815423a488d7962bdd46032ea Mon Sep 17 00:00:00 2001 From: Pavitra Agarwal Date: Mon, 29 Apr 2024 19:07:05 +0530 Subject: [PATCH] merkle root --- __pycache__/block.cpython-312.pyc | Bin 2016 -> 2059 bytes block.py | 4 ++-- main.py | 2 +- output.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__pycache__/block.cpython-312.pyc b/__pycache__/block.cpython-312.pyc index 101b708036f814c0e4c16371edbe2b423fb784fa..059f00ec2ec21452ac1b2b6b6e3c9a248ea48d63 100644 GIT binary patch delta 134 zcmaFB-z~s8D9<$$yy5c@~;12wGrr zQApz=hsI_zmTE?z_$JnH&J+e9WNc-YoXo~HkI`rHQZ`*}s9JuF4weV}!V^lai>qG* dB7XG?9O^$maWV)Q7qbE_?B{o6nEaXTEdYV*DR%$> delta 79 zcmeAcc)-tlnwOW00SL}5)KBBx$Xmn2$S}E!sdzFc^FPMM$s8=^%ojP7HhZ&FGcwjq iKF%6GS&MBpqx0lrY`T;Gut~AA0JZk>TTPZ@e+vM1trl_s diff --git a/block.py b/block.py index 87e9aa7..007a3b8 100644 --- a/block.py +++ b/block.py @@ -14,7 +14,7 @@ def __init__(self, version, prev_block, merkle_root, def serialize(self): result = int_to_little_endian(self.version, 4) result += self.prev_block[::-1] - result += self.merkle_root + result += self.merkle_root[::-1] result += int_to_little_endian(self.timestamp, 4) result += self.bits[::-1] result += self.nonce[::-1] @@ -34,6 +34,6 @@ def validate_merkle_root(self): hashes = [h[::-1] for h in self.tx_hashes] # compute the Merkle Root and reverse - root = merkle_root(hashes) + root = merkle_root(hashes)[::-1] # return whether self.merkle_root is the same return root == self.merkle_root \ No newline at end of file diff --git a/main.py b/main.py index 3d77f22..d8b24d6 100644 --- a/main.py +++ b/main.py @@ -162,7 +162,7 @@ def hash2561(data): block = Block ( version = 0x20000002 , prev_block= bytes.fromhex(base_block), - merkle_root= merkle_root(txides), + merkle_root= merkle_root(txides)[::-1], timestamp= int(ts), bits=bytes.fromhex('1f00ffff') , nonce= bytes.fromhex(nonce()) , #nonce()) , #nonce should be of the bytes diff --git a/output.txt b/output.txt index 6b7cf56..50a8f19 100644 --- a/output.txt +++ b/output.txt @@ -1,4 +1,4 @@ -020000200000000000000000000000000000000000000000000000000000000000000000e016e1851957a9a69e138c34bf5c67fdf83581514903d012886f1c3d9d0c54aacfa12f66ffff001f09deb1c9 +020000200000000000000000000000000000000000000000000000000000000000000000e016e1851957a9a69e138c34bf5c67fdf83581514903d012886f1c3d9d0c54aa60a22f66ffff001f06f16696 010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff6a47304402201f6e9296e322013f90f89433926509a9ff686ce91452679c82c921cf18257c95022027497b1354b4dce14b3e15d2372c69d6323ecfad9cbc0c8bb20d8d8d088fc22001210224c6633127ca04e9b678ae7d106a9828ba2aed9a402eefae69f52fbe7a065699ffffffff02f595814a000000001976a914edf10a7fac6b32e24daa5305c723f3de58db1bc888ac0000000000000000266a24aa21a9ed0743cafb2ad89219798f1b2651467d2f6256998e493800f2560784f5f1bcd4670120000000000000000000000000000000000000000000000000000000000000000000000000 FD0600 49a6af777488f947e2b6e2e0ab87f56f44cbfe8280c4dfd9c7c5d9c1b1291f10