Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

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