Bitcoin Stack Alternate is a query and reply web site for Bitcoin customers, builders, and fanatics. It solely takes a minute to enroll.
Anyone can ask a query
Anyone can reply
One of the best solutions are voted up and rise to the highest
Requested
Seen
13 occasions
I downloaded the required data and made the coinbase. Then I calculated the merkle root… However I all the time get an error message after I submit a block: “bad-txnmerkleroot”. Tere is my code:
def dblsha(d)->bytes:
return hashlib.sha256(hashlib.sha256(d).digest()).digest()
def makeMerkleRoot()->None:
world merkleroot,txnlist
txnlist=[coinbase]+[unhexlify(a['data']) for a in tmpl['transactions']]
merklehashes=[dblsha(t)[::-1] for t in txnlist]
whereas len(merklehashes)>1:
if len(merklehashes)%2:
merklehashes.append(merklehashes[-1])
merklehashes=[dblsha(merklehashes[i]+merklehashes[i+1]) for i in vary(0,len(merklehashes),2)]
merkleroot=merklehashes[0][::-1]
- I reversed the information of all transactions(embody coinbase)
- I calculated the hashes(bytes)
- I calculated the merkleroot(bytes)
- I reversed the merkleroot
- I transformed the merkleroot(bytes) to hex
However all the time get an error: ‘bad-txnmerkleroot’, no matter whether or not I inverted it or not, or what number of occasions. Do I really want to reverse the information through the calculation? By the way in which, I examined the code in regtest. Ought to I take a look at the code on the primary community? Are there different causes for the ‘bad-txnmerkle’ error? Just like the improper coinbase. I am actually at my wits’ finish.
Jack Inexperienced is a brand new contributor to this web site. Take care in asking for clarification, commenting, and answering.
Try our Code of Conduct.
1