Based on what I read, there is this script to build the Merkle root
import hashlib
def dblsha(data):
return hashlib.sha256(hashlib.sha256(data).digest()).digest()
txnlist = [coinbase] + [binascii.a2b_hex(a['data']) for a in template['transactions']]
merklehashes = [dblsha(t) for t in txnlist]
while len(merklehashes) > 1:
if len(merklehashes) % 2:
merklehashes.append(merklehashes[-1])
merklehashes = [dblsha(merklehashes[i] + merklehashes[i + 1]) for i in range(0, len(merklehashes), 2)]
merkleroot = merklehashes[0]
I wanted to mine an empty block (a block with only a coinbase transaction in it) , can I modify the script so that txnlist
only includes coinbase and ignore the other transactions? or it is considered a hard fork?
txnlist = [coinbase]
Or this isn't the correct way to mine empty block?
I currently only have a shallow understanding of Bitcoin, that's why I ask.