MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetWalletBalances

Function GetWalletBalances

src/bitcoin-cli.cpp:1360–1376  ·  view source on GitHub ↗

* GetWalletBalances calls listwallets; if more than one wallet is loaded, it then * fetches mine.trusted balances for each loaded wallet and pushes them to `result`. * * @param result Reference to UniValue object the wallet names and balances are pushed to. */

Source from the content-addressed store, hash-verified

1358 * @param result Reference to UniValue object the wallet names and balances are pushed to.
1359 */
1360static void GetWalletBalances(UniValue& result)
1361{
1362 DefaultRequestHandler rh;
1363 const UniValue listwallets = ConnectAndCallRPC(&rh, "listwallets", /* args=*/{});
1364 if (!listwallets.find_value("error").isNull()) return;
1365 const UniValue& wallets = listwallets.find_value("result");
1366 if (wallets.size() <= 1) return;
1367
1368 UniValue balances(UniValue::VOBJ);
1369 for (const UniValue& wallet : wallets.getValues()) {
1370 const std::string& wallet_name = wallet.get_str();
1371 const UniValue getbalances = ConnectAndCallRPC(&rh, "getbalances", /* args=*/{}, wallet_name);
1372 const UniValue& balance = getbalances.find_value("result")["mine"]["trusted"];
1373 balances.pushKV(wallet_name, balance);
1374 }
1375 result.pushKV("balances", std::move(balances));
1376}
1377
1378/**
1379 * GetProgressBar constructs a progress bar with 5% intervals.

Callers 1

CommandLineRPCFunction · 0.85

Calls 4

ConnectAndCallRPCFunction · 0.85
isNullMethod · 0.80
pushKVMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected