diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -13,15 +13,24 @@ static const int SERIALIZE_TRANSACTION = 0x00; +/** A TxHash is the double sha256 hash of the full transaction data */ +struct TxHash : public uint256 { + + TxHash() {} + + // TODO: make this explicit once the full refactoring txid->txhash is done + TxHash(const uint256 &b) : uint256(b) {} +}; + /** An outpoint - a combination of a transaction hash and an index n into its * vout */ class COutPoint { public: - uint256 hash; + TxHash hash; uint32_t n; COutPoint() { SetNull(); } - COutPoint(uint256 hashIn, uint32_t nIn) { + COutPoint(TxHash hashIn, uint32_t nIn) { hash = hashIn; n = nIn; } @@ -97,7 +106,7 @@ explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn = CScript(), uint32_t nSequenceIn = SEQUENCE_FINAL); - CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn = CScript(), + CTxIn(TxHash hashPrevTx, uint32_t nOut, CScript scriptSigIn = CScript(), uint32_t nSequenceIn = SEQUENCE_FINAL); ADD_SERIALIZE_METHODS; @@ -238,9 +247,9 @@ private: /** Memory only. */ - const uint256 hash; + const TxHash hash; - uint256 ComputeHash() const; + TxHash ComputeHash() const; public: /** Construct a CTransaction that qualifies as IsNull() */ @@ -263,10 +272,10 @@ bool IsNull() const { return vin.empty() && vout.empty(); } - const uint256 &GetId() const { return hash; } + const TxHash &GetId() const { return hash; } // Compute a hash that includes both transaction and witness data - uint256 GetHash() const; + TxHash GetHash() const; // Return sum of txouts. Amount GetValueOut() const; @@ -328,7 +337,7 @@ /** Compute the hash of this CMutableTransaction. This is computed on the * fly, as opposed to GetId() in CTransaction, which uses a cached result. */ - uint256 GetId() const; + TxHash GetId() const; friend bool operator==(const CMutableTransaction &a, const CMutableTransaction &b) { diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -19,7 +19,7 @@ nSequence = nSequenceIn; } -CTxIn::CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn, +CTxIn::CTxIn(TxHash hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nSequenceIn) { prevout = COutPoint(hashPrevTx, nOut); scriptSig = scriptSigIn; @@ -58,15 +58,15 @@ : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {} -uint256 CMutableTransaction::GetId() const { +TxHash CMutableTransaction::GetId() const { return SerializeHash(*this, SER_GETHASH, 0); } -uint256 CTransaction::ComputeHash() const { +TxHash CTransaction::ComputeHash() const { return SerializeHash(*this, SER_GETHASH, 0); } -uint256 CTransaction::GetHash() const { +TxHash CTransaction::GetHash() const { return GetId(); }