Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-cli.cpp
Show First 20 Lines • Show All 924 Lines • ▼ Show 20 Lines | |||||
* GetWalletBalances calls listwallets; if more than one wallet is loaded, it | * GetWalletBalances calls listwallets; if more than one wallet is loaded, it | ||||
* then fetches mine.trusted balances for each loaded wallet and pushes them to | * then fetches mine.trusted balances for each loaded wallet and pushes them to | ||||
* `result`. | * `result`. | ||||
* | * | ||||
* @param result Reference to UniValue object the wallet names and balances are | * @param result Reference to UniValue object the wallet names and balances are | ||||
* pushed to. | * pushed to. | ||||
*/ | */ | ||||
static void GetWalletBalances(UniValue &result) { | static void GetWalletBalances(UniValue &result) { | ||||
std::unique_ptr<BaseRequestHandler> rh{ | DefaultRequestHandler rh; | ||||
std::make_unique<DefaultRequestHandler>()}; | |||||
const UniValue listwallets = | const UniValue listwallets = | ||||
ConnectAndCallRPC(rh.get(), "listwallets", /* args=*/{}); | ConnectAndCallRPC(&rh, "listwallets", /* args=*/{}); | ||||
if (!find_value(listwallets, "error").isNull()) { | if (!find_value(listwallets, "error").isNull()) { | ||||
return; | return; | ||||
} | } | ||||
const UniValue &wallets = find_value(listwallets, "result"); | const UniValue &wallets = find_value(listwallets, "result"); | ||||
if (wallets.size() <= 1) { | if (wallets.size() <= 1) { | ||||
return; | return; | ||||
} | } | ||||
UniValue balances(UniValue::VOBJ); | UniValue balances(UniValue::VOBJ); | ||||
for (const UniValue &wallet : wallets.getValues()) { | for (const UniValue &wallet : wallets.getValues()) { | ||||
const std::string wallet_name = wallet.get_str(); | const std::string wallet_name = wallet.get_str(); | ||||
const UniValue getbalances = ConnectAndCallRPC( | const UniValue getbalances = | ||||
rh.get(), "getbalances", /* args=*/{}, wallet_name); | ConnectAndCallRPC(&rh, "getbalances", /* args=*/{}, wallet_name); | ||||
const UniValue &balance = | const UniValue &balance = | ||||
find_value(getbalances, "result")["mine"]["trusted"]; | find_value(getbalances, "result")["mine"]["trusted"]; | ||||
balances.pushKV(wallet_name, balance); | balances.pushKV(wallet_name, balance); | ||||
} | } | ||||
result.pushKV("balances", balances); | result.pushKV("balances", balances); | ||||
} | } | ||||
/** | /** | ||||
* Call RPC getnewaddress. | * Call RPC getnewaddress. | ||||
* @returns getnewaddress response as a UniValue object. | * @returns getnewaddress response as a UniValue object. | ||||
*/ | */ | ||||
static UniValue GetNewAddress() { | static UniValue GetNewAddress() { | ||||
std::optional<std::string> wallet_name{}; | std::optional<std::string> wallet_name{}; | ||||
if (gArgs.IsArgSet("-rpcwallet")) { | if (gArgs.IsArgSet("-rpcwallet")) { | ||||
wallet_name = gArgs.GetArg("-rpcwallet", ""); | wallet_name = gArgs.GetArg("-rpcwallet", ""); | ||||
} | } | ||||
std::unique_ptr<BaseRequestHandler> rh{ | DefaultRequestHandler rh; | ||||
std::make_unique<DefaultRequestHandler>()}; | return ConnectAndCallRPC(&rh, "getnewaddress", /* args=*/{}, wallet_name); | ||||
return ConnectAndCallRPC(rh.get(), "getnewaddress", /* args=*/{}, | |||||
wallet_name); | |||||
} | } | ||||
/** | /** | ||||
* Check bounds and set up args for RPC generatetoaddress params: nblocks, | * Check bounds and set up args for RPC generatetoaddress params: nblocks, | ||||
* address, maxtries. | * address, maxtries. | ||||
* @param[in] address Reference to const string address to insert into the | * @param[in] address Reference to const string address to insert into the | ||||
* args. | * args. | ||||
* @param args Reference to vector of string args to modify. | * @param args Reference to vector of string args to modify. | ||||
▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines |