From 405b1ec5ca5d04482fb20df86c560e73476759d9 Mon Sep 17 00:00:00 2001 From: David Burkett Date: Tue, 12 Apr 2022 17:47:46 -0400 Subject: [PATCH] More accurate filtering of transactions not belonging to wallet --- src/wallet/txlist.cpp | 28 +++++++++++++++++++++++++++- src/wallet/txlist.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/wallet/txlist.cpp b/src/wallet/txlist.cpp index 773fa3602..e255cbd31 100644 --- a/src/wallet/txlist.cpp +++ b/src/wallet/txlist.cpp @@ -62,7 +62,7 @@ void TxList::List(std::vector& tx_records, const CWalletTx& wtx, CAmount nDebit = wtx.GetDebit(filter_ismine); CAmount nNet = nCredit - nDebit; - if (nCredit == 0 && nDebit == 0) { + if (!IsMine(wtx)) { return; } @@ -304,4 +304,30 @@ bool TxList::IsAllToMe(const CWalletTx& wtx) } return true; +} + +// A few release candidates of v0.21.2 added some transactions to the wallet that didn't actually belong to it. +// This is a temporary band-aid to filter out these transactions from the list. +// We can consider removing it after testing, since only a limited number of testnet wallets should've been impacted. +bool TxList::IsMine(const CWalletTx& wtx) +{ + for (const CTxInput& input : wtx.GetInputs()) { + if (m_wallet.IsMine(input)) { + return true; + } + } + + for (const CTxOutput& output : wtx.GetOutputs()) { + if (m_wallet.IsMine(output)) { + return true; + } + } + + for (const PegOutCoin& pegout : wtx.tx->mweb_tx.GetPegOuts()) { + if (m_wallet.IsMine(DestinationAddr{pegout.GetScriptPubKey()})) { + return true; + } + } + + return false; } \ No newline at end of file diff --git a/src/wallet/txlist.h b/src/wallet/txlist.h index d98c862b4..df6c5fa0d 100644 --- a/src/wallet/txlist.h +++ b/src/wallet/txlist.h @@ -37,4 +37,5 @@ private: DestinationAddr GetAddress(const CTxOutput& output); bool IsAllFromMe(const CWalletTx& wtx); bool IsAllToMe(const CWalletTx& wtx); + bool IsMine(const CWalletTx& wtx); }; \ No newline at end of file