Bitcoin Core  26.1.0
P2P Digital Currency
server.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2022 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 <common/args.h>
9 #include <common/system.h>
10 #include <logging.h>
11 #include <rpc/util.h>
12 #include <shutdown.h>
13 #include <sync.h>
14 #include <util/strencodings.h>
15 #include <util/string.h>
16 #include <util/time.h>
17 
18 #include <boost/signals2/signal.hpp>
19 
20 #include <cassert>
21 #include <chrono>
22 #include <memory>
23 #include <mutex>
24 #include <unordered_map>
25 
27 static std::atomic<bool> g_rpc_running{false};
28 static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
29 static std::string rpcWarmupStatus GUARDED_BY(g_rpc_warmup_mutex) = "RPC server started";
30 /* Timer-creating functions */
32 /* Map of name to timer. */
34 static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers GUARDED_BY(g_deadline_timers_mutex);
35 static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
36 
38 {
39  std::string method;
40  SteadyClock::time_point start;
41 };
42 
44 {
46  std::list<RPCCommandExecutionInfo> active_commands GUARDED_BY(mutex);
47 };
48 
50 
52 {
53  std::list<RPCCommandExecutionInfo>::iterator it;
54  explicit RPCCommandExecution(const std::string& method)
55  {
57  it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.end(), {method, SteadyClock::now()});
58  }
60  {
62  g_rpc_server_info.active_commands.erase(it);
63  }
64 };
65 
66 static struct CRPCSignals
67 {
68  boost::signals2::signal<void ()> Started;
69  boost::signals2::signal<void ()> Stopped;
70 } g_rpcSignals;
71 
72 void RPCServer::OnStarted(std::function<void ()> slot)
73 {
74  g_rpcSignals.Started.connect(slot);
75 }
76 
77 void RPCServer::OnStopped(std::function<void ()> slot)
78 {
79  g_rpcSignals.Stopped.connect(slot);
80 }
81 
82 std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const
83 {
84  std::string strRet;
85  std::string category;
86  std::set<intptr_t> setDone;
87  std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
88  vCommands.reserve(mapCommands.size());
89 
90  for (const auto& entry : mapCommands)
91  vCommands.emplace_back(entry.second.front()->category + entry.first, entry.second.front());
92  sort(vCommands.begin(), vCommands.end());
93 
94  JSONRPCRequest jreq = helpreq;
96  jreq.params = UniValue();
97 
98  for (const std::pair<std::string, const CRPCCommand*>& command : vCommands)
99  {
100  const CRPCCommand *pcmd = command.second;
101  std::string strMethod = pcmd->name;
102  if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
103  continue;
104  jreq.strMethod = strMethod;
105  try
106  {
107  UniValue unused_result;
108  if (setDone.insert(pcmd->unique_id).second)
109  pcmd->actor(jreq, unused_result, /*last_handler=*/true);
110  }
111  catch (const std::exception& e)
112  {
113  // Help text is returned in an exception
114  std::string strHelp = std::string(e.what());
115  if (strCommand == "")
116  {
117  if (strHelp.find('\n') != std::string::npos)
118  strHelp = strHelp.substr(0, strHelp.find('\n'));
119 
120  if (category != pcmd->category)
121  {
122  if (!category.empty())
123  strRet += "\n";
124  category = pcmd->category;
125  strRet += "== " + Capitalize(category) + " ==\n";
126  }
127  }
128  strRet += strHelp + "\n";
129  }
130  }
131  if (strRet == "")
132  strRet = strprintf("help: unknown command: %s\n", strCommand);
133  strRet = strRet.substr(0,strRet.size()-1);
134  return strRet;
135 }
136 
137 static RPCHelpMan help()
138 {
139  return RPCHelpMan{"help",
140  "\nList all commands, or get help for a specified command.\n",
141  {
142  {"command", RPCArg::Type::STR, RPCArg::DefaultHint{"all commands"}, "The command to get help on"},
143  },
144  {
145  RPCResult{RPCResult::Type::STR, "", "The help text"},
147  },
148  RPCExamples{""},
149  [&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue
150 {
151  std::string strCommand;
152  if (jsonRequest.params.size() > 0) {
153  strCommand = jsonRequest.params[0].get_str();
154  }
155  if (strCommand == "dump_all_command_conversions") {
156  // Used for testing only, undocumented
157  return tableRPC.dumpArgMap(jsonRequest);
158  }
159 
160  return tableRPC.help(strCommand, jsonRequest);
161 },
162  };
163 }
164 
165 static RPCHelpMan stop()
166 {
167  static const std::string RESULT{PACKAGE_NAME " stopping"};
168  return RPCHelpMan{"stop",
169  // Also accept the hidden 'wait' integer argument (milliseconds)
170  // For instance, 'stop 1000' makes the call wait 1 second before returning
171  // to the client (intended for testing)
172  "\nRequest a graceful shutdown of " PACKAGE_NAME ".",
173  {
174  {"wait", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "how long to wait in ms", RPCArgOptions{.hidden=true}},
175  },
176  RPCResult{RPCResult::Type::STR, "", "A string with the content '" + RESULT + "'"},
177  RPCExamples{""},
178  [&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue
179 {
180  // Event loop will exit after current HTTP requests have been handled, so
181  // this reply will get back to the client.
182  StartShutdown();
183  if (jsonRequest.params[0].isNum()) {
184  UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].getInt<int>()});
185  }
186  return RESULT;
187 },
188  };
189 }
190 
192 {
193  return RPCHelpMan{"uptime",
194  "\nReturns the total uptime of the server.\n",
195  {},
196  RPCResult{
197  RPCResult::Type::NUM, "", "The number of seconds that the server has been running"
198  },
199  RPCExamples{
200  HelpExampleCli("uptime", "")
201  + HelpExampleRpc("uptime", "")
202  },
203  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
204 {
205  return GetTime() - GetStartupTime();
206 }
207  };
208 }
209 
211 {
212  return RPCHelpMan{"getrpcinfo",
213  "\nReturns details of the RPC server.\n",
214  {},
215  RPCResult{
216  RPCResult::Type::OBJ, "", "",
217  {
218  {RPCResult::Type::ARR, "active_commands", "All active commands",
219  {
220  {RPCResult::Type::OBJ, "", "Information about an active command",
221  {
222  {RPCResult::Type::STR, "method", "The name of the RPC command"},
223  {RPCResult::Type::NUM, "duration", "The running time in microseconds"},
224  }},
225  }},
226  {RPCResult::Type::STR, "logpath", "The complete file path to the debug log"},
227  }
228  },
229  RPCExamples{
230  HelpExampleCli("getrpcinfo", "")
231  + HelpExampleRpc("getrpcinfo", "")},
232  [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
233 {
235  UniValue active_commands(UniValue::VARR);
236  for (const RPCCommandExecutionInfo& info : g_rpc_server_info.active_commands) {
237  UniValue entry(UniValue::VOBJ);
238  entry.pushKV("method", info.method);
239  entry.pushKV("duration", int64_t{Ticks<std::chrono::microseconds>(SteadyClock::now() - info.start)});
240  active_commands.push_back(entry);
241  }
242 
243  UniValue result(UniValue::VOBJ);
244  result.pushKV("active_commands", active_commands);
245 
246  const std::string path = LogInstance().m_file_path.u8string();
247  UniValue log_path(UniValue::VSTR, path);
248  result.pushKV("logpath", log_path);
249 
250  return result;
251 }
252  };
253 }
254 
255 static const CRPCCommand vRPCCommands[]{
256  /* Overall control/query calls */
257  {"control", &getrpcinfo},
258  {"control", &help},
259  {"control", &stop},
260  {"control", &uptime},
261 };
262 
264 {
265  for (const auto& c : vRPCCommands) {
266  appendCommand(c.name, &c);
267  }
268 }
269 
270 void CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
271 {
272  CHECK_NONFATAL(!IsRPCRunning()); // Only add commands before rpc is running
273 
274  mapCommands[name].push_back(pcmd);
275 }
276 
277 bool CRPCTable::removeCommand(const std::string& name, const CRPCCommand* pcmd)
278 {
279  auto it = mapCommands.find(name);
280  if (it != mapCommands.end()) {
281  auto new_end = std::remove(it->second.begin(), it->second.end(), pcmd);
282  if (it->second.end() != new_end) {
283  it->second.erase(new_end, it->second.end());
284  return true;
285  }
286  }
287  return false;
288 }
289 
290 void StartRPC()
291 {
292  LogPrint(BCLog::RPC, "Starting RPC\n");
293  g_rpc_running = true;
295 }
296 
298 {
299  static std::once_flag g_rpc_interrupt_flag;
300  // This function could be called twice if the GUI has been started with -server=1.
301  std::call_once(g_rpc_interrupt_flag, []() {
302  LogPrint(BCLog::RPC, "Interrupting RPC\n");
303  // Interrupt e.g. running longpolls
304  g_rpc_running = false;
305  });
306 }
307 
308 void StopRPC()
309 {
310  static std::once_flag g_rpc_stop_flag;
311  // This function could be called twice if the GUI has been started with -server=1.
313  std::call_once(g_rpc_stop_flag, []() {
314  LogPrint(BCLog::RPC, "Stopping RPC\n");
315  WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
318  });
319 }
320 
322 {
323  return g_rpc_running;
324 }
325 
327 {
328  if (!IsRPCRunning()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
329 }
330 
331 void SetRPCWarmupStatus(const std::string& newStatus)
332 {
334  rpcWarmupStatus = newStatus;
335 }
336 
338 {
340  assert(fRPCInWarmup);
341  fRPCInWarmup = false;
342 }
343 
344 bool RPCIsInWarmup(std::string *outStatus)
345 {
347  if (outStatus)
348  *outStatus = rpcWarmupStatus;
349  return fRPCInWarmup;
350 }
351 
352 bool IsDeprecatedRPCEnabled(const std::string& method)
353 {
354  const std::vector<std::string> enabled_methods = gArgs.GetArgs("-deprecatedrpc");
355 
356  return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end();
357 }
358 
360 {
361  UniValue rpc_result(UniValue::VOBJ);
362 
363  try {
364  jreq.parse(req);
365 
366  UniValue result = tableRPC.execute(jreq);
367  rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
368  }
369  catch (const UniValue& objError)
370  {
371  rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
372  }
373  catch (const std::exception& e)
374  {
375  rpc_result = JSONRPCReplyObj(NullUniValue,
376  JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
377  }
378 
379  return rpc_result;
380 }
381 
382 std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq)
383 {
385  for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
386  ret.push_back(JSONRPCExecOne(jreq, vReq[reqIdx]));
387 
388  return ret.write() + "\n";
389 }
390 
395 static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, const std::vector<std::pair<std::string, bool>>& argNames)
396 {
397  JSONRPCRequest out = in;
398  out.params = UniValue(UniValue::VARR);
399  // Build a map of parameters, and remove ones that have been processed, so that we can throw a focused error if
400  // there is an unknown one.
401  const std::vector<std::string>& keys = in.params.getKeys();
402  const std::vector<UniValue>& values = in.params.getValues();
403  std::unordered_map<std::string, const UniValue*> argsIn;
404  for (size_t i=0; i<keys.size(); ++i) {
405  auto [_, inserted] = argsIn.emplace(keys[i], &values[i]);
406  if (!inserted) {
407  throw JSONRPCError(RPC_INVALID_PARAMETER, "Parameter " + keys[i] + " specified multiple times");
408  }
409  }
410  // Process expected parameters. If any parameters were left unspecified in
411  // the request before a parameter that was specified, null values need to be
412  // inserted at the unspecifed parameter positions, and the "hole" variable
413  // below tracks the number of null values that need to be inserted.
414  // The "initial_hole_size" variable stores the size of the initial hole,
415  // i.e. how many initial positional arguments were left unspecified. This is
416  // used after the for-loop to add initial positional arguments from the
417  // "args" parameter, if present.
418  int hole = 0;
419  int initial_hole_size = 0;
420  const std::string* initial_param = nullptr;
421  UniValue options{UniValue::VOBJ};
422  for (const auto& [argNamePattern, named_only]: argNames) {
423  std::vector<std::string> vargNames = SplitString(argNamePattern, '|');
424  auto fr = argsIn.end();
425  for (const std::string & argName : vargNames) {
426  fr = argsIn.find(argName);
427  if (fr != argsIn.end()) {
428  break;
429  }
430  }
431 
432  // Handle named-only parameters by pushing them into a temporary options
433  // object, and then pushing the accumulated options as the next
434  // positional argument.
435  if (named_only) {
436  if (fr != argsIn.end()) {
437  if (options.exists(fr->first)) {
438  throw JSONRPCError(RPC_INVALID_PARAMETER, "Parameter " + fr->first + " specified multiple times");
439  }
440  options.pushKVEnd(fr->first, *fr->second);
441  argsIn.erase(fr);
442  }
443  continue;
444  }
445 
446  if (!options.empty() || fr != argsIn.end()) {
447  for (int i = 0; i < hole; ++i) {
448  // Fill hole between specified parameters with JSON nulls,
449  // but not at the end (for backwards compatibility with calls
450  // that act based on number of specified parameters).
451  out.params.push_back(UniValue());
452  }
453  hole = 0;
454  if (!initial_param) initial_param = &argNamePattern;
455  } else {
456  hole += 1;
457  if (out.params.empty()) initial_hole_size = hole;
458  }
459 
460  // If named input parameter "fr" is present, push it onto out.params. If
461  // options are present, push them onto out.params. If both are present,
462  // throw an error.
463  if (fr != argsIn.end()) {
464  if (!options.empty()) {
465  throw JSONRPCError(RPC_INVALID_PARAMETER, "Parameter " + fr->first + " conflicts with parameter " + options.getKeys().front());
466  }
467  out.params.push_back(*fr->second);
468  argsIn.erase(fr);
469  }
470  if (!options.empty()) {
471  out.params.push_back(std::move(options));
472  options = UniValue{UniValue::VOBJ};
473  }
474  }
475  // If leftover "args" param was found, use it as a source of positional
476  // arguments and add named arguments after. This is a convenience for
477  // clients that want to pass a combination of named and positional
478  // arguments as described in doc/JSON-RPC-interface.md#parameter-passing
479  auto positional_args{argsIn.extract("args")};
480  if (positional_args && positional_args.mapped()->isArray()) {
481  if (initial_hole_size < (int)positional_args.mapped()->size() && initial_param) {
482  throw JSONRPCError(RPC_INVALID_PARAMETER, "Parameter " + *initial_param + " specified twice both as positional and named argument");
483  }
484  // Assign positional_args to out.params and append named_args after.
485  UniValue named_args{std::move(out.params)};
486  out.params = *positional_args.mapped();
487  for (size_t i{out.params.size()}; i < named_args.size(); ++i) {
488  out.params.push_back(named_args[i]);
489  }
490  }
491  // If there are still arguments in the argsIn map, this is an error.
492  if (!argsIn.empty()) {
493  throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown named parameter " + argsIn.begin()->first);
494  }
495  // Return request with named arguments transformed to positional arguments
496  return out;
497 }
498 
499 static bool ExecuteCommands(const std::vector<const CRPCCommand*>& commands, const JSONRPCRequest& request, UniValue& result)
500 {
501  for (const auto& command : commands) {
502  if (ExecuteCommand(*command, request, result, &command == &commands.back())) {
503  return true;
504  }
505  }
506  return false;
507 }
508 
510 {
511  // Return immediately if in warmup
512  {
514  if (fRPCInWarmup)
515  throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
516  }
517 
518  // Find method
519  auto it = mapCommands.find(request.strMethod);
520  if (it != mapCommands.end()) {
521  UniValue result;
522  if (ExecuteCommands(it->second, request, result)) {
523  return result;
524  }
525  }
526  throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
527 }
528 
529 static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler)
530 {
531  try {
532  RPCCommandExecution execution(request.strMethod);
533  // Execute, convert arguments to array if necessary
534  if (request.params.isObject()) {
535  return command.actor(transformNamedArguments(request, command.argNames), result, last_handler);
536  } else {
537  return command.actor(request, result, last_handler);
538  }
539  } catch (const UniValue::type_error& e) {
540  throw JSONRPCError(RPC_TYPE_ERROR, e.what());
541  } catch (const std::exception& e) {
542  throw JSONRPCError(RPC_MISC_ERROR, e.what());
543  }
544 }
545 
546 std::vector<std::string> CRPCTable::listCommands() const
547 {
548  std::vector<std::string> commandList;
549  commandList.reserve(mapCommands.size());
550  for (const auto& i : mapCommands) commandList.emplace_back(i.first);
551  return commandList;
552 }
553 
555 {
556  JSONRPCRequest request = args_request;
557  request.mode = JSONRPCRequest::GET_ARGS;
558 
560  for (const auto& cmd : mapCommands) {
561  UniValue result;
562  if (ExecuteCommands(cmd.second, request, result)) {
563  for (const auto& values : result.getValues()) {
564  ret.push_back(values);
565  }
566  }
567  }
568  return ret;
569 }
570 
572 {
573  if (!timerInterface)
574  timerInterface = iface;
575 }
576 
578 {
579  timerInterface = iface;
580 }
581 
583 {
584  if (timerInterface == iface)
585  timerInterface = nullptr;
586 }
587 
588 void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds)
589 {
590  if (!timerInterface)
591  throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
593  deadlineTimers.erase(name);
594  LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
595  deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));
596 }
597 
599 {
600  int flag = 0;
601  if (gArgs.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0)
603  return flag;
604 }
605 
bool isObject() const
Definition: univalue.h:85
void push_back(UniValue val)
Definition: univalue.cpp:104
int ret
RPC timer "driver".
Definition: server.h:59
static const int SERIALIZE_TRANSACTION_NO_WITNESS
A flag that is ORed into the protocol version to designate that a transaction should be (un)serialize...
Definition: transaction.h:32
std::string help(const std::string &name, const JSONRPCRequest &helpreq) const
Definition: server.cpp:82
std::string category
Definition: server.h:115
const std::vector< UniValue > & getValues() const
BCLog::Logger & LogInstance()
Definition: logging.cpp:20
static GlobalMutex g_deadline_timers_mutex
Definition: server.cpp:33
RPC command dispatcher.
Definition: server.h:134
#define LogPrint(category,...)
Definition: logging.h:246
assert(!tx.IsCoinBase())
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:331
static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION
Definition: server.h:19
Actor actor
Definition: server.h:117
fs::path m_file_path
Definition: logging.h:124
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
static bool ExecuteCommands(const std::vector< const CRPCCommand *> &commands, const JSONRPCRequest &request, UniValue &result)
Definition: server.cpp:499
bool hidden
For testing only.
Definition: util.h:152
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:270
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex)
#define CHECK_NONFATAL(condition)
Identity function.
Definition: check.h:46
static std::atomic< bool > g_rpc_running
Definition: server.cpp:27
void OnStopped(std::function< void()> slot)
Definition: server.cpp:77
static GlobalMutex g_rpc_warmup_mutex
Definition: server.cpp:26
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
Definition: server.cpp:277
const auto cmd
#define PACKAGE_NAME
void InterruptRPC()
Definition: server.cpp:297
const std::string & get_str() const
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
const std::vector< std::string > & getKeys() const
static const CRPCCommand vRPCCommands[]
Definition: server.cpp:255
void RPCRunLater(const std::string &name, std::function< void()> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:588
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition: string.h:21
Client still warming up.
Definition: protocol.h:49
std::string method
Definition: server.cpp:39
Invalid, missing or duplicate parameter.
Definition: protocol.h:43
static RPCServerInfo g_rpc_server_info
Definition: server.cpp:49
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:582
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
Definition: request.cpp:134
static bool ExecuteCommand(const CRPCCommand &command, const JSONRPCRequest &request, UniValue &result, bool last_handler)
Definition: server.cpp:529
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
Definition: server.cpp:509
boost::signals2::signal< void()> Stopped
Definition: server.cpp:69
std::string strMethod
Definition: request.h:32
void SetRPCWarmupFinished()
Definition: server.cpp:337
std::string name
Definition: server.h:116
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:161
CRPCTable tableRPC
Definition: server.cpp:606
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:58
static JSONRPCRequest transformNamedArguments(const JSONRPCRequest &in, const std::vector< std::pair< std::string, bool >> &argNames)
Process named arguments into a vector of positional arguments, based on the passed-in specification f...
Definition: server.cpp:395
Mutex mutex
Definition: server.cpp:45
UniValue params
Definition: request.h:33
#define LOCK(cs)
Definition: sync.h:258
const char * name
Definition: rest.cpp:45
enum JSONRPCRequest::Mode mode
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:74
static RPCTimerInterface * timerInterface
Definition: server.cpp:31
boost::signals2::signal< void()> Started
Definition: server.cpp:68
std::string JSONRPCExecBatch(const JSONRPCRequest &jreq, const UniValue &vReq)
Definition: server.cpp:382
UniValue id
Definition: request.h:31
Unexpected type was passed as parameter.
Definition: protocol.h:40
Special type to disable type checks (for testing only)
General application defined errors.
Definition: protocol.h:39
std::string DefaultHint
Hint for default value.
Definition: util.h:198
RPCCommandExecution(const std::string &method)
Definition: server.cpp:54
void StartRPC()
Definition: server.cpp:290
static RPCHelpMan stop()
Definition: server.cpp:165
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: util.cpp:143
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:352
static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue &req)
Definition: server.cpp:359
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:302
static struct CRPCSignals g_rpcSignals
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:571
virtual RPCTimerBase * NewTimer(std::function< void()> &func, int64_t millis)=0
Factory function for timers.
ArgsManager gArgs
Definition: args.cpp:42
Optional argument for which the default value is omitted from help text for one of two reasons: ...
void parse(const UniValue &valRequest)
Definition: request.cpp:166
void StopRPC()
Definition: server.cpp:308
const auto command
void UninterruptibleSleep(const std::chrono::microseconds &n)
Definition: time.cpp:23
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:126
int RPCSerializationFlags()
Definition: server.cpp:598
void RpcInterruptionPoint()
Throw JSONRPCError if RPC is not running.
Definition: server.cpp:326
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
Definition: args.cpp:481
static RPCHelpMan getrpcinfo()
Definition: server.cpp:210
void RPCSetTimerInterface(RPCTimerInterface *iface)
Set the factory function for timers.
Definition: server.cpp:577
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
Definition: request.cpp:40
std::list< RPCCommandExecutionInfo >::iterator it
Definition: server.cpp:53
std::string u8string() const
Definition: fs.h:55
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:344
const UniValue NullUniValue
Definition: univalue.cpp:16
void StartShutdown()
Request shutdown of the application.
Definition: shutdown.cpp:16
int64_t GetStartupTime()
Definition: system.cpp:104
virtual const char * Name()=0
Implementation name.
void OnStarted(std::function< void()> slot)
Definition: server.cpp:72
std::map< std::string, std::vector< const CRPCCommand * > > mapCommands
Definition: server.h:137
size_t size() const
Definition: univalue.h:70
Different type to mark Mutex at global scope.
Definition: sync.h:141
std::list< RPCCommandExecutionInfo > active_commands GUARDED_BY(mutex)
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: args.cpp:361
SteadyClock::time_point start
Definition: server.cpp:40
intptr_t unique_id
Definition: server.h:128
int64_t GetTime()
DEPRECATED, see GetTime.
Definition: time.cpp:97
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:546
P2P client errors.
Definition: protocol.h:58
UniValue dumpArgMap(const JSONRPCRequest &request) const
Return all named arguments that need to be converted by the client from string to another JSON type...
Definition: server.cpp:554
static RPCHelpMan help()
Definition: server.cpp:137
CRPCTable()
Definition: server.cpp:263
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
static RPCHelpMan uptime()
Definition: server.cpp:191