Skip to content

Commit 9508761

Browse files
committed
[wallet] [rpc] Add listwallets RPC
This commit adds a listwallets RPC, which lists the names of the currently loaded wallets. This command intentionally shows no information about the wallet other then the name. Information on individual wallets can be obtained using the getwalletinfo RPC.
1 parent 4a05715 commit 9508761

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,6 +2491,39 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
24912491
return obj;
24922492
}
24932493

2494+
UniValue listwallets(const JSONRPCRequest& request)
2495+
{
2496+
if (request.fHelp || request.params.size() != 0)
2497+
throw std::runtime_error(
2498+
"listwallets\n"
2499+
"Returns a list of currently loaded wallets.\n"
2500+
"For full information on the wallet, use \"getwalletinfo\"\n"
2501+
"\nResult:\n"
2502+
"[ (json array of strings)\n"
2503+
" \"walletname\" (string) the wallet name\n"
2504+
" ...\n"
2505+
"]\n"
2506+
"\nExamples:\n"
2507+
+ HelpExampleCli("listwallets", "")
2508+
+ HelpExampleRpc("listwallets", "")
2509+
);
2510+
2511+
UniValue obj(UniValue::VARR);
2512+
2513+
for (CWalletRef pwallet : vpwallets) {
2514+
2515+
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2516+
return NullUniValue;
2517+
}
2518+
2519+
LOCK(pwallet->cs_wallet);
2520+
2521+
obj.push_back(pwallet->GetName());
2522+
}
2523+
2524+
return obj;
2525+
}
2526+
24942527
UniValue resendwallettransactions(const JSONRPCRequest& request)
24952528
{
24962529
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
@@ -3087,6 +3120,7 @@ static const CRPCCommand commands[] =
30873120
{ "wallet", "listsinceblock", &listsinceblock, false, {"blockhash","target_confirmations","include_watchonly"} },
30883121
{ "wallet", "listtransactions", &listtransactions, false, {"account","count","skip","include_watchonly"} },
30893122
{ "wallet", "listunspent", &listunspent, false, {"minconf","maxconf","addresses","include_unsafe","query_options"} },
3123+
{ "wallet", "listwallets", &listwallets, true, {} },
30903124
{ "wallet", "lockunspent", &lockunspent, true, {"unlock","transactions"} },
30913125
{ "wallet", "move", &movecmd, false, {"fromaccount","toaccount","amount","minconf","comment"} },
30923126
{ "wallet", "sendfrom", &sendfrom, false, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} },

0 commit comments

Comments
 (0)