aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Harding <tomh@thinlink.com>2015-03-11 16:48:53 -0700
committerTom Harding <tomh@thinlink.com>2015-04-11 19:03:58 -0700
commitb2b361926215eadd6bf43ed1d7110b925fc7cae5 (patch)
tree82db9091d3556b309368bbe63806602ef26cfe87
parentc8a13501196fc79a3f728683b74f9d586dda46c1 (diff)
downloadbitcoin-b2b361926215eadd6bf43ed1d7110b925fc7cae5.tar.xz
Implement CTransaction::IsEquivalentTo(...)
Define CTransaction::IsEquivalentTo(const CTransaction& tx) True if only scriptSigs are different. In other words, true if the two transactions are malleability clones. In other words, true if the two transactions have the same effect on the outside universe. In the wallet, only SyncMetaData for equivalent transactions.
-rw-r--r--src/primitives/transaction.cpp9
-rw-r--r--src/primitives/transaction.h3
-rw-r--r--src/wallet/wallet.cpp1
3 files changed, 13 insertions, 0 deletions
diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp
index 606dbea798..d864a9b6d3 100644
--- a/src/primitives/transaction.cpp
+++ b/src/primitives/transaction.cpp
@@ -87,6 +87,15 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
return *this;
}
+bool CTransaction::IsEquivalentTo(const CTransaction& tx) const
+{
+ CMutableTransaction tx1 = *this;
+ CMutableTransaction tx2 = tx;
+ for (unsigned int i = 0; i < tx1.vin.size(); i++) tx1.vin[i].scriptSig = CScript();
+ for (unsigned int i = 0; i < tx2.vin.size(); i++) tx2.vin[i].scriptSig = CScript();
+ return CTransaction(tx1) == CTransaction(tx2);
+}
+
CAmount CTransaction::GetValueOut() const
{
CAmount nValueOut = 0;
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h
index 6cfd93a9a1..0c9ebb7b88 100644
--- a/src/primitives/transaction.h
+++ b/src/primitives/transaction.h
@@ -222,6 +222,9 @@ public:
return hash;
}
+ // True if only scriptSigs are different
+ bool IsEquivalentTo(const CTransaction& tx) const;
+
// Return sum of txouts.
CAmount GetValueOut() const;
// GetValueIn() is a method on CCoinsViewCache, because
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 2566b2712b..92bb972cf3 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -417,6 +417,7 @@ void CWallet::SyncMetaData(pair<TxSpends::iterator, TxSpends::iterator> range)
const uint256& hash = it->second;
CWalletTx* copyTo = &mapWallet[hash];
if (copyFrom == copyTo) continue;
+ if (!copyFrom->IsEquivalentTo(*copyTo)) continue;
copyTo->mapValue = copyFrom->mapValue;
copyTo->vOrderForm = copyFrom->vOrderForm;
// fTimeReceivedIsTxTime not copied on purpose