Title: How is the hash of a transaction calculated? (Move to dev discussion please?) Post by: Martin P. Hellwig on June 12, 2011, 12:27:33 PM Hi all,
I was wondering how the hash was calculated of a transaction, so I can replicate it in my python code. I have read up on: https://en.bitcoin.it/wiki/Protocol_specification#tx and https://en.bitcoin.it/wiki/Dump_format But I think I am missing something. For example the block http://blockexplorer.com/b/130264 hash a transaction with hash "230cf0853ffdd82e99fbf1eef37cc3e97de310812d9e2a3ba79fe1ffa9518109" How is this hash calculated with the given context? ---cut--- Code: { Thanks for any suggestions, Martin Title: Re: How is the hash of a transaction calculated? (Move to dev discussion please?) Post by: theymos on June 12, 2011, 12:59:30 PM You need to put that data into the binary format before hashing it.
Title: Re: How is the hash of a transaction calculated? (Move to dev discussion please?) Post by: Martin P. Hellwig on June 12, 2011, 02:09:08 PM Ah Cool thanks,
One thing I noticed is that https://en.bitcoin.it/wiki/Protocol_specification#tx says that both [tx_in count, tx_out count] are a byte or more size. But is that actually true? As far as I can see the parser does not know in advance what size that count field is. Is the spec wrong in saying this field is variable size and should be one byte and as such a transaction can have a maximum of 256 inputs and outputs? Title: Re: How is the hash of a transaction calculated? (Move to dev discussion please?) Post by: joan on June 12, 2011, 03:58:36 PM Ah Cool thanks, They are variable integers, check the page you linked further up.One thing I noticed is that https://en.bitcoin.it/wiki/Protocol_specification#tx says that both [tx_in count, tx_out count] are a byte or more size. But is that actually true? As far as I can see the parser does not know in advance what size that count field is. Is the spec wrong in saying this field is variable size and should be one byte and as such a transaction can have a maximum of 256 inputs and outputs? If the byte value is 252 or less (which is almost always the case for tx_in_count and tx_out_count), it's coded on one byte only and the count is the byte value. If it's 253, the count is coded on the next 2 bytes, etc. Title: Re: How is the hash of a transaction calculated? (Move to dev discussion please?) Post by: Martin P. Hellwig on June 12, 2011, 04:42:24 PM Ah yes, under common structures, variable length integers. Thanks for the pointer!
|