Skip to content

Commit 76603b1

Browse files
committed
Select wallet based on the given endpoint
1 parent 32c9710 commit 76603b1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "consensus/validation.h"
1010
#include "core_io.h"
1111
#include "init.h"
12+
#include "httpserver.h"
1213
#include "validation.h"
1314
#include "net.h"
1415
#include "policy/feerate.h"
@@ -30,10 +31,21 @@
3031

3132
#include <univalue.h>
3233

34+
static const std::string WALLET_ENDPOINT_BASE = "/wallet/";
35+
3336
CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
3437
{
35-
// TODO: Some way to access secondary wallets
36-
return vpwallets.empty() ? nullptr : vpwallets[0];
38+
if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {
39+
// wallet endpoint was used
40+
std::string requestedWallet = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
41+
for (CWalletRef pwallet : ::vpwallets) {
42+
if (pwallet->GetName() == requestedWallet) {
43+
return pwallet;
44+
}
45+
}
46+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Requested wallet does not exist or is not loaded");
47+
}
48+
return ::vpwallets.size() == 1 || (request.fHelp && ::vpwallets.size() > 0) ? ::vpwallets[0] : nullptr;
3749
}
3850

3951
std::string HelpRequiringPassphrase(CWallet * const pwallet)

0 commit comments

Comments
 (0)