]> Git Repo - VerusCoin.git/commitdiff
Add GetTxid() which returns a non-malleable txid.
authorSimon <[email protected]>
Fri, 22 Jul 2016 21:09:38 +0000 (14:09 -0700)
committerSimon <[email protected]>
Wed, 27 Jul 2016 00:09:27 +0000 (17:09 -0700)
src/primitives/transaction.cpp
src/primitives/transaction.h

index 102a1a33d0d3aa0df7c387bd7cc23bd3f6f5c8d9..510e0b5c5262d2d8715cc38106138051976fd051 100644 (file)
@@ -223,3 +223,31 @@ std::string CTransaction::ToString() const
         str += "    " + vout[i].ToString() + "\n";
     return str;
 }
+
+// Return a txid which is non-malleable.
+// Signature data is cleared before the transaction is serialized and hashed.
+uint256 CTransaction::GetTxid() const
+{
+    // Create a deep copy of this transaction
+    CMutableTransaction tx(*this);
+
+    // 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);
+
+    // Return double SHA256 hash
+    return tx.GetHash();
+}
+
+
+// Return a txid which is non-malleable.
+uint256 CMutableTransaction::GetTxid() const
+{
+    CTransaction tx(*this);
+    return tx.GetTxid();
+}
+
index a664159b06c98b06c473efb8f168d8abb0504900..0009fcf4445ea51c6b75354eef01d424f7512520 100644 (file)
@@ -373,6 +373,10 @@ public:
     }
 
     std::string ToString() const;
+
+    // Return the txid which is the double SHA256 hash of the transaction.
+    uint256 GetTxid() const;
+
 };
 
 /** A mutable version of CTransaction. */
@@ -411,6 +415,9 @@ struct CMutableTransaction
      * fly, as opposed to GetHash() in CTransaction, which uses a cached result.
      */
     uint256 GetHash() const;
+
+    // Compute a non-malleable txid on the fly.
+    uint256 GetTxid() const;
 };
 
 #endif // BITCOIN_PRIMITIVES_TRANSACTION_H
This page took 0.025549 seconds and 4 git commands to generate.