From 6b94f10940781915038a09889379cdeef6929802 Mon Sep 17 00:00:00 2001 From: Divyansh Gupta Date: Sat, 27 Apr 2024 21:05:23 +0530 Subject: [PATCH] fix: include merkle_root in natural order --- Block.py | 30 ++++++++++++++++++++++++++---- __pycache__/Block.cpython-311.pyc | Bin 6848 -> 6840 bytes output.txt | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Block.py b/Block.py index e272092f..26fda81b 100644 --- a/Block.py +++ b/Block.py @@ -32,8 +32,8 @@ def serialize_blockheader(self): result = int_to_little_endian(self.version, 4) # prev_block - 32 bytes, little endian result += self.prev_block[::-1] - # merkle_root - 32 bytes, little endian - result += self.merkle_root[::-1] + # merkle_root - 32 bytes, little endian -> require it in natural order in grader + result += self.merkle_root # timestamp - 4 bytes, little endian result += int_to_little_endian(self.timestamp, 4) # bits - 4 bytes @@ -90,7 +90,7 @@ def create_block(cls, tx_files): # we assume that the tx_files are in sorted in fee_rate version = 803823616 - timestamp = 1714064564 + timestamp = 1714214394 prev_block= "000000000000000000030ed9d2b8643c4c1d8519f34fbecaf150136e20ee183f" prev_block_in_bytes= bytes.fromhex(prev_block) @@ -151,10 +151,32 @@ def create_block(cls, tx_files): # now print the required block details in the output.txt # print the serliased block header - print(valid_block.serialize_blockheader()) + serliased= valid_block.serialize_blockheader() + print(serliased) + + + + + + + + # print("merkle root : \n {}".format(valid_block.merkle_root.hex())) + # print(serliased) + # serliased_in_bytes= bytes.fromhex(serliased) + + + # desired_slice = serliased_in_bytes[36:68].hex() + # print(desired_slice) + # print(desired_slice == valid_block.merkle_root.hex()) # print("{} {} {} {} {} {} ".format(valid_block.version,(valid_block.prev_block).hex(),(valid_block.merkle_root).hex(),valid_block.timestamp,(valid_block.bits).hex(),valid_block.nonce)) # print("block hash: {}".format(valid_block.hash())) + + + + + + # serliased coinbase transaction print(serliased_coinbase_tx) diff --git a/__pycache__/Block.cpython-311.pyc b/__pycache__/Block.cpython-311.pyc index 78a06c7aec6ae0bb4b023f3a531561adb3378d83..e60546ca6f12d143564f04446b475cd142236800 100644 GIT binary patch delta 319 zcmX?Ly2F%jIWI340}z#EM?4g8{v zj8c=2349UfEKV)T$xJLxO}WKdQW2k-QY-~jt}ywipey6{&D=r>jLIJb7=&c63mRP# zG`c8gaz)UjA@eR9cZcUiHnA&gVi(xNzM5?A6#mZ0cyM#0Xe%RQ++=p~XvT|^lf`ea zg#!&Miks{xF+nPUkyZQy1Bm>{%)lnt68(V*EEK>z`L)Dz#=OawCD+;eGc$^OV8Bj( O1dD&cAzLI4vvH2%k11lrf<|>{>CV>)ZkO2@-BeH;V@^Rz}9y$^XTo8Fx>P7Qew3 z1~jH9cCw|!1Su~@R`CxEAo3$K1Djw=^am!ePzuxJ#}dyOb0?pcTxVa=HC0Xz8- NEdB+DY>_z7Dgc0oUYGy? diff --git a/output.txt b/output.txt index a0a398bf..4e39940f 100644 --- a/output.txt +++ b/output.txt @@ -1,4 +1,4 @@ -0060e92f3f18ee206e1350f1cabe4ff319851d4c3c64b8d2d90e03000000000000000000d40eb0df1c5945f0059bfb300ab3d2f2064ad229f15aaac08d9f7c6896d0a395b48c2a66ffff001f627f0100 +0060e92f3f18ee206e1350f1cabe4ff319851d4c3c64b8d2d90e0300000000000000000095a3d096687c9f8dc0aa5af129d24a06f2d2b30a30fb9b05f045591cdfb00ed4fad52c66ffff001f974d0000 010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff11030cd3bf0c004f4345414e2e58595a002effffffff02e412bf13000000001976a9142c30a6aaac6d96687291475d7d52f4b469f665a688ac0000000000000000266a24aa21a9ed07528e9068d79f4fa737ce2b8cdea09f1b9c3c7a588948ff29e9d29d9a9cb2ef0120000000000000000000000000000000000000000000000000000000000000000000000000 dcd522b3588c7adb0418454539e1a929fff936f211e5a20383fdcbc3ad8751b9 423c61f1ec58b9400a373e1052c26debdd5d55eb0057900c3dcf41f54762486c