Skip to content

Commit

Permalink
[wallet] [rpc] Add listwallets RPC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jnewbery authored and random-zebra committed Jun 2, 2021
1 parent 1525281 commit 4fd5913
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4081,6 +4081,37 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
return obj;
}

UniValue listwallets(const JSONRPCRequest& request)
{
if (request.fHelp || !request.params.empty())
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) {
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue;
}

LOCK(pwallet->cs_wallet);
obj.push_back(pwallet->GetName());
}

return obj;
}

UniValue getstakingstatus(const JSONRPCRequest& request)
{
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
Expand Down Expand Up @@ -4515,6 +4546,7 @@ static const CRPCCommand commands[] =
{ "wallet", "listsinceblock", &listsinceblock, false, {"blockhash","target_confirmations","include_watchonly"} },
{ "wallet", "listtransactions", &listtransactions, false, {"dummy","count","from","include_watchonly","include_delegated","include_cold"} },
{ "wallet", "listunspent", &listunspent, false, {"minconf","maxconf","addresses","watchonly_config","query_options","include_unsafe" } },
{ "wallet", "listwallets", &listwallets, true, {} },
{ "wallet", "lockunspent", &lockunspent, true, {"unlock","transactions"} },
{ "wallet", "rawdelegatestake", &rawdelegatestake, false, {"staking_addr","amount","owner_addr","ext_owner","include_delegated","from_shield","force"} },
{ "wallet", "sendmany", &sendmany, false, {"dummy","amounts","minconf","comment","include_delegated"} },
Expand Down

0 comments on commit 4fd5913

Please sign in to comment.