Skip to content

Commit 93449a4

Browse files
committed
Refactored further
1 parent 51cfe16 commit 93449a4

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

examples/create_and_mine_block.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111
import hashlib
1212

1313

14-
def calculate_wtxid(tx_hex):
15-
# note: normal transaction id's do not include the witness data
16-
# unlike witness transaction id's which include the witness data
17-
tx_binary = bytes.fromhex(tx_hex)
18-
hash_once = hashlib.sha256(tx_binary).digest()
19-
hash_twice = hashlib.sha256(hash_once).digest()
20-
return hash_twice[::-1].hex()
21-
22-
2314
def calculate_merkle_root(txid_list):
2415
"""
2516
Calculates merkel root by hashing pairwise txids till only 1 is left.
@@ -268,7 +259,7 @@ def main():
268259
witness_stack = [witness_reserved_value]
269260

270261
# wtxid is different from txid
271-
wtxid = calculate_wtxid(tx_details["hex"])
262+
wtxid = tx1.get_wtxid();
272263
print("Wtx id :", wtxid)
273264

274265
# Coinbase wtxid must be set to all zeros to avoid circular reference
@@ -291,7 +282,7 @@ def main():
291282
# 1-byte - Push the following 36 bytes (0x24)
292283
# 4-byte - Commitment header (0xaa21a9ed)
293284
# 32-byte - Commitment hash: Double-SHA256(witness root hash|witness reserved value)
294-
commitment = "6a24aa21a9ed" + witness_commitment_hash
285+
commitment = "6a24"+ "aa21a9ed" + witness_commitment_hash
295286

296287
print("Witness Commitment :", commitment)
297288
# note: to_addr defined at the top. Taken from the first transaction
@@ -304,8 +295,9 @@ def main():
304295

305296
# The commitment script is described above
306297
# and is added to the second output of the coinbase transaction
307-
witness_commitment_script = Script([])
308-
witness_commitment_script = witness_commitment_script.from_raw(commitment)
298+
witness_commitment_script = Script(["OP_RETURN", "aa21a9ed"+witness_commitment_hash]);
299+
300+
print("1 : ", witness_commitment_script);
309301
print("witness commitment script : ", witness_commitment_script)
310302
txout2 = TxOutput(to_satoshis(0), witness_commitment_script)
311303
coinbase_tx = Transaction(

0 commit comments

Comments
 (0)