Skip to content

Commit

Permalink
wallet: get the balances in getbalances RPC from GetFullBalance(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonOdiwuor committed Dec 17, 2023
1 parent 1a7cb64 commit 6a0272b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/wallet/rpc/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,15 @@ RPCHelpMan getbalances()

LOCK(wallet.cs_wallet);

const auto bal = GetBalance(wallet);
const auto bal = GetFullBalance(wallet);
UniValue balances{UniValue::VOBJ};
{
UniValue balances_mine{UniValue::VOBJ};
balances_mine.pushKV("trusted", ValueFromAmount(bal.m_mine_trusted));
balances_mine.pushKV("untrusted_pending", ValueFromAmount(bal.m_mine_untrusted_pending));
balances_mine.pushKV("immature", ValueFromAmount(bal.m_mine_immature));
if (wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) {
// If the AVOID_REUSE flag is set, bal has been set to just the un-reused address balance. Get
// the total balance, and then subtract bal to get the reused address balance.
const auto full_bal = GetBalance(wallet, 0, false);
balances_mine.pushKV("used", ValueFromAmount(full_bal.m_mine_trusted + full_bal.m_mine_untrusted_pending - bal.m_mine_trusted - bal.m_mine_untrusted_pending));
balances_mine.pushKV("used", ValueFromAmount(bal.m_mine_used));
}
balances.pushKV("mine", balances_mine);
}
Expand Down

0 comments on commit 6a0272b

Please sign in to comment.