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