diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8481d4eec..969399a2e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -917,18 +917,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD wtx.nIndex = wtxIn.nIndex; fUpdated = true; } - if (!wtxIn.mapNoteData.empty() && wtxIn.mapNoteData != wtx.mapNoteData) - { - auto tmp = wtxIn.mapNoteData; - // Ensure we keep any cached witnesses we may already have - for (const std::pair nd : wtx.mapNoteData) { - if (tmp.count(nd.first) && nd.second.witnesses.size() > 0) { - tmp.at(nd.first).witnesses.assign( - nd.second.witnesses.cbegin(), nd.second.witnesses.cend()); - } - } - // Now copy over the updated note data - wtx.mapNoteData = tmp; + if (UpdatedNoteData(wtxIn, wtx)) { fUpdated = true; } if (wtxIn.fFromMe && wtxIn.fFromMe != wtx.fFromMe) @@ -965,6 +954,24 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD return true; } +bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx) +{ + if (wtxIn.mapNoteData.empty() || wtxIn.mapNoteData == wtx.mapNoteData) { + return false; + } + auto tmp = wtxIn.mapNoteData; + // Ensure we keep any cached witnesses we may already have + for (const std::pair nd : wtx.mapNoteData) { + if (tmp.count(nd.first) && nd.second.witnesses.size() > 0) { + tmp.at(nd.first).witnesses.assign( + nd.second.witnesses.cbegin(), nd.second.witnesses.cend()); + } + } + // Now copy over the updated note data + wtx.mapNoteData = tmp; + return true; +} + /** * Add a transaction to the wallet, or update it. * pblock is optional, but should be provided if the transaction is known to be in a block. @@ -1005,6 +1012,11 @@ void CWallet::SyncTransaction(const CTransaction& tx, const CBlock* pblock) if (!AddToWalletIfInvolvingMe(tx, pblock, true)) return; // Not one of ours + MarkAffectedTransactionsDirty(tx); +} + +void CWallet::MarkAffectedTransactionsDirty(const CTransaction& tx) +{ // If a transaction changes 'conflicted' state, that changes the balance // available of the outputs it spends. So force those to be // recomputed, also: diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index b736e6906..bd65287dd 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -599,6 +599,10 @@ private: template void SyncMetaData(std::pair::iterator, typename TxSpendMap::iterator>); +protected: + bool UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx); + void MarkAffectedTransactionsDirty(const CTransaction& tx); + public: /* * Main wallet lock.