[wallet] [tests] Add listwallets RPC, include wallet name in `getwalletinfo` and add multiwallet test #10604
Merged
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4a05715
[wallet] [rpc] print wallet name in getwalletinfo
jnewbery 09eacee
[wallet] fix comment for CWallet::Verify()
jnewbery 9508761
[wallet] [rpc] Add listwallets RPC
jnewbery 3707fcd
[wallet] [tests] Add listwallets to multiwallet test
jnewbery
Jump to file or symbol
Failed to load files and symbols.
| @@ -2447,6 +2447,7 @@ UniValue getwalletinfo(const JSONRPCRequest& request) | ||
| "Returns an object containing various wallet state info.\n" | ||
| "\nResult:\n" | ||
| "{\n" | ||
| + " \"walletname\": xxxxx, (string) the wallet name\n" | ||
| " \"walletversion\": xxxxx, (numeric) the wallet version\n" | ||
| " \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n" | ||
| " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n" | ||
| @@ -2469,6 +2470,7 @@ UniValue getwalletinfo(const JSONRPCRequest& request) | ||
| UniValue obj(UniValue::VOBJ); | ||
| size_t kpExternalSize = pwallet->KeypoolCountExternalKeys(); | ||
| + obj.push_back(Pair("walletname", pwallet->GetName())); | ||
| obj.push_back(Pair("walletversion", pwallet->GetVersion())); | ||
| obj.push_back(Pair("balance", ValueFromAmount(pwallet->GetBalance()))); | ||
| obj.push_back(Pair("unconfirmed_balance", ValueFromAmount(pwallet->GetUnconfirmedBalance()))); | ||
| @@ -2489,6 +2491,39 @@ UniValue getwalletinfo(const JSONRPCRequest& request) | ||
| return obj; | ||
| } | ||
| +UniValue listwallets(const JSONRPCRequest& request) | ||
| +{ | ||
| + if (request.fHelp || request.params.size() != 0) | ||
| + throw std::runtime_error( | ||
| + "listwallets\n" | ||
| + "Returns a list of currently loaded wallets.\n" | ||
| + "For full information on the wallet, use \"getwalletinfo\"\n" | ||
| + "\nResult:\n" | ||
| + "[ (json array of strings)\n" | ||
| + " \"walletname\" (string) the wallet name\n" | ||
| + " ...\n" | ||
| + "]\n" | ||
| + "\nExamples:\n" | ||
| + + HelpExampleCli("listwallets", "") | ||
| + + HelpExampleRpc("listwallets", "") | ||
| + ); | ||
| + | ||
| + UniValue obj(UniValue::VARR); | ||
| + | ||
| + for (CWalletRef pwallet : vpwallets) { | ||
| + | ||
jnewbery
Member
|
||
| + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||
| + return NullUniValue; | ||
| + } | ||
| + | ||
| + LOCK(pwallet->cs_wallet); | ||
| + | ||
| + obj.push_back(pwallet->GetName()); | ||
| + } | ||
| + | ||
| + return obj; | ||
| +} | ||
| + | ||
| UniValue resendwallettransactions(const JSONRPCRequest& request) | ||
| { | ||
| CWallet * const pwallet = GetWalletForJSONRPCRequest(request); | ||
| @@ -3085,6 +3120,7 @@ static const CRPCCommand commands[] = | ||
| { "wallet", "listsinceblock", &listsinceblock, false, {"blockhash","target_confirmations","include_watchonly"} }, | ||
| { "wallet", "listtransactions", &listtransactions, false, {"account","count","skip","include_watchonly"} }, | ||
| { "wallet", "listunspent", &listunspent, false, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, | ||
| + { "wallet", "listwallets", &listwallets, true, {} }, | ||
| { "wallet", "lockunspent", &lockunspent, true, {"unlock","transactions"} }, | ||
| { "wallet", "move", &movecmd, false, {"fromaccount","toaccount","amount","minconf","comment"} }, | ||
| { "wallet", "sendfrom", &sendfrom, false, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} }, | ||
nit newline