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