Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Hashing coinbase transaction to get txid
by
arch_stanton
on 21/09/2017, 07:57:40 UTC
⭐ Merited by ETFbitcoin (1)
I'm not able to get a txid from coinbase transactions, by hashing. I can get it from any other transaction by doing the double hash. Here's what I'm trying:
Code:
import hashlib

txid = 'd3104f6e12f47b9fef672820ed8721670b087aaa801591b43fa2210bf3887649'
txRaw = "0100000001c4efdc5025c9816bd6cc098b205ec7a5e5d91b398969e5350d4ce528310ea7a4000000006b483045022100a33944bd7354dd464b605d30f7f94f728f41c3dc58d434d918b4685e645b183e02200d37ec139c4d0de363ddd66bdb29ff19aac538644440dee950d03b935f1d3900012103eb38b8ea461b42ec464f738e890ab0c9ca909ef2e7df9599e5d939cb441e5390feffffff02b0ac1600000000001976a91492b00d72d4ef77d5710e71c415be831900e8739488acd0480a00000000001976a9149cadc280f1873709b80d005764e7a8741ee8d94788ac796b0700"
print('**')
print('Raw transaction:')
print(txRaw)
print('**')
data=txRaw.decode("hex")
hash = hashlib.sha256(hashlib.sha256(data).digest()).digest()
print('txid:')
print(txid)
print "Hashed Raw tx:\n", hash[::-1].encode('hex_codec')

Output when using a normal transaction:
Code:
**
Raw transaction:
0100000001c4efdc5025c9816bd6cc098b205ec7a5e5d91b398969e5350d4ce528310ea7a4000000006b483045022100a33944bd7354dd464b605d30f7f94f728f41c3dc58d434d918b4685e645b183e02200d37ec139c4d0de363ddd66bdb29ff19aac538644440dee950d03b935f1d3900012103eb38b8ea461b42ec464f738e890ab0c9ca909ef2e7df9599e5d939cb441e5390feffffff02b0ac1600000000001976a91492b00d72d4ef77d5710e71c415be831900e8739488acd0480a00000000001976a9149cadc280f1873709b80d005764e7a8741ee8d94788ac796b0700
**
txid:
d3104f6e12f47b9fef672820ed8721670b087aaa801591b43fa2210bf3887649
Hashed Raw tx:
d3104f6e12f47b9fef672820ed8721670b087aaa801591b43fa2210bf3887649

Output when using a coinbase transaction:
Code:
**
Raw transaction:
010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff3103816b07244d696e656420627920416e74506f6f6c6b2f4542312f4144362f4e59412f332059c36d7be1550000df320000ffffffff0238252e4d000000001976a914660371326d3a2e064c278b20107a65dad847e8a988ac0000000000000000266a24aa21a9edc11e8cdbd8d442b27bf8f273395baa83b5da4c9c3d87fbc539dad742480437100120000000000000000000000000000000000000000000000000000000000000000000000000
**
txid:
d0783f480343fb37b009b5e3db90ccad85e2c8314639de98b3bb66c396dd7915
Hashed Raw tx:
4495cc1d511e61de206cd5b18998eeab11932d42c6b1d264c400a20eefc97e99

I haven't been able to find any documentation about this. Does anybody know why this is?