From 3bdb071cc32f9501c990fd9eb57c27d663c3ac4e Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 27 Aug 2016 13:58:50 -0700 Subject: [PATCH] Remove #1144 from transaction.cpp by reverting back to commit 942bc46. --- src/primitives/transaction.cpp | 41 ++++++---------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 5c1f9475..1cedd6f2 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -120,6 +120,11 @@ CMutableTransaction::CMutableTransaction(const CTransaction& tx) : nVersion(tx.n } +uint256 CMutableTransaction::GetHash() const +{ + return SerializeHash(*this); +} + void CTransaction::UpdateHash() const { *const_cast(&hash) = SerializeHash(*this); @@ -131,7 +136,6 @@ CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion joinSplitPubKey(tx.joinSplitPubKey), joinSplitSig(tx.joinSplitSig) { UpdateHash(); - UpdateTxid(); } CTransaction& CTransaction::operator=(const CTransaction &tx) { @@ -143,7 +147,6 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) { *const_cast(&joinSplitPubKey) = tx.joinSplitPubKey; *const_cast(&joinSplitSig) = tx.joinSplitSig; *const_cast(&hash) = tx.hash; - *const_cast(&txid) = tx.txid; return *this; } @@ -212,9 +215,8 @@ unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const std::string CTransaction::ToString() const { std::string str; - str += strprintf("CTransaction(txid=%s, hash=%s, ver=%d, vin.size=%u, vout.size=%u, nLockTime=%u)\n", - txid.ToString().substr(0,10), - hash.ToString().substr(0,10), + str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%u, vout.size=%u, nLockTime=%u)\n", + GetHash().ToString().substr(0,10), nVersion, vin.size(), vout.size(), @@ -225,32 +227,3 @@ std::string CTransaction::ToString() const str += " " + vout[i].ToString() + "\n"; return str; } - -// Update the txid which is non-malleable. -// Signature data is cleared before the transaction is serialized and hashed. -void CTransaction::UpdateTxid() const -{ - // Create a deep copy of this transaction - CMutableTransaction tx(*this); - - // We keep the sigscript for coinbase txs to avoid duplicate txids (BIP34 and BIP30) - if (!IsCoinBase()) { - // Clear sigscript from all transaction inputs. - for (CTxIn & txIn : tx.vin) { - txIn.scriptSig.clear(); - } - - // Clear joinSplitSig by filling the buffer with zero - tx.joinSplitSig.assign(0); - } - - *const_cast(&txid) = SerializeHash(tx); -} - -// Return a txid which is non-malleable. -uint256 CMutableTransaction::GetTxid() const -{ - CTransaction tx(*this); - return tx.GetTxid(); -} -