user323: How does one calculate the hash of a Tx? Which fields need to be double SHA hashed and in what order?

user84235: Here's a python implementation to find the doubleSHA256 hash for genesis block:
01000000010000000000000000000000000000000000000000000000000000000000000000FFFFFFFF4D04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73FFFFFFFF0100F2052A01000000434104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC00000000

import codecs

//switch the endianness of a given string
def revEndian(string):
    return ''.join(reversed([string[i:i+2] for i in range(0, len(string), 2)]))

//convert a bytebuffer into a string
def hashStr(bytebuffer):
    return str(codecs.encode(bytebuffer, 'hex'))[2:-1]

//find the double sha256 hash for a given hex string
def doubleSha256(hex): 
    bin = codecs.decode(hex, 'hex')
    hash = hashlib.sha256(bin).digest()
    hash2 = hashlib.sha256(hash).digest()
    return revEndian(hashStr(hash2))


user323: As explained by Gavin Andersen on the forum - in order to calculate the ID hash of the Tx that is used in the Merkle Tree, one needs to SHA hash the whole Tx message as defined in the Protocol Specification wiki page twice.
For example, for the only Tx from the Genesis Block one would double hash the following array of bytes:
01000000010000000000000000000000000000000000000000000000000000000000000000FFFFFFFF4D04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73FFFFFFFF0100F2052A01000000434104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC00000000
And if double hashed correctly, it would give the following hash:
4A5E1E4BAAB89F3A32518A88C31BC87F618F76673E2CC77AB2127B7AFDEDA33B

323: <p>How does one calculate the hash of a Tx? Which fields need to be double SHA hashed and in what order?</p>
 84235: <p>Here's a python implementation to find the doubleSHA256 hash for genesis block:</p>

<pre><code>01000000010000000000000000000000000000000000000000000000000000000000000000FFFFFFFF4D04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73FFFFFFFF0100F2052A01000000434104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC00000000

import codecs

//switch the endianness of a given string
def revEndian(string):
    return ''.join(reversed([string[i:i+2] for i in range(0, len(string), 2)]))

//convert a bytebuffer into a string
def hashStr(bytebuffer):
    return str(codecs.encode(bytebuffer, 'hex'))[2:-1]

//find the double sha256 hash for a given hex string
def doubleSha256(hex): 
    bin = codecs.decode(hex, 'hex')
    hash = hashlib.sha256(bin).digest()
    hash2 = hashlib.sha256(hash).digest()
    return revEndian(hashStr(hash2))
</code></pre>
 323: <p>As explained by <a href="https://bitcointalk.org/index.php?topic=54451.msg649253#msg649253" rel="noreferrer">Gavin Andersen on the forum</a> - in order to calculate the ID hash of the Tx that is used in the Merkle Tree, one needs to SHA hash <a href="https://en.bitcoin.it/wiki/Protocol_specification#tx" rel="noreferrer">the whole Tx message</a> as defined in <a href="https://en.bitcoin.it/wiki/Protocol_specification#tx" rel="noreferrer">the Protocol Specification wiki page</a> twice.</p>

<p>For example, for the only Tx from the <a href="http://blockexplorer.com/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" rel="noreferrer">Genesis Block</a> one would double hash the following array of bytes:</p>

<p>01000000010000000000000000000000000000000000000000000000000000000000000000FFFFFFFF4D04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73FFFFFFFF0100F2052A01000000434104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC00000000</p>

<p>And if double hashed correctly, it would give the following hash:</p>

<p><a href="http://blockexplorer.com/tx/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b" rel="noreferrer">4A5E1E4BAAB89F3A32518A88C31BC87F618F76673E2CC77AB2127B7AFDEDA33B</a></p>
