Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-cli.cpp
Show First 20 Lines • Show All 564 Lines • ▼ Show 20 Lines | do { | ||||
} else { | } else { | ||||
throw; | throw; | ||||
} | } | ||||
} | } | ||||
} while (fWait); | } while (fWait); | ||||
return response; | return response; | ||||
} | } | ||||
/** | |||||
* 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. | |||||
*/ | |||||
[[maybe_unused]] static void GetWalletBalances(UniValue &result) { | |||||
std::unique_ptr<BaseRequestHandler> rh{ | |||||
std::make_unique<DefaultRequestHandler>()}; | |||||
const UniValue listwallets = | |||||
ConnectAndCallRPC(rh.get(), "listwallets", /* args=*/{}); | |||||
if (!find_value(listwallets, "error").isNull()) { | |||||
return; | |||||
} | |||||
const UniValue &wallets = find_value(listwallets, "result"); | |||||
if (wallets.size() <= 1) { | |||||
return; | |||||
} | |||||
UniValue balances(UniValue::VOBJ); | |||||
for (const UniValue &wallet : wallets.getValues()) { | |||||
const std::string wallet_name = wallet.get_str(); | |||||
const UniValue getbalances = ConnectAndCallRPC( | |||||
rh.get(), "getbalances", /* args=*/{}, wallet_name); | |||||
const UniValue &balance = | |||||
find_value(getbalances, "result")["mine"]["trusted"]; | |||||
balances.pushKV(wallet_name, balance); | |||||
} | |||||
result.pushKV("balances", balances); | |||||
} | |||||
static int CommandLineRPC(int argc, char *argv[]) { | static int CommandLineRPC(int argc, char *argv[]) { | ||||
std::string strPrint; | std::string strPrint; | ||||
int nRet = 0; | int nRet = 0; | ||||
try { | try { | ||||
// Skip switches | // Skip switches | ||||
while (argc > 1 && IsSwitchChar(argv[1][0])) { | while (argc > 1 && IsSwitchChar(argv[1][0])) { | ||||
argc--; | argc--; | ||||
argv++; | argv++; | ||||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |