Raven Core  3.0.0
P2P Digital Currency
raven-cli.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #if defined(HAVE_CONFIG_H)
8 #include "config/raven-config.h"
9 #endif
10 
11 #include "chainparamsbase.h"
12 #include "clientversion.h"
13 #include "fs.h"
14 #include "rpc/client.h"
15 #include "rpc/protocol.h"
16 #include "util.h"
17 #include "utilstrencodings.h"
18 
19 #include <stdio.h>
20 
21 #include <event2/buffer.h>
22 #include <event2/keyvalq_struct.h>
23 #include "support/events.h"
24 
25 #include <univalue.h>
26 
27 static const char DEFAULT_RPCCONNECT[] = "127.0.0.1";
28 static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
29 static const bool DEFAULT_NAMED=false;
30 static const int CONTINUE_EXECUTION=-1;
31 
32 std::string HelpMessageCli()
33 {
34  const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
35  const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
36  std::string strUsage;
37  strUsage += HelpMessageGroup(_("Options:"));
38  strUsage += HelpMessageOpt("-?", _("This help message"));
39  strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), RAVEN_CONF_FILENAME));
40  strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
41  strUsage += HelpMessageOpt("-getinfo", _("Get general information from the remote server. Note that unlike server-side RPC calls, the results of -getinfo is the result of multiple non-atomic requests. Some entries in the result may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)"));
42  AppendParamsHelpMessages(strUsage);
43  strUsage += HelpMessageOpt("-named", strprintf(_("Pass named instead of positional arguments (default: %s)"), DEFAULT_NAMED));
44  strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT));
45  strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()));
46  strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
47  strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
48  strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
49  strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout in seconds during HTTP requests, or 0 for no timeout. (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
50  strUsage += HelpMessageOpt("-stdinrpcpass", strprintf(_("Read RPC password from standard input as a single line. When combined with -stdin, the first line from standard input is used for the RPC password.")));
51  strUsage += HelpMessageOpt("-stdin", _("Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases). When combined with -stdinrpcpass, the first line from standard input is used for the RPC password."));
52  strUsage += HelpMessageOpt("-rpcwallet=<walletname>", _("Send RPC for non-default wallet on RPC server (argument is wallet filename in ravend directory, required if ravend/-Qt runs with multiple wallets)"));
53 
54  return strUsage;
55 }
56 
58 //
59 // Start
60 //
61 
62 //
63 // Exception thrown on connection error. This error is used to determine
64 // when to wait if -rpcwait is given.
65 //
66 class CConnectionFailed : public std::runtime_error
67 {
68 public:
69 
70  explicit inline CConnectionFailed(const std::string& msg) :
71  std::runtime_error(msg)
72  {}
73 
74 };
75 
76 //
77 // This function returns either one of EXIT_ codes when it's expected to stop the process or
78 // CONTINUE_EXECUTION when it's expected to continue further.
79 //
80 static int AppInitRPC(int argc, char* argv[])
81 {
82  //
83  // Parameters
84  //
85  gArgs.ParseParameters(argc, argv);
86  if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) {
87  std::string strUsage = strprintf(_("%s RPC client version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n";
88  if (!gArgs.IsArgSet("-version")) {
89  strUsage += "\n" + _("Usage:") + "\n" +
90  " raven-cli [options] <command> [params] " + strprintf(_("Send command to %s"), _(PACKAGE_NAME)) + "\n" +
91  " raven-cli [options] -named <command> [name=value] ... " + strprintf(_("Send command to %s (with named arguments)"), _(PACKAGE_NAME)) + "\n" +
92  " raven-cli [options] help " + _("List commands") + "\n" +
93  " raven-cli [options] help <command> " + _("Get help for a command") + "\n";
94 
95  strUsage += "\n" + HelpMessageCli();
96  }
97 
98  fprintf(stdout, "%s", strUsage.c_str());
99  if (argc < 2) {
100  fprintf(stderr, "Error: too few parameters\n");
101  return EXIT_FAILURE;
102  }
103  return EXIT_SUCCESS;
104  }
105  if (!fs::is_directory(GetDataDir(false))) {
106  fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
107  return EXIT_FAILURE;
108  }
109  try {
111  } catch (const std::exception& e) {
112  fprintf(stderr,"Error reading configuration file: %s\n", e.what());
113  return EXIT_FAILURE;
114  }
115  // Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
116  try {
118  } catch (const std::exception& e) {
119  fprintf(stderr, "Error: %s\n", e.what());
120  return EXIT_FAILURE;
121  }
122  if (gArgs.GetBoolArg("-rpcssl", false))
123  {
124  fprintf(stderr, "Error: SSL mode for RPC (-rpcssl) is no longer supported.\n");
125  return EXIT_FAILURE;
126  }
127  return CONTINUE_EXECUTION;
128 }
129 
130 
132 struct HTTPReply
133 {
134  HTTPReply(): status(0), error(-1) {}
135 
136  int status;
137  int error;
138  std::string body;
139 };
140 
141 const char *http_errorstring(int code)
142 {
143  switch(code) {
144 #if LIBEVENT_VERSION_NUMBER >= 0x02010300
145  case EVREQ_HTTP_TIMEOUT:
146  return "timeout reached";
147  case EVREQ_HTTP_EOF:
148  return "EOF reached";
149  case EVREQ_HTTP_INVALID_HEADER:
150  return "error while reading header, or invalid header";
151  case EVREQ_HTTP_BUFFER_ERROR:
152  return "error encountered while reading or writing";
153  case EVREQ_HTTP_REQUEST_CANCEL:
154  return "request was canceled";
155  case EVREQ_HTTP_DATA_TOO_LONG:
156  return "response body is larger than allowed";
157 #endif
158  default:
159  return "unknown";
160  }
161 }
162 
163 static void http_request_done(struct evhttp_request *req, void *ctx)
164 {
165  HTTPReply *reply = static_cast<HTTPReply*>(ctx);
166 
167  if (req == nullptr) {
168  /* If req is nullptr, it means an error occurred while connecting: the
169  * error code will have been passed to http_error_cb.
170  */
171  reply->status = 0;
172  return;
173  }
174 
175  reply->status = evhttp_request_get_response_code(req);
176 
177  struct evbuffer *buf = evhttp_request_get_input_buffer(req);
178  if (buf)
179  {
180  size_t size = evbuffer_get_length(buf);
181  const char *data = (const char*)evbuffer_pullup(buf, size);
182  if (data)
183  reply->body = std::string(data, size);
184  evbuffer_drain(buf, size);
185  }
186 }
187 
188 #if LIBEVENT_VERSION_NUMBER >= 0x02010300
189 static void http_error_cb(enum evhttp_request_error err, void *ctx)
190 {
191  HTTPReply *reply = static_cast<HTTPReply*>(ctx);
192  reply->error = err;
193 }
194 #endif
195 
200 {
201 public:
202  virtual UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) = 0;
203  virtual UniValue ProcessReply(const UniValue &batch_in) = 0;
204 };
205 
208 {
209 public:
210  const int ID_NETWORKINFO = 0;
211  const int ID_BLOCKCHAININFO = 1;
212  const int ID_WALLETINFO = 2;
213 
215  UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) override
216  {
217  UniValue result(UniValue::VARR);
218  result.push_back(JSONRPCRequestObj("getnetworkinfo", NullUniValue, ID_NETWORKINFO));
219  result.push_back(JSONRPCRequestObj("getblockchaininfo", NullUniValue, ID_BLOCKCHAININFO));
220  result.push_back(JSONRPCRequestObj("getwalletinfo", NullUniValue, ID_WALLETINFO));
221  return result;
222  }
223 
225  UniValue ProcessReply(const UniValue &batch_in) override
226  {
227  UniValue result(UniValue::VOBJ);
228  std::vector<UniValue> batch = JSONRPCProcessBatchReply(batch_in, 3);
229  // Errors in getnetworkinfo() and getblockchaininfo() are fatal, pass them on
230  // getwalletinfo() is allowed to fail in case there is no wallet.
231  if (!batch[ID_NETWORKINFO]["error"].isNull()) {
232  return batch[ID_NETWORKINFO];
233  }
234  if (!batch[ID_BLOCKCHAININFO]["error"].isNull()) {
235  return batch[ID_BLOCKCHAININFO];
236  }
237  result.pushKV("version", batch[ID_NETWORKINFO]["result"]["version"]);
238  result.pushKV("protocolversion", batch[ID_NETWORKINFO]["result"]["protocolversion"]);
239  if (!batch[ID_WALLETINFO].isNull()) {
240  result.pushKV("walletversion", batch[ID_WALLETINFO]["result"]["walletversion"]);
241  result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]);
242  }
243  result.pushKV("blocks", batch[ID_BLOCKCHAININFO]["result"]["blocks"]);
244  result.pushKV("timeoffset", batch[ID_NETWORKINFO]["result"]["timeoffset"]);
245  result.pushKV("connections", batch[ID_NETWORKINFO]["result"]["connections"]);
246  result.pushKV("proxy", batch[ID_NETWORKINFO]["result"]["networks"][0]["proxy"]);
247  result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
248  result.pushKV("testnet", UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"].get_str() == "test"));
249  if (!batch[ID_WALLETINFO].isNull()) {
250  result.pushKV("walletversion", batch[ID_WALLETINFO]["result"]["walletversion"]);
251  result.pushKV("balance", batch[ID_WALLETINFO]["result"]["balance"]);
252  result.pushKV("keypoololdest", batch[ID_WALLETINFO]["result"]["keypoololdest"]);
253  result.pushKV("keypoolsize", batch[ID_WALLETINFO]["result"]["keypoolsize"]);
254  if (!batch[ID_WALLETINFO]["result"]["unlocked_until"].isNull()) {
255  result.pushKV("unlocked_until", batch[ID_WALLETINFO]["result"]["unlocked_until"]);
256  }
257  result.pushKV("paytxfee", batch[ID_WALLETINFO]["result"]["paytxfee"]);
258  }
259  result.pushKV("relayfee", batch[ID_NETWORKINFO]["result"]["relayfee"]);
260  result.pushKV("warnings", batch[ID_NETWORKINFO]["result"]["warnings"]);
261  return JSONRPCReplyObj(result, NullUniValue, 1);
262  }
263 };
264 
267 public:
268  UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) override
269  {
270  UniValue params;
271  if(gArgs.GetBoolArg("-named", DEFAULT_NAMED)) {
272  params = RPCConvertNamedValues(method, args);
273  } else {
274  params = RPCConvertValues(method, args);
275  }
276  return JSONRPCRequestObj(method, params, 1);
277  }
278 
279  UniValue ProcessReply(const UniValue &reply) override
280  {
281  return reply.get_obj();
282  }
283 };
284 
285 static UniValue CallRPC(BaseRequestHandler *rh, const std::string& strMethod, const std::vector<std::string>& args)
286 {
287  std::string host;
288  // In preference order, we choose the following for the port:
289  // 1. -rpcport
290  // 2. port in -rpcconnect (ie following : in ipv4 or ]: in ipv6)
291  // 3. default port for chain
292  int port = BaseParams().RPCPort();
293  SplitHostPort(gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host);
294  port = gArgs.GetArg("-rpcport", port);
295 
296  // Obtain event base
297  raii_event_base base = obtain_event_base();
298 
299  // Synchronously look up hostname
300  raii_evhttp_connection evcon = obtain_evhttp_connection_base(base.get(), host, port);
301  evhttp_connection_set_timeout(evcon.get(), gArgs.GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT));
302 
303  HTTPReply response;
304  raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response);
305  if (req == nullptr)
306  throw std::runtime_error("create http request failed");
307 #if LIBEVENT_VERSION_NUMBER >= 0x02010300
308  evhttp_request_set_error_cb(req.get(), http_error_cb);
309 #endif
310 
311  // Get credentials
312  std::string strRPCUserColonPass;
313  if (gArgs.GetArg("-rpcpassword", "") == "") {
314  // Try fall back to cookie-based authentication if no password is provided
315  if (!GetAuthCookie(&strRPCUserColonPass)) {
316  throw std::runtime_error(strprintf(
317  _("Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set. See -rpcpassword and -stdinrpcpass. Configuration file: (%s)"),
318  GetConfigFile(gArgs.GetArg("-conf", RAVEN_CONF_FILENAME)).string().c_str()));
319 
320  }
321  } else {
322  strRPCUserColonPass = gArgs.GetArg("-rpcuser", "") + ":" + gArgs.GetArg("-rpcpassword", "");
323  }
324 
325  struct evkeyvalq* output_headers = evhttp_request_get_output_headers(req.get());
326  assert(output_headers);
327  evhttp_add_header(output_headers, "Host", host.c_str());
328  evhttp_add_header(output_headers, "Connection", "close");
329  evhttp_add_header(output_headers, "Authorization", (std::string("Basic ") + EncodeBase64(strRPCUserColonPass)).c_str());
330 
331  // Attach request data
332  std::string strRequest = rh->PrepareRequest(strMethod, args).write() + "\n";
333  struct evbuffer* output_buffer = evhttp_request_get_output_buffer(req.get());
334  assert(output_buffer);
335  evbuffer_add(output_buffer, strRequest.data(), strRequest.size());
336 
337  // check if we should use a special wallet endpoint
338  std::string endpoint = "/";
339  std::string walletName = gArgs.GetArg("-rpcwallet", "");
340  if (!walletName.empty()) {
341  char *encodedURI = evhttp_uriencode(walletName.c_str(), walletName.size(), false);
342  if (encodedURI) {
343  endpoint = "/wallet/"+ std::string(encodedURI);
344  free(encodedURI);
345  }
346  else {
347  throw CConnectionFailed("uri-encode failed");
348  }
349  }
350  int r = evhttp_make_request(evcon.get(), req.get(), EVHTTP_REQ_POST, endpoint.c_str());
351  req.release(); // ownership moved to evcon in above call
352  if (r != 0) {
353  throw CConnectionFailed("send http request failed");
354  }
355 
356  event_base_dispatch(base.get());
357 
358  if (response.status == 0)
359  throw CConnectionFailed(strprintf("couldn't connect to server: %s (code %d)\n(make sure server is running and you are connecting to the correct RPC port)", http_errorstring(response.error), response.error));
360  else if (response.status == HTTP_UNAUTHORIZED)
361  throw std::runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
362  else if (response.status >= 400 && response.status != HTTP_BAD_REQUEST && response.status != HTTP_NOT_FOUND && response.status != HTTP_INTERNAL_SERVER_ERROR)
363  throw std::runtime_error(strprintf("server returned HTTP error %d", response.status));
364  else if (response.body.empty())
365  throw std::runtime_error("no response from server");
366 
367  // Parse reply
368  UniValue valReply(UniValue::VSTR);
369  if (!valReply.read(response.body))
370  throw std::runtime_error("couldn't parse reply from server");
371  const UniValue reply = rh->ProcessReply(valReply);
372  if (reply.empty())
373  throw std::runtime_error("expected reply to have result, error and id properties");
374 
375  return reply;
376 }
377 
378 int CommandLineRPC(int argc, char *argv[])
379 {
380  std::string strPrint;
381  int nRet = 0;
382  try {
383  // Skip switches
384  while (argc > 1 && IsSwitchChar(argv[1][0])) {
385  argc--;
386  argv++;
387  }
388  std::string rpcPass;
389  if (gArgs.GetBoolArg("-stdinrpcpass", false)) {
390  if (!std::getline(std::cin, rpcPass)) {
391  throw std::runtime_error("-stdinrpcpass specified but failed to read from standard input");
392  }
393  gArgs.ForceSetArg("-rpcpassword", rpcPass);
394  }
395  std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
396  if (gArgs.GetBoolArg("-stdin", false)) {
397  // Read one arg per line from stdin and append
398  std::string line;
399  while (std::getline(std::cin, line)) {
400  args.push_back(line);
401  }
402  }
403  std::unique_ptr<BaseRequestHandler> rh;
404  std::string method;
405  if (gArgs.GetBoolArg("-getinfo", false)) {
406  rh.reset(new GetinfoRequestHandler());
407  method = "";
408  } else {
409  rh.reset(new DefaultRequestHandler());
410  if (args.size() < 1) {
411  throw std::runtime_error("too few parameters (need at least command)");
412  }
413  method = args[0];
414  args.erase(args.begin()); // Remove trailing method name from arguments vector
415  }
416 
417  // Execute and handle connection failures with -rpcwait
418  const bool fWait = gArgs.GetBoolArg("-rpcwait", false);
419  do {
420  try {
421  const UniValue reply = CallRPC(rh.get(), method, args);
422 
423  // Parse reply
424  const UniValue& result = find_value(reply, "result");
425  const UniValue& error = find_value(reply, "error");
426 
427  if (!error.isNull()) {
428  // Error
429  int code = error["code"].get_int();
430  if (fWait && code == RPC_IN_WARMUP)
431  throw CConnectionFailed("server in warmup");
432  strPrint = "error: " + error.write();
433  nRet = abs(code);
434  if (error.isObject())
435  {
436  UniValue errCode = find_value(error, "code");
437  UniValue errMsg = find_value(error, "message");
438  strPrint = errCode.isNull() ? "" : "error code: "+errCode.getValStr()+"\n";
439 
440  if (errMsg.isStr())
441  strPrint += "error message:\n"+errMsg.get_str();
442 
443  if (errCode.isNum() && errCode.get_int() == RPC_WALLET_NOT_SPECIFIED) {
444  strPrint += "\nTry adding \"-rpcwallet=<filename>\" option to raven-cli command line.";
445  }
446  }
447  } else {
448  // Result
449  if (result.isNull())
450  strPrint = "";
451  else if (result.isStr())
452  strPrint = result.get_str();
453  else
454  strPrint = result.write(2);
455  }
456  // Connection succeeded, no need to retry.
457  break;
458  }
459  catch (const CConnectionFailed&) {
460  if (fWait)
461  MilliSleep(1000);
462  else
463  throw;
464  }
465  } while (fWait);
466  }
467  catch (const boost::thread_interrupted&) {
468  throw;
469  }
470  catch (const std::exception& e) {
471  strPrint = std::string("error: ") + e.what();
472  nRet = EXIT_FAILURE;
473  }
474  catch (...) {
475  PrintExceptionContinue(nullptr, "CommandLineRPC()");
476  throw;
477  }
478 
479  if (strPrint != "") {
480  fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
481  }
482  return nRet;
483 }
484 
485 int main(int argc, char* argv[])
486 {
488  if (!SetupNetworking()) {
489  fprintf(stderr, "Error: Initializing networking failed\n");
490  return EXIT_FAILURE;
491  }
492 
493  try {
494  int ret = AppInitRPC(argc, argv);
495  if (ret != CONTINUE_EXECUTION)
496  return ret;
497  }
498  catch (const std::exception& e) {
499  PrintExceptionContinue(&e, "AppInitRPC()");
500  return EXIT_FAILURE;
501  } catch (...) {
502  PrintExceptionContinue(nullptr, "AppInitRPC()");
503  return EXIT_FAILURE;
504  }
505 
506  int ret = EXIT_FAILURE;
507  try {
508  ret = CommandLineRPC(argc, argv);
509  }
510  catch (const std::exception& e) {
511  PrintExceptionContinue(&e, "CommandLineRPC()");
512  } catch (...) {
513  PrintExceptionContinue(nullptr, "CommandLineRPC()");
514  }
515  return ret;
516 }
No wallet specified (error when there are multiple wallets loaded)
Definition: protocol.h:88
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: util.cpp:511
bool isObject() const
Definition: univalue.h:86
std::unique_ptr< CBaseChainParams > CreateBaseChainParams(const std::string &chain)
Creates and returns a std::unique_ptr<CBaseChainParams> of the chosen chain.
void AppendParamsHelpMessages(std::string &strUsage, bool debugHelp)
Append the help messages for the chainparams options to the parameter string.
std::string HelpMessageCli()
Definition: raven-cli.cpp:32
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: util.cpp:448
bool SetupNetworking()
Definition: util.cpp:896
raii_event_base obtain_event_base()
Definition: events.h:31
const char *const RAVEN_CONF_FILENAME
Definition: util.cpp:91
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:404
void MilliSleep(int64_t n)
Definition: utiltime.cpp:61
bool read(const char *raw, size_t len)
#define strprintf
Definition: tinyformat.h:1054
UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue &params, const UniValue &id)
JSON-RPC protocol.
Definition: protocol.cpp:28
UniValue ProcessReply(const UniValue &reply) override
Definition: raven-cli.cpp:279
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: util.cpp:535
const std::string & get_str() const
bool isNum() const
Definition: univalue.h:84
raii_evhttp_request obtain_evhttp_request(void(*cb)(struct evhttp_request *, void *), void *arg)
Definition: events.h:46
bool isStr() const
Definition: univalue.h:83
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: util.cpp:470
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Definition: util.cpp:494
#define PACKAGE_NAME
Definition: raven-config.h:350
std::vector< UniValue > JSONRPCProcessBatchReply(const UniValue &in, size_t num)
Parse JSON-RPC batch reply into a vector.
Definition: protocol.cpp:139
void ReadConfigFile(const std::string &confPath)
Definition: util.cpp:621
const std::string & getValStr() const
Definition: univalue.h:67
Client still warming up.
Definition: protocol.h:60
virtual UniValue ProcessReply(const UniValue &batch_in)=0
UniValue PrepareRequest(const std::string &method, const std::vector< std::string > &args) override
Create a simulated getinfo request.
Definition: raven-cli.cpp:215
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:236
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
UniValue RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert positional arguments to command-specific RPC representation.
Definition: client.cpp:246
bool GetAuthCookie(std::string *cookie_out)
Read the RPC authentication cookie from disk.
Definition: protocol.cpp:114
bool push_back(const UniValue &val)
Definition: univalue.cpp:110
int CommandLineRPC(int argc, char *argv[])
Definition: raven-cli.cpp:378
const char * http_errorstring(int code)
Definition: raven-cli.cpp:141
bool empty() const
Definition: univalue.h:68
virtual UniValue PrepareRequest(const std::string &method, const std::vector< std::string > &args)=0
raii_evhttp_connection obtain_evhttp_connection_base(struct event_base *base, std::string host, uint16_t port)
Definition: events.h:50
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:135
int get_int() const
UniValue ProcessReply(const UniValue &batch_in) override
Collect values from the batch and form a simulated getinfo reply.
Definition: raven-cli.cpp:225
bool isNull() const
Definition: univalue.h:79
Class that handles the conversion from a command-line to a JSON-RPC request, as well as converting ba...
Definition: raven-cli.cpp:199
std::string FormatFullVersion()
CConnectionFailed(const std::string &msg)
Definition: raven-cli.cpp:70
ArgsManager gArgs
Definition: util.cpp:94
int RPCPort() const
bool IsSwitchChar(char c)
Definition: util.h:213
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
fs::path GetConfigFile(const std::string &confPath)
Definition: util.cpp:612
const UniValue & get_obj() const
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: util.cpp:454
Process default single requests.
Definition: raven-cli.cpp:266
std::string ChainNameFromCommandLine()
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
std::string body
Definition: raven-cli.cpp:138
const UniValue NullUniValue
Definition: univalue.cpp:15
bool error(const char *fmt, const Args &... args)
Definition: util.h:168
UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert named arguments to command-specific RPC representation.
Definition: client.cpp:265
static const std::string TESTNET
const fs::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:572
UniValue PrepareRequest(const std::string &method, const std::vector< std::string > &args) override
Definition: raven-cli.cpp:268
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
Definition: protocol.cpp:37
void SetupEnvironment()
Definition: util.cpp:865
void SelectBaseParams(const std::string &chain)
Sets the params returned by Params() to those for the given network.
Process getinfo requests.
Definition: raven-cli.cpp:207
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: util.cpp:506
int main(int argc, char *argv[])
Definition: raven-cli.cpp:485
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: util.h:66
Reply structure for request_done to fill in.
Definition: raven-cli.cpp:132
std::string EncodeBase64(const unsigned char *pch, size_t len)