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