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