Skip to content

Commit

Permalink
Select wallet based on the given endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli authored and random-zebra committed Jun 2, 2021
1 parent 5683a9c commit a64440b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "core_io.h"
#include "destination_io.h"
#include "init.h"
#include "httpserver.h"
#include "key_io.h"
#include "masternode-sync.h"
#include "net.h"
Expand All @@ -33,11 +34,21 @@
#include <univalue.h>


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

CWallet* GetWalletForJSONRPCRequest(const JSONRPCRequest& request)
{
// TODO: Some way to access secondary wallets
return vpwallets.empty() ? nullptr : vpwallets[0];
if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == WALLET_ENDPOINT_BASE) {
// wallet endpoint was used
std::string requestedWallet = urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size()));
for (CWalletRef pwallet : ::vpwallets) {
if (pwallet->GetName() == requestedWallet) {
return pwallet;
}
}
throw JSONRPCError(RPC_INVALID_PARAMETER, "Requested wallet does not exist or is not loaded");
}
return ::vpwallets.size() == 1 || (request.fHelp && ::vpwallets.size() > 0) ? ::vpwallets[0] : nullptr;
}

std::string HelpRequiringPassphrase(CWallet* const pwallet)
Expand Down

0 comments on commit a64440b

Please sign in to comment.