Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

server.cpp
Go to the documentation of this file.
1 // Copyright (c) 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 #include <rpc/server.h>
8 
9 #include <base58.h>
10 #include <fs.h>
11 #include <init.h>
12 #include <random.h>
13 #include <sync.h>
14 #include <ui_interface.h>
15 #include <util.h>
16 #include <utilstrencodings.h>
17 
18 #include <boost/bind.hpp>
19 #include <boost/signals2/signal.hpp>
20 #include <boost/algorithm/string/case_conv.hpp> // for to_upper()
21 #include <boost/algorithm/string/classification.hpp>
22 #include <boost/algorithm/string/split.hpp>
23 
24 #include <algorithm>
25 #include <memory> // for unique_ptr
26 #include <unordered_map>
27 
28 static bool fRPCRunning = false;
29 static bool fRPCInWarmup = true;
30 static std::string rpcWarmupStatus("RPC server started");
32 /* Timer-creating functions */
34 /* Map of name to timer. */
35 static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers;
36 
37 static struct CRPCSignals
38 {
39  boost::signals2::signal<void ()> Started;
40  boost::signals2::signal<void ()> Stopped;
41  boost::signals2::signal<void (const CRPCCommand&)> PreCommand;
42 } g_rpcSignals;
43 
44 void RPCServer::OnStarted(std::function<void ()> slot)
45 {
46  g_rpcSignals.Started.connect(slot);
47 }
48 
49 void RPCServer::OnStopped(std::function<void ()> slot)
50 {
51  g_rpcSignals.Stopped.connect(slot);
52 }
53 
54 void RPCTypeCheck(const UniValue& params,
55  const std::list<UniValue::VType>& typesExpected,
56  bool fAllowNull)
57 {
58  unsigned int i = 0;
59  for (UniValue::VType t : typesExpected)
60  {
61  if (params.size() <= i)
62  break;
63 
64  const UniValue& v = params[i];
65  if (!(fAllowNull && v.isNull())) {
67  }
68  i++;
69  }
70 }
71 
72 void RPCTypeCheckArgument(const UniValue& value, UniValue::VType typeExpected)
73 {
74  if (value.type() != typeExpected) {
75  throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Expected type %s, got %s", uvTypeName(typeExpected), uvTypeName(value.type())));
76  }
77 }
78 
79 void RPCTypeCheckObj(const UniValue& o,
80  const std::map<std::string, UniValueType>& typesExpected,
81  bool fAllowNull,
82  bool fStrict)
83 {
84  for (const auto& t : typesExpected) {
85  const UniValue& v = find_value(o, t.first);
86  if (!fAllowNull && v.isNull())
87  throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
88 
89  if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) {
90  std::string err = strprintf("Expected type %s for %s, got %s",
91  uvTypeName(t.second.type), t.first, uvTypeName(v.type()));
92  throw JSONRPCError(RPC_TYPE_ERROR, err);
93  }
94  }
95 
96  if (fStrict)
97  {
98  for (const std::string& k : o.getKeys())
99  {
100  if (typesExpected.count(k) == 0)
101  {
102  std::string err = strprintf("Unexpected key %s", k);
103  throw JSONRPCError(RPC_TYPE_ERROR, err);
104  }
105  }
106  }
107 }
108 
110 {
111  if (!value.isNum() && !value.isStr())
112  throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string");
113  CAmount amount;
114  if (!ParseFixedPoint(value.getValStr(), 8, &amount))
115  throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
116  if (!MoneyRange(amount))
117  throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range");
118  return amount;
119 }
120 
121 uint256 ParseHashV(const UniValue& v, std::string strName)
122 {
123  std::string strHex;
124  if (v.isStr())
125  strHex = v.get_str();
126  if (!IsHex(strHex)) // Note: IsHex("") is false
127  throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
128  if (64 != strHex.length())
129  throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s must be of length %d (not %d)", strName, 64, strHex.length()));
130  uint256 result;
131  result.SetHex(strHex);
132  return result;
133 }
134 uint256 ParseHashO(const UniValue& o, std::string strKey)
135 {
136  return ParseHashV(find_value(o, strKey), strKey);
137 }
138 std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName)
139 {
140  std::string strHex;
141  if (v.isStr())
142  strHex = v.get_str();
143  if (!IsHex(strHex))
144  throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
145  return ParseHex(strHex);
146 }
147 std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey)
148 {
149  return ParseHexV(find_value(o, strKey), strKey);
150 }
151 
152 int32_t ParseInt32V(const UniValue& v, const std::string &strName)
153 {
154  std::string strNum = v.getValStr();
155  int32_t num;
156  if (!ParseInt32(strNum, &num))
157  throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a 32bit integer (not '"+strNum+"')");
158  return num;
159 }
160 
161 int64_t ParseInt64V(const UniValue& v, const std::string &strName)
162 {
163  std::string strNum = v.getValStr();
164  int64_t num;
165  if (!ParseInt64(strNum, &num))
166  throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a 64bit integer (not '"+strNum+"')");
167  return num;
168 }
169 
170 double ParseDoubleV(const UniValue& v, const std::string &strName)
171 {
172  std::string strNum = v.getValStr();
173  double num;
174  if (!ParseDouble(strNum, &num))
175  throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be a be number (not '"+strNum+"')");
176  return num;
177 }
178 
179 bool ParseBoolV(const UniValue& v, const std::string &strName)
180 {
181  std::string strBool;
182  if (v.isBool())
183  return v.get_bool();
184  else if (v.isNum())
185  strBool = itostr(v.get_int());
186  else if (v.isStr())
187  strBool = v.get_str();
188 
189  std::transform(strBool.begin(), strBool.end(), strBool.begin(), ::tolower);
190 
191  if (strBool == "true" || strBool == "yes" || strBool == "1") {
192  return true;
193  } else if (strBool == "false" || strBool == "no" || strBool == "0") {
194  return false;
195  }
196  throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be true, false, yes, no, 1 or 0 (not '"+strBool+"')");
197 }
198 
203 std::string CRPCTable::help(const std::string& strCommand, const std::string& strSubCommand, const JSONRPCRequest& helpreq) const
204 {
205  std::string strRet;
206  std::string category;
207  std::set<rpcfn_type> setDone;
208  std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
209 
210  for (const auto& entry : mapCommands)
211  vCommands.push_back(make_pair(entry.second->category + entry.first, entry.second));
212  sort(vCommands.begin(), vCommands.end());
213 
214  JSONRPCRequest jreq(helpreq);
215  jreq.fHelp = true;
216  jreq.params = UniValue();
217 
218  for (const std::pair<std::string, const CRPCCommand*>& command : vCommands)
219  {
220  const CRPCCommand *pcmd = command.second;
221  std::string strMethod = pcmd->name;
222  if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
223  continue;
224  jreq.strMethod = strMethod;
225  try
226  {
227  if (!strSubCommand.empty()) {
228  jreq.params.setArray();
229  jreq.params.push_back(strSubCommand);
230  }
231  rpcfn_type pfn = pcmd->actor;
232  if (setDone.insert(pfn).second)
233  (*pfn)(jreq);
234  }
235  catch (const std::exception& e)
236  {
237  // Help text is returned in an exception
238  std::string strHelp = std::string(e.what());
239  if (strCommand == "")
240  {
241  if (strHelp.find('\n') != std::string::npos)
242  strHelp = strHelp.substr(0, strHelp.find('\n'));
243 
244  if (category != pcmd->category)
245  {
246  if (!category.empty())
247  strRet += "\n";
248  category = pcmd->category;
249  std::string firstLetter = category.substr(0,1);
250  boost::to_upper(firstLetter);
251  strRet += "== " + firstLetter + category.substr(1) + " ==\n";
252  }
253  }
254  strRet += strHelp + "\n";
255  }
256  }
257  if (strRet == "")
258  strRet = strprintf("help: unknown command: %s\n", strCommand);
259  strRet = strRet.substr(0,strRet.size()-1);
260  return strRet;
261 }
262 
263 UniValue help(const JSONRPCRequest& jsonRequest)
264 {
265  if (jsonRequest.fHelp || jsonRequest.params.size() > 2)
266  throw std::runtime_error(
267  "help ( \"command\" ) (\"subCommand\")\n"
268  "\nList all commands, or get help for a specified command.\n"
269  "\nArguments:\n"
270  "1. \"command\" (string, optional) The command to get help on\n"
271  "2. \"subCommand\" (string, optional) The subcommand to get help on. Please not that not all subcommands support this at the moment\n"
272  "\nResult:\n"
273  "\"text\" (string) The help text\n"
274  );
275 
276  std::string strCommand, strSubCommand;
277  if (jsonRequest.params.size() > 0)
278  strCommand = jsonRequest.params[0].get_str();
279  if (jsonRequest.params.size() > 1)
280  strSubCommand = jsonRequest.params[1].get_str();
281 
282  return tableRPC.help(strCommand, strSubCommand, jsonRequest);
283 }
284 
285 
286 UniValue stop(const JSONRPCRequest& jsonRequest)
287 {
288  // Accept the deprecated and ignored 'detach' boolean argument
289  // Also accept the hidden 'wait' integer argument (milliseconds)
290  // For instance, 'stop 1000' makes the call wait 1 second before returning
291  // to the client (intended for testing)
292  if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
293  throw std::runtime_error(
294  "stop\n"
295  "\nStop Dash Core server.");
296  // Event loop will exit after current HTTP requests have been handled, so
297  // this reply will get back to the client.
298  StartShutdown();
299  if (jsonRequest.params[0].isNum()) {
300  MilliSleep(jsonRequest.params[0].get_int());
301  }
302  return "Dash Core server stopping";
303 }
304 
305 UniValue uptime(const JSONRPCRequest& jsonRequest)
306 {
307  if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
308  throw std::runtime_error(
309  "uptime\n"
310  "\nReturns the total uptime of the server.\n"
311  "\nResult:\n"
312  "ttt (numeric) The number of seconds that the server has been running\n"
313  "\nExamples:\n"
314  + HelpExampleCli("uptime", "")
315  + HelpExampleRpc("uptime", "")
316  );
317 
318  return GetTime() - GetStartupTime();
319 }
320 
324 static const CRPCCommand vRPCCommands[] =
325 { // category name actor (function) argNames
326  // --------------------- ------------------------ ----------------------- ----------
327  /* Overall control/query calls */
328  { "control", "help", &help, {"command"} },
329  { "control", "stop", &stop, {"wait"} },
330  { "control", "uptime", &uptime, {} },
331 };
332 
334 {
335  unsigned int vcidx;
336  for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++)
337  {
338  const CRPCCommand *pcmd;
339 
340  pcmd = &vRPCCommands[vcidx];
341  mapCommands[pcmd->name] = pcmd;
342  }
343 }
344 
345 const CRPCCommand *CRPCTable::operator[](const std::string &name) const
346 {
347  std::map<std::string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
348  if (it == mapCommands.end())
349  return nullptr;
350  return (*it).second;
351 }
352 
353 bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
354 {
355  if (IsRPCRunning())
356  return false;
357 
358  // don't allow overwriting for now
359  std::map<std::string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
360  if (it != mapCommands.end())
361  return false;
362 
363  mapCommands[name] = pcmd;
364  return true;
365 }
366 
367 bool StartRPC()
368 {
369  LogPrint(BCLog::RPC, "Starting RPC\n");
370  fRPCRunning = true;
372  return true;
373 }
374 
376 {
377  LogPrint(BCLog::RPC, "Interrupting RPC\n");
378  // Interrupt e.g. running longpolls
379  fRPCRunning = false;
380 }
381 
382 void StopRPC()
383 {
384  LogPrint(BCLog::RPC, "Stopping RPC\n");
385  deadlineTimers.clear();
388 }
389 
391 {
392  return fRPCRunning;
393 }
394 
395 void SetRPCWarmupStatus(const std::string& newStatus)
396 {
398  rpcWarmupStatus = newStatus;
399 }
400 
402 {
404  assert(fRPCInWarmup);
405  fRPCInWarmup = false;
406 }
407 
408 bool RPCIsInWarmup(std::string *outStatus)
409 {
411  if (outStatus)
412  *outStatus = rpcWarmupStatus;
413  return fRPCInWarmup;
414 }
415 
416 void JSONRPCRequest::parse(const UniValue& valRequest)
417 {
418  // Parse request
419  if (!valRequest.isObject())
420  throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object");
421  const UniValue& request = valRequest.get_obj();
422 
423  // Parse id now so errors from here on will have the id
424  id = find_value(request, "id");
425 
426  // Parse method
427  UniValue valMethod = find_value(request, "method");
428  if (valMethod.isNull())
429  throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method");
430  if (!valMethod.isStr())
431  throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string");
432  strMethod = valMethod.get_str();
433  if (strMethod != "getblocktemplate") {
434  LogPrint(BCLog::RPC, "ThreadRPCServer method=%s\n", SanitizeString(strMethod));
435  }
436 
437  // Parse params
438  UniValue valParams = find_value(request, "params");
439  if (valParams.isArray() || valParams.isObject())
440  params = valParams;
441  else if (valParams.isNull())
443  else
444  throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object");
445 }
446 
447 bool IsDeprecatedRPCEnabled(const std::string& method)
448 {
449  const std::vector<std::string> enabled_methods = gArgs.GetArgs("-deprecatedrpc");
450 
451  return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end();
452 }
453 
455 {
456  UniValue rpc_result(UniValue::VOBJ);
457 
458  try {
459  jreq.parse(req);
460 
461  UniValue result = tableRPC.execute(jreq);
462  rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
463  }
464  catch (const UniValue& objError)
465  {
466  rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
467  }
468  catch (const std::exception& e)
469  {
470  rpc_result = JSONRPCReplyObj(NullUniValue,
471  JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
472  }
473 
474  return rpc_result;
475 }
476 
477 std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq)
478 {
480  for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
481  ret.push_back(JSONRPCExecOne(jreq, vReq[reqIdx]));
482 
483  return ret.write() + "\n";
484 }
485 
490 static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, const std::vector<std::string>& argNames)
491 {
492  JSONRPCRequest out = in;
494  // Build a map of parameters, and remove ones that have been processed, so that we can throw a focused error if
495  // there is an unknown one.
496  const std::vector<std::string>& keys = in.params.getKeys();
497  const std::vector<UniValue>& values = in.params.getValues();
498  std::unordered_map<std::string, const UniValue*> argsIn;
499  for (size_t i=0; i<keys.size(); ++i) {
500  argsIn[keys[i]] = &values[i];
501  }
502  // Process expected parameters.
503  int hole = 0;
504  for (const std::string &argNamePattern: argNames) {
505  std::vector<std::string> vargNames;
506  boost::algorithm::split(vargNames, argNamePattern, boost::algorithm::is_any_of("|"));
507  auto fr = argsIn.end();
508  for (const std::string & argName : vargNames) {
509  fr = argsIn.find(argName);
510  if (fr != argsIn.end()) {
511  break;
512  }
513  }
514  if (fr != argsIn.end()) {
515  for (int i = 0; i < hole; ++i) {
516  // Fill hole between specified parameters with JSON nulls,
517  // but not at the end (for backwards compatibility with calls
518  // that act based on number of specified parameters).
519  out.params.push_back(UniValue());
520  }
521  hole = 0;
522  out.params.push_back(*fr->second);
523  argsIn.erase(fr);
524  } else {
525  hole += 1;
526  }
527  }
528  // If there are still arguments in the argsIn map, this is an error.
529  if (!argsIn.empty()) {
530  throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown named parameter " + argsIn.begin()->first);
531  }
532  // Return request with named arguments transformed to positional arguments
533  return out;
534 }
535 
537 {
538  // Return immediately if in warmup
539  {
541  if (fRPCInWarmup)
543  }
544 
545  // Find method
546  const CRPCCommand *pcmd = tableRPC[request.strMethod];
547  if (!pcmd)
548  throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
549 
550  g_rpcSignals.PreCommand(*pcmd);
551 
552  try
553  {
554  // Execute, convert arguments to array if necessary
555  if (request.params.isObject()) {
556  return pcmd->actor(transformNamedArguments(request, pcmd->argNames));
557  } else {
558  return pcmd->actor(request);
559  }
560  }
561  catch (const std::exception& e)
562  {
563  throw JSONRPCError(RPC_MISC_ERROR, e.what());
564  }
565 }
566 
567 std::vector<std::string> CRPCTable::listCommands() const
568 {
569  std::vector<std::string> commandList;
570  typedef std::map<std::string, const CRPCCommand*> commandMap;
571 
572  std::transform( mapCommands.begin(), mapCommands.end(),
573  std::back_inserter(commandList),
574  boost::bind(&commandMap::value_type::first,_1) );
575  return commandList;
576 }
577 
578 std::string HelpExampleCli(const std::string& methodname, const std::string& args)
579 {
580  return "> dash-cli " + methodname + " " + args + "\n";
581 }
582 
583 std::string HelpExampleRpc(const std::string& methodname, const std::string& args)
584 {
585  return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", "
586  "\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;'"
587  " http://127.0.0.1:" + strprintf("%d", gArgs.GetArg("-rpcport", BaseParams().RPCPort())) + "/\n";
588 }
589 
591 {
592  if (!timerInterface)
593  timerInterface = iface;
594 }
595 
597 {
598  timerInterface = iface;
599 }
600 
602 {
603  if (timerInterface == iface)
604  timerInterface = nullptr;
605 }
606 
607 void RPCRunLater(const std::string& name, std::function<void(void)> func, int64_t nSeconds)
608 {
609  if (!timerInterface)
610  throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
611  deadlineTimers.erase(name);
612  LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
613  deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));
614 }
615 
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
Definition: server.cpp:79
uint256 ParseHashO(const UniValue &o, std::string strKey)
Definition: server.cpp:134
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
Definition: server.cpp:147
bool isObject() const
Definition: univalue.h:85
RPC timer "driver".
Definition: server.h:98
bool isBool() const
Definition: univalue.h:81
std::string category
Definition: server.h:131
double ParseDoubleV(const UniValue &v, const std::string &strName)
Definition: server.cpp:170
const std::vector< UniValue > & getValues() const
static JSONRPCRequest transformNamedArguments(const JSONRPCRequest &in, const std::vector< std::string > &argNames)
Process named arguments into a vector of positional arguments, based on the passed-in specification f...
Definition: server.cpp:490
Dash RPC command dispatcher.
Definition: server.h:140
rpcfn_type actor
Definition: server.h:133
void MilliSleep(int64_t n)
Definition: utiltime.cpp:75
bool get_bool() const
bool IsRPCRunning()
Query whether RPC is running.
Definition: server.cpp:390
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
Definition: server.cpp:395
#define strprintf
Definition: tinyformat.h:1066
int32_t ParseInt32V(const UniValue &v, const std::string &strName)
Definition: server.cpp:152
UniValue uptime(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:305
int64_t GetStartupTime()
Definition: util.cpp:1429
bool MoneyRange(const CAmount &nValue)
Definition: amount.h:27
void StartShutdown()
Definition: init.cpp:171
static bool fRPCRunning
Definition: server.cpp:28
void OnStopped(std::function< void()> slot)
Definition: server.cpp:49
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
void InterruptRPC()
Definition: server.cpp:375
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
Definition: protocol.cpp:128
const std::string & get_str() const
bool isNum() const
Definition: univalue.h:83
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:583
bool isStr() const
Definition: univalue.h:82
const std::vector< std::string > & getKeys() const
bool ParseDouble(const std::string &str, double *out)
Convert string to double with strict parse error feedback.
static const CRPCCommand vRPCCommands[]
Call Table.
Definition: server.cpp:324
boost::signals2::signal< void(const CRPCCommand &)> PreCommand
Definition: server.cpp:41
const std::string & getValStr() const
Definition: univalue.h:66
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:353
Client still warming up.
Definition: protocol.h:59
std::vector< std::string > argNames
Definition: server.h:134
void RPCTypeCheck(const UniValue &params, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: server.cpp:54
Invalid, missing or duplicate parameter.
Definition: protocol.h:53
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: server.cpp:121
std::string help(const std::string &name, const std::string &strSubCommand, const JSONRPCRequest &helpreq) const
Note: This interface may still be subject to change.
Definition: server.cpp:203
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:601
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:236
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
Definition: server.cpp:536
boost::signals2::signal< void()> Stopped
Definition: server.cpp:40
const CRPCCommand * operator[](const std::string &name) const
Definition: server.cpp:345
std::string strMethod
Definition: server.h:41
void SetRPCWarmupFinished()
Definition: server.cpp:401
bool ParseInt64(const std::string &str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
int64_t GetTime()
Return system time (or mocked time, if set)
Definition: utiltime.cpp:22
std::string name
Definition: server.h:132
CRPCTable tableRPC
Definition: server.cpp:616
const char * uvTypeName(UniValue::VType t)
Definition: univalue.cpp:221
bool push_back(const UniValue &val)
Definition: univalue.cpp:110
virtual RPCTimerBase * NewTimer(std::function< void(void)> &func, int64_t millis)=0
Factory function for timers.
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
UniValue params
Definition: server.h:42
int64_t ParseInt64V(const UniValue &v, const std::string &strName)
Definition: server.cpp:161
#define LOCK(cs)
Definition: sync.h:178
const char * name
Definition: rest.cpp:36
void RPCTypeCheckArgument(const UniValue &value, UniValue::VType typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
Definition: server.cpp:72
bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
static RPCTimerInterface * timerInterface
Definition: server.cpp:33
boost::signals2::signal< void()> Started
Definition: server.cpp:39
std::string JSONRPCExecBatch(const JSONRPCRequest &jreq, const UniValue &vReq)
Definition: server.cpp:477
UniValue id
Definition: server.h:40
bool IsHex(const std::string &str)
Unexpected type was passed as parameter.
Definition: protocol.h:50
General application defined errors.
Definition: protocol.h:48
std::map< std::string, const CRPCCommand * > mapCommands
Definition: server.h:143
int get_int() const
UniValue help(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:263
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:578
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:109
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:447
static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue &req)
Definition: server.cpp:454
bool isNull() const
Definition: univalue.h:78
void RPCRunLater(const std::string &name, std::function< void(void)> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:607
static struct CRPCSignals g_rpcSignals
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:590
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
Definition: server.cpp:138
static std::map< std::string, std::unique_ptr< RPCTimerBase > > deadlineTimers
Definition: server.cpp:35
#define LogPrint(category,...)
Definition: util.h:214
bool fHelp
Definition: server.h:43
256-bit opaque blob.
Definition: uint256.h:123
void parse(const UniValue &valRequest)
Definition: server.cpp:416
ArgsManager gArgs
Definition: util.cpp:108
enum VType type() const
Definition: univalue.h:174
void StopRPC()
Definition: server.cpp:382
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
void RPCSetTimerInterface(RPCTimerInterface *iface)
Set the factory function for timers.
Definition: server.cpp:596
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:408
const UniValue NullUniValue
Definition: univalue.cpp:15
bool ParseBoolV(const UniValue &v, const std::string &strName)
Definition: server.cpp:179
Standard JSON-RPC 2.0 errors.
Definition: protocol.h:37
virtual const char * Name()=0
Implementation name.
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:54
bool StartRPC()
Definition: server.cpp:367
void OnStarted(std::function< void()> slot)
Definition: server.cpp:44
size_t size() const
Definition: univalue.h:69
static std::string rpcWarmupStatus("RPC server started")
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
static CCriticalSection cs_rpcWarmup
Definition: server.cpp:31
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:567
void SetHex(const char *psz)
Definition: uint256.cpp:27
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
UniValue(* rpcfn_type)(const JSONRPCRequest &jsonRequest)
Definition: server.h:126
bool isArray() const
Definition: univalue.h:84
CRPCTable()
Definition: server.cpp:333
static bool fRPCInWarmup
Definition: server.cpp:29
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
std::string itostr(int n)
UniValue stop(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:286
std::vector< unsigned char > ParseHex(const char *psz)
Released under the MIT license