diff --git a/src/wallet/receive.cpp b/src/wallet/receive.cpp index df3fbc0877d..13a25b36326 100644 --- a/src/wallet/receive.cpp +++ b/src/wallet/receive.cpp @@ -195,7 +195,10 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx, bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx) { - return (CachedTxGetDebit(wallet, wtx, /*avoid_reuse=*/false) > 0); + if (!wtx.m_cached_from_me.has_value()) { + wtx.m_cached_from_me = wallet.IsFromMe(*wtx.tx); + } + return wtx.m_cached_from_me.value(); } // NOLINTNEXTLINE(misc-no-recursion) diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h index bc6f0ef8450..1dbcdd2d921 100644 --- a/src/wallet/transaction.h +++ b/src/wallet/transaction.h @@ -232,6 +232,8 @@ public: * CWallet::ComputeTimeSmart(). */ unsigned int nTimeSmart; + // Cached value for whether the transaction spends any inputs known to the wallet + mutable std::optional m_cached_from_me{std::nullopt}; int64_t nOrderPos; //!< position in ordered transaction list std::multimap::const_iterator m_it_wtxOrdered; @@ -339,6 +341,7 @@ public: m_amounts[CREDIT].Reset(); fChangeCached = false; m_is_cache_empty = true; + m_cached_from_me = std::nullopt; } /** True if only scriptSigs are different */