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