| 355 | } |
| 356 | |
| 357 | Balance GetBalance(const CWallet& wallet, const int min_depth, bool avoid_reuse) |
| 358 | { |
| 359 | Balance ret; |
| 360 | isminefilter reuse_filter = avoid_reuse ? ISMINE_NO : ISMINE_USED; |
| 361 | { |
| 362 | LOCK(wallet.cs_wallet); |
| 363 | std::set<uint256> trusted_parents; |
| 364 | for (const auto& entry : wallet.mapWallet) |
| 365 | { |
| 366 | const CWalletTx& wtx = entry.second; |
| 367 | const bool is_trusted{CachedTxIsTrusted(wallet, wtx, trusted_parents)}; |
| 368 | const int tx_depth{wallet.GetTxDepthInMainChain(wtx)}; |
| 369 | const CAmountMap tx_credit_mine{CachedTxGetAvailableCredit(wallet, wtx, /* fUseCache */ true, ISMINE_SPENDABLE | reuse_filter)}; |
| 370 | const CAmountMap tx_credit_watchonly{CachedTxGetAvailableCredit(wallet, wtx, /* fUseCache */ true, ISMINE_WATCH_ONLY | reuse_filter)}; |
| 371 | if (is_trusted && tx_depth >= min_depth) { |
| 372 | ret.m_mine_trusted += tx_credit_mine; |
| 373 | ret.m_watchonly_trusted += tx_credit_watchonly; |
| 374 | } |
| 375 | if (!is_trusted && tx_depth == 0 && wtx.InMempool()) { |
| 376 | ret.m_mine_untrusted_pending += tx_credit_mine; |
| 377 | ret.m_watchonly_untrusted_pending += tx_credit_watchonly; |
| 378 | } |
| 379 | ret.m_mine_immature += CachedTxGetImmatureCredit(wallet, wtx); |
| 380 | ret.m_watchonly_immature += CachedTxGetImmatureWatchOnlyCredit(wallet, wtx); |
| 381 | } |
| 382 | } |
| 383 | return ret; |
| 384 | } |
| 385 | |
| 386 | std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet) |
| 387 | { |