Browse Source

Add wallet endpoint support to bitcoin-cli (-usewallet)

tags/v0.15.1
Jonas Schnelli 4 years ago
parent
commit
31e07203bd
No account linked to committer's email address
3 changed files with 28 additions and 1 deletions
  1. 15
    1
      src/bitcoin-cli.cpp
  2. 11
    0
      src/httpserver.cpp
  3. 2
    0
      src/httpserver.h

+ 15
- 1
src/bitcoin-cli.cpp View File

@@ -46,6 +46,7 @@ std::string HelpMessageCli()
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout in seconds during HTTP requests, or 0 for no timeout. (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
strUsage += HelpMessageOpt("-stdin", _("Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases)"));
strUsage += HelpMessageOpt("-usewallet=<walletname>", _("Send RPC for non-default wallet on RPC server (argument is wallet filename in bitcoind directory, required if bitcoind/-Qt runs with multiple wallets)"));

return strUsage;
}
@@ -241,7 +242,20 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)
assert(output_buffer);
evbuffer_add(output_buffer, strRequest.data(), strRequest.size());

int r = evhttp_make_request(evcon.get(), req.get(), EVHTTP_REQ_POST, "/");
// check if we should use a special wallet endpoint
std::string endpoint = "/";
std::string walletName = GetArg("-usewallet", "");
if (!walletName.empty()) {
char *encodedURI = evhttp_uriencode(walletName.c_str(), walletName.size(), false);
if (encodedURI) {
endpoint = "/wallet/"+ std::string(encodedURI);
free(encodedURI);
}
else {
throw CConnectionFailed("uri-encode failed");
}
}
int r = evhttp_make_request(evcon.get(), req.get(), EVHTTP_REQ_POST, endpoint.c_str());
req.release(); // ownership moved to evcon in above call
if (r != 0) {
throw CConnectionFailed("send http request failed");

+ 11
- 0
src/httpserver.cpp View File

@@ -666,3 +666,14 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
}
}

std::string urlDecode(const std::string &urlEncoded) {
std::string res;
if (!urlEncoded.empty()) {
char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, NULL);
if (decoded) {
res = std::string(decoded);
free(decoded);
}
}
return res;
}

+ 2
- 0
src/httpserver.h View File

@@ -148,4 +148,6 @@ private:
struct event* ev;
};

std::string urlDecode(const std::string &urlEncoded);

#endif // BITCOIN_HTTPSERVER_H

Loading…
Cancel
Save