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