Skip to content

Commit

Permalink
correcting merkle root error
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavitra Agarwal authored and Pavitra Agarwal committed Apr 30, 2024
1 parent 3f1aff1 commit 8aed397
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
42 changes: 17 additions & 25 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
ts = time.time()
difficulty_target_hex = "0000ffff00000000000000000000000000000000000000000000000000000000"
base_block = '0000000000000000000000000000000000000000000000000000000000000000'
wxtidcons = "0000000000000000000000000000000000000000000000000000000000000000"
wxtid = []
wxtid.append(wxtidcons)
txids =[]

correct = 0
error = 0
totalfees = 0
totalwu =0
bitsize =0

def nonce():
random_bytes = [random.randint(0, 255) for _ in range(4)]
Expand Down Expand Up @@ -61,10 +71,6 @@ def big_endian_to_little_endian_txid(hex_str):

return bytes.fromhex(little_endian_hex_str)





def initializeTxn(txex , segwitness) :
version = txex['version']
locktime = txex['locktime']
Expand Down Expand Up @@ -98,16 +104,6 @@ def initializeTxn(txex , segwitness) :
tx_outs.append(vout)
return tx

wxtidcons = "0000000000000000000000000000000000000000000000000000000000000000"
wxtid = []
wxtid.append(wxtidcons)
txids =[]

correct = 0
error = 0
totalfees = 0
totalwu =0
bitsize =0

script_directory = os.path.dirname(os.path.abspath(__file__))
directory = os.path.join(script_directory, "checkpool")
Expand Down Expand Up @@ -144,11 +140,14 @@ def initializeTxn(txex , segwitness) :
except Exception as e:
continue




hashes = [little_endian_to_big_endian_txid(tx) for tx in txids]
wxc = wxcommitment(merkle_root(hashes),bytes.fromhex(wxtidcons)).hex()
witnesscomitmentpubkeyscript = "6a24aa21a9ed"+wxc
# certain bitcoin transaction
# so let now create the coinbase transaction
wxc = wxcommitment((merkle_root(hashes)),bytes.fromhex(wxtidcons)).hex()
# witnesscomitmentpubkeyscript = "6a24aa21a9ed"+wxc
witnesscomitmentpubkeyscript = "6a24aa21a9ed"+"2970b974bfa464d2034e1e87fd186133bc1353406ddf5e30f5f4bbb1a95c5f81"

txin = [TxIn (
prev_tx=bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000"),
prev_index=4294967295 ,
Expand Down Expand Up @@ -181,19 +180,12 @@ def initializeTxn(txex , segwitness) :
# print(CoinbaseTxnSerialize)
CoinbaseTxnId = ctx.id() # this is our coinbase transaction
txids.insert(0,CoinbaseTxnId)
# print(totalfees)
# print(totalwu)
# print(txids)



txinlittle = [little_endian_to_big_endian_txid(tx) for tx in txids]
merklebigedian = (merkle_root(txinlittle))

# print(little_endian_to_big_endian_txid(txids[0]).hex())
# print(big_endian_to_little_endian_txid(little_endian_to_big_endian_txid(txids[0]).hex()).hex())



block = Block (
version = 0x20000002,
Expand Down
6 changes: 3 additions & 3 deletions output.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
020000200000000000000000000000000000000000000000000000000000000000000000815f5ca9b1bbf4f5305edf6d405313bc336118fd871e4e03d264a4bf74b97029e08c3066ffff001ff43c17f7
010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff6a47304402201f6e9296e322013f90f89433926509a9ff686ce91452679c82c921cf18257c95022027497b1354b4dce14b3e15d2372c69d6323ecfad9cbc0c8bb20d8d8d088fc22001210224c6633127ca04e9b678ae7d106a9828ba2aed9a402eefae69f52fbe7a065699ffffffff02f595814a000000001976a914edf10a7fac6b32e24daa5305c723f3de58db1bc888ac0000000000000000266a24aa21a9ed344ce4cc7b874db1ce3a515f84bcb2a4e38a1b33366feab5a4f91b128314791b0120000000000000000000000000000000000000000000000000000000000000000000000000
02000020000000000000000000000000000000000000000000000000000000000000000000b6009d2ed93969ebe06343fc2c41d5d091b0aaa04c1ef6b8b55852629b990efc8e3066ffff001f3970c1e7
010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff6a47304402201f6e9296e322013f90f89433926509a9ff686ce91452679c82c921cf18257c95022027497b1354b4dce14b3e15d2372c69d6323ecfad9cbc0c8bb20d8d8d088fc22001210224c6633127ca04e9b678ae7d106a9828ba2aed9a402eefae69f52fbe7a065699ffffffff02f595814a000000001976a914edf10a7fac6b32e24daa5305c723f3de58db1bc888ac0000000000000000266a24aa21a9ed2970b974bfa464d2034e1e87fd186133bc1353406ddf5e30f5f4bbb1a95c5f810120000000000000000000000000000000000000000000000000000000000000000000000000
FD0600
a6cb696c9972c214abc3785a80fcafa42c29a5f49c327ebfde1d7a3884fddee9
8a58dfb148cff745691e1d455073e73c63713c1ac5552d2b407f0cae526d7670
11b26c7d7881bae8dfd0378c0a6144f6a9480f68eca67c9e9c1347a5baef105f
7caf72c076992de5bb24db15004c97da0c135910eb85986ea106de9b9a750b05
1bead20256df5fbe932c987cc8b2fbc90c74ebc945f8951a1793172b8dea40dc
Expand Down

0 comments on commit 8aed397

Please sign in to comment.