mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-15 12:19:46 +01:00
wallet: Replace CachedTxIsFromMe with CheckIsFromMeMap
Instead of looking at the cached amounts or searching every input of a transaction each time we want to determine whether it is "from me", use the m_from_me map which stores this value for us.
This commit is contained in:
parent
36f2c6a6bd
commit
ba24bf61cd
4 changed files with 16 additions and 9 deletions
|
@ -203,9 +203,14 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
|
|||
|
||||
}
|
||||
|
||||
bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter)
|
||||
bool CheckIsFromMeMap(const std::map<isminefilter, bool>& from_me_map, const isminefilter& filter)
|
||||
{
|
||||
return (CachedTxGetDebit(wallet, wtx, filter) > 0);
|
||||
for (const auto& [from_me_filter, from_me] : from_me_map) {
|
||||
if ((filter & from_me_filter) && from_me) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
|
@ -226,7 +231,7 @@ bool CachedTxIsTrusted(const CWallet& wallet, const TxState& state, const uint25
|
|||
assert(wtx);
|
||||
|
||||
// using wtx's cached debit
|
||||
if (!wallet.m_spend_zero_conf_change || !CachedTxIsFromMe(wallet, *wtx, ISMINE_ALL)) return false;
|
||||
if (!wallet.m_spend_zero_conf_change || !CheckIsFromMeMap(wtx->m_from_me, ISMINE_ALL)) return false;
|
||||
|
||||
// Trusted if all inputs are from us and are in the mempool:
|
||||
for (const CTxIn& txin : wtx->tx->vin)
|
||||
|
@ -317,7 +322,7 @@ std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet)
|
|||
if (wallet.IsTXOInImmatureCoinBase(txo)) continue;
|
||||
|
||||
int nDepth = wallet.GetTxStateDepthInMainChain(txo.GetState());
|
||||
if (nDepth < (CachedTxIsFromMe(wallet, txo.GetWalletTx(), ISMINE_ALL) ? 0 : 1)) continue;
|
||||
if (nDepth < (CheckIsFromMeMap(txo.GetWalletTx().m_from_me, ISMINE_ALL) ? 0 : 1)) continue;
|
||||
|
||||
CTxDestination addr;
|
||||
Assume(wallet.IsMine(txo.GetTxOut()));
|
||||
|
|
|
@ -40,12 +40,13 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
|
|||
std::list<COutputEntry>& listSent,
|
||||
CAmount& nFee, const isminefilter& filter,
|
||||
bool include_change);
|
||||
bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter);
|
||||
bool CachedTxIsTrusted(const CWallet& wallet, const TxState& state, const uint256& txid, std::set<uint256>& trusted_parents) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
||||
bool CachedTxIsTrusted(const CWallet& wallet, const TxState& state, const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
||||
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<uint256>& trusted_parents) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
||||
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx);
|
||||
|
||||
bool CheckIsFromMeMap(const std::map<isminefilter, bool>& from_me_map, const isminefilter& filter);
|
||||
|
||||
struct Balance {
|
||||
CAmount m_mine_trusted{0}; //!< Trusted, at depth=GetBalance.min_depth or more
|
||||
CAmount m_mine_untrusted_pending{0}; //!< Untrusted, but in mempool (pending)
|
||||
|
|
|
@ -330,7 +330,7 @@ static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nM
|
|||
|
||||
CachedTxGetAmounts(wallet, wtx, listReceived, listSent, nFee, filter_ismine, include_change);
|
||||
|
||||
bool involvesWatchonly = CachedTxIsFromMe(wallet, wtx, ISMINE_WATCH_ONLY);
|
||||
bool involvesWatchonly = CheckIsFromMeMap(wtx.m_from_me, ISMINE_WATCH_ONLY);
|
||||
|
||||
// Sent
|
||||
if (!filter_label.has_value())
|
||||
|
@ -779,10 +779,11 @@ RPCHelpMan gettransaction()
|
|||
CAmount nCredit = CachedTxGetCredit(*pwallet, wtx, filter);
|
||||
CAmount nDebit = CachedTxGetDebit(*pwallet, wtx, filter);
|
||||
CAmount nNet = nCredit - nDebit;
|
||||
CAmount nFee = (CachedTxIsFromMe(*pwallet, wtx, filter) ? wtx.tx->GetValueOut() - nDebit : 0);
|
||||
bool from_me = CheckIsFromMeMap(wtx.m_from_me, filter);
|
||||
CAmount nFee = (from_me ? wtx.tx->GetValueOut() - nDebit : 0);
|
||||
|
||||
entry.pushKV("amount", ValueFromAmount(nNet - nFee));
|
||||
if (CachedTxIsFromMe(*pwallet, wtx, filter))
|
||||
if (from_me)
|
||||
entry.pushKV("fee", ValueFromAmount(nFee));
|
||||
|
||||
WalletTxToJSON(*pwallet, wtx, entry);
|
||||
|
|
|
@ -415,7 +415,7 @@ CoinsResult AvailableCoins(const CWallet& wallet,
|
|||
continue;
|
||||
}
|
||||
|
||||
bool tx_from_me = CachedTxIsFromMe(wallet, wtx, ISMINE_ALL);
|
||||
bool tx_from_me = CheckIsFromMeMap(wtx.m_from_me, ISMINE_ALL);
|
||||
|
||||
std::unique_ptr<SigningProvider> provider = wallet.GetSolvingProvider(output.scriptPubKey);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue