Skip to content

Commit 113a422

Browse files
committed
wallet: Add m_cached_from_me to cache "from me" status
m_cached_from_me is used to track whether a transaction is "from me", i.e. has any inputs which belong to the wallet. This is held in memory only in the same way that a transaction's balances are.
1 parent 609d265 commit 113a422

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/wallet/receive.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
195195

196196
bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx)
197197
{
198-
return (CachedTxGetDebit(wallet, wtx, /*avoid_reuse=*/false) > 0);
198+
if (!wtx.m_cached_from_me.has_value()) {
199+
wtx.m_cached_from_me = wallet.IsFromMe(*wtx.tx);
200+
}
201+
return wtx.m_cached_from_me.value();
199202
}
200203

201204
// NOLINTNEXTLINE(misc-no-recursion)

src/wallet/transaction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ class CWalletTx
232232
* CWallet::ComputeTimeSmart().
233233
*/
234234
unsigned int nTimeSmart;
235+
// Cached value for whether the transaction spends any inputs known to the wallet
236+
mutable std::optional<bool> m_cached_from_me{std::nullopt};
235237
int64_t nOrderPos; //!< position in ordered transaction list
236238
std::multimap<int64_t, CWalletTx*>::const_iterator m_it_wtxOrdered;
237239

@@ -339,6 +341,7 @@ class CWalletTx
339341
m_amounts[CREDIT].Reset();
340342
fChangeCached = false;
341343
m_is_cache_empty = true;
344+
m_cached_from_me = std::nullopt;
342345
}
343346

344347
/** True if only scriptSigs are different */

0 commit comments

Comments
 (0)