mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-10 09:06:15 +01:00
wallet: don't iter twice when getting the cached debit/credit amount
Instead of calling GetCachableAmount twice, which will result in iterating through all the transaction txins/txouts and calling GetDebit/GetCredit (which lock cs_wallet), just merge the filters and do it once.
This commit is contained in:
parent
9fb2a2bc67
commit
757216e31c
1 changed files with 6 additions and 10 deletions
|
@ -130,12 +130,10 @@ CAmount CachedTxGetCredit(const CWallet& wallet, const CWalletTx& wtx, const ism
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
CAmount credit = 0;
|
CAmount credit = 0;
|
||||||
if (filter & ISMINE_SPENDABLE) {
|
const isminefilter get_amount_filter{filter & ISMINE_ALL};
|
||||||
|
if (get_amount_filter) {
|
||||||
// GetBalance can assume transactions in mapWallet won't change
|
// GetBalance can assume transactions in mapWallet won't change
|
||||||
credit += GetCachableAmount(wallet, wtx, CWalletTx::CREDIT, ISMINE_SPENDABLE);
|
credit += GetCachableAmount(wallet, wtx, CWalletTx::CREDIT, get_amount_filter);
|
||||||
}
|
|
||||||
if (filter & ISMINE_WATCH_ONLY) {
|
|
||||||
credit += GetCachableAmount(wallet, wtx, CWalletTx::CREDIT, ISMINE_WATCH_ONLY);
|
|
||||||
}
|
}
|
||||||
return credit;
|
return credit;
|
||||||
}
|
}
|
||||||
|
@ -146,11 +144,9 @@ CAmount CachedTxGetDebit(const CWallet& wallet, const CWalletTx& wtx, const ismi
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
CAmount debit = 0;
|
CAmount debit = 0;
|
||||||
if (filter & ISMINE_SPENDABLE) {
|
const isminefilter get_amount_filter{filter & ISMINE_ALL};
|
||||||
debit += GetCachableAmount(wallet, wtx, CWalletTx::DEBIT, ISMINE_SPENDABLE);
|
if (get_amount_filter) {
|
||||||
}
|
debit += GetCachableAmount(wallet, wtx, CWalletTx::DEBIT, get_amount_filter);
|
||||||
if (filter & ISMINE_WATCH_ONLY) {
|
|
||||||
debit += GetCachableAmount(wallet, wtx, CWalletTx::DEBIT, ISMINE_WATCH_ONLY);
|
|
||||||
}
|
}
|
||||||
return debit;
|
return debit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue