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

Function GetWalletBalances

src/bitcoin-cli.cpp:903–919  ·  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

901 * @param result Reference to UniValue object the wallet names and balances are pushed to.
902 */
903static void GetWalletBalances(UniValue& result)
904{
905 DefaultRequestHandler rh;
906 const UniValue listwallets = ConnectAndCallRPC(&rh, "listwallets", /* args=*/{});
907 if (!find_value(listwallets, "error").isNull()) return;
908 const UniValue& wallets = find_value(listwallets, "result");
909 if (wallets.size() <= 1) return;
910
911 UniValue balances(UniValue::VOBJ);
912 for (const UniValue& wallet : wallets.getValues()) {
913 const std::string wallet_name = wallet.get_str();
914 const UniValue getbalances = ConnectAndCallRPC(&rh, "getbalances", /* args=*/{}, wallet_name);
915 const UniValue& balance = find_value(getbalances, "result")["mine"]["trusted"];
916 balances.pushKV(wallet_name, balance);
917 }
918 result.pushKV("balances", balances);
919}
920
921/**
922 * GetProgressBar constructs a progress bar with 5% intervals.

Callers 1

CommandLineRPCFunction · 0.85

Calls 4

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

Tested by

no test coverage detected