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