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