aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2022-07-18 10:35:26 +0100
committerfanquake <fanquake@gmail.com>2022-07-18 10:37:45 +0100
commitc5fa7ed409f31faed75b86cb0bb98bed151e07bd (patch)
tree2f4ec13b97885b2a7bc559d90e7c3c73ae59a87d /src
parent4e2929e987fc71c1df9d109210bd2527ccefca34 (diff)
parent757216e31cac7dcd45e11b2a2c6148420b3b99da (diff)
downloadbitcoin-c5fa7ed409f31faed75b86cb0bb98bed151e07bd.tar.xz
Merge bitcoin/bitcoin#25544: wallet: don't iter twice when getting the cached debit/credit amount
757216e31cac7dcd45e11b2a2c6148420b3b99da wallet: don't iter twice when getting the cached debit/credit amount (Antoine Poinsot) Pull request description: A small optimization i stumbled upon while looking at something else. Figured it could be worth a PR. 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. ACKs for top commit: achow101: ACK 757216e31cac7dcd45e11b2a2c6148420b3b99da aureleoules: ACK 757216e31cac7dcd45e11b2a2c6148420b3b99da. Tree-SHA512: 0dbbdd24231380196e929dce572752e6be1d69457252a7215e279e71d6199483b516f64019ae999a91dbce7fdd86f8bf0336b6e151cca93cbcf51bc854e838a2
Diffstat (limited to 'src')
-rw-r--r--src/wallet/receive.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/wallet/receive.cpp b/src/wallet/receive.cpp
index 8de4017371..d3303c0b1f 100644
--- a/src/wallet/receive.cpp
+++ b/src/wallet/receive.cpp
@@ -130,12 +130,10 @@ CAmount CachedTxGetCredit(const CWallet& wallet, const CWalletTx& wtx, const ism
return 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
- credit += GetCachableAmount(wallet, wtx, CWalletTx::CREDIT, ISMINE_SPENDABLE);
- }
- if (filter & ISMINE_WATCH_ONLY) {
- credit += GetCachableAmount(wallet, wtx, CWalletTx::CREDIT, ISMINE_WATCH_ONLY);
+ credit += GetCachableAmount(wallet, wtx, CWalletTx::CREDIT, get_amount_filter);
}
return credit;
}
@@ -146,11 +144,9 @@ CAmount CachedTxGetDebit(const CWallet& wallet, const CWalletTx& wtx, const ismi
return 0;
CAmount debit = 0;
- if (filter & ISMINE_SPENDABLE) {
- debit += GetCachableAmount(wallet, wtx, CWalletTx::DEBIT, ISMINE_SPENDABLE);
- }
- if (filter & ISMINE_WATCH_ONLY) {
- debit += GetCachableAmount(wallet, wtx, CWalletTx::DEBIT, ISMINE_WATCH_ONLY);
+ const isminefilter get_amount_filter{filter & ISMINE_ALL};
+ if (get_amount_filter) {
+ debit += GetCachableAmount(wallet, wtx, CWalletTx::DEBIT, get_amount_filter);
}
return debit;
}