@@ -452,6 +452,30 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
452
452
return response;
453
453
}
454
454
455
+ /* *
456
+ * GetWalletBalances calls listwallets; if more than one wallet is loaded, it then
457
+ * fetches mine.trusted balances for each loaded wallet and pushes them to `result`.
458
+ *
459
+ * @param result Reference to UniValue object the wallet names and balances are pushed to.
460
+ */
461
+ static void GetWalletBalances (UniValue& result)
462
+ {
463
+ std::unique_ptr<BaseRequestHandler> rh{MakeUnique<DefaultRequestHandler>()};
464
+ const UniValue listwallets = ConnectAndCallRPC (rh.get (), " listwallets" , /* args=*/ {});
465
+ if (!find_value (listwallets, " error" ).isNull ()) return ;
466
+ const UniValue& wallets = find_value (listwallets, " result" );
467
+ if (wallets.size () <= 1 ) return ;
468
+
469
+ UniValue balances (UniValue::VOBJ);
470
+ for (const UniValue& wallet : wallets.getValues ()) {
471
+ const std::string wallet_name = wallet.get_str ();
472
+ const UniValue getbalances = ConnectAndCallRPC (rh.get (), " getbalances" , /* args=*/ {}, wallet_name);
473
+ const UniValue& balance = find_value (getbalances, " result" )[" mine" ][" trusted" ];
474
+ balances.pushKV (wallet_name, balance);
475
+ }
476
+ result.pushKV (" balances" , balances);
477
+ }
478
+
455
479
static int CommandLineRPC (int argc, char *argv[])
456
480
{
457
481
std::string strPrint;
0 commit comments