MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetBalance

Function GetBalance

src/wallet/receive.cpp:357–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

355}
356
357Balance 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
386std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet)
387{

Callers 10

getBalancesMethod · 0.85
getBalanceMethod · 0.85
BOOST_FIXTURE_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
getbalanceFunction · 0.85
getunconfirmedbalanceFunction · 0.85
getbalancesFunction · 0.85
getwalletinfoFunction · 0.85
WalletBalanceFunction · 0.85

Calls 6

CachedTxIsTrustedFunction · 0.85
GetTxDepthInMainChainMethod · 0.80
InMempoolMethod · 0.80

Tested by 2

BOOST_FIXTURE_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68