Browse Source

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

0.15
Jonas Schnelli 8 years ago
parent
commit
31e07203bd
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D
  1. 16
      src/bitcoin-cli.cpp
  2. 11
      src/httpserver.cpp
  3. 2
      src/httpserver.h

16
src/bitcoin-cli.cpp

@ -46,6 +46,7 @@ std::string HelpMessageCli() @@ -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) @@ -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
src/httpserver.cpp

@ -666,3 +666,14 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch) @@ -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
src/httpserver.h

@ -148,4 +148,6 @@ private: @@ -148,4 +148,6 @@ private:
struct event* ev;
};
std::string urlDecode(const std::string &urlEncoded);
#endif // BITCOIN_HTTPSERVER_H

Loading…
Cancel
Save