Browse Source

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.
0.13
Tom Harding 10 years ago
parent
commit
b2b3619262
  1. 9
      src/primitives/transaction.cpp
  2. 3
      src/primitives/transaction.h
  3. 1
      src/wallet/wallet.cpp

9
src/primitives/transaction.cpp

@ -87,6 +87,15 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) { @@ -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;

3
src/primitives/transaction.h

@ -222,6 +222,9 @@ public: @@ -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

1
src/wallet/wallet.cpp

@ -417,6 +417,7 @@ void CWallet::SyncMetaData(pair<TxSpends::iterator, TxSpends::iterator> range) @@ -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

Loading…
Cancel
Save