Skip to content

Commit 537efe1

Browse files
committed
rpc: Extract GetWalletNameFromJSONRPCRequest from GetWalletForJSONRPCRequest
1 parent e4082d5 commit 537efe1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,21 @@
4040

4141
static const std::string WALLET_ENDPOINT_BASE = "/wallet/";
4242

43-
std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
43+
bool GetWalletNameFromJSONRPCRequest(const JSONRPCRequest& request, std::string& wallet_name)
4444
{
4545
if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {
4646
// wallet endpoint was used
47-
std::string requestedWallet = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
48-
std::shared_ptr<CWallet> pwallet = GetWallet(requestedWallet);
47+
wallet_name = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
48+
return true;
49+
}
50+
return false;
51+
}
52+
53+
std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
54+
{
55+
std::string wallet_name;
56+
if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) {
57+
std::shared_ptr<CWallet> pwallet = GetWallet(wallet_name);
4958
if (!pwallet) throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded");
5059
return pwallet;
5160
}

0 commit comments

Comments
 (0)