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