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