Bitcoin ABC 0.33.1
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 <common/args.h>
10#include <config.h>
11#include <logging.h>
12#include <rpc/util.h>
13#include <shutdown.h>
14#include <sync.h>
15#include <util/strencodings.h>
16#include <util/string.h>
17#include <util/time.h>
18
19#include <boost/signals2/signal.hpp>
20
21#include <cassert>
22#include <chrono>
23#include <memory>
24#include <mutex>
25#include <set>
26#include <unordered_map>
27
29
30using SteadyClock = std::chrono::steady_clock;
31
33static std::atomic<bool> g_rpc_running{false};
34static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
35static std::string
36 rpcWarmupStatus GUARDED_BY(g_rpc_warmup_mutex) = "RPC server started";
37/* Timer-creating functions */
39/* Map of name to timer. */
41static std::map<std::string, std::unique_ptr<RPCTimerBase>>
43static bool ExecuteCommand(const Config &config, const CRPCCommand &command,
44 const JSONRPCRequest &request, UniValue &result,
45 bool last_handler);
46
48 std::string method;
49 SteadyClock::time_point start;
50};
51
54 std::list<RPCCommandExecutionInfo> active_commands GUARDED_BY(mutex);
55};
56
58
60 std::list<RPCCommandExecutionInfo>::iterator it;
61 explicit RPCCommandExecution(const std::string &method) {
63 it = g_rpc_server_info.active_commands.insert(
64 g_rpc_server_info.active_commands.cend(),
65 {method, SteadyClock::now()});
66 }
69 g_rpc_server_info.active_commands.erase(it);
70 }
71};
72
74 const JSONRPCRequest &request) const {
75 // Return immediately if in warmup
76 // This is retained from the old RPC implementation because a lot of state
77 // is set during warmup that RPC commands may depend on. This can be
78 // safely removed once global variable usage has been eliminated.
79 {
81 if (fRPCInWarmup) {
82 throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
83 }
84 }
85
86 std::string commandName = request.strMethod;
87 {
88 auto commandsReadView = commands.getReadView();
89 auto iter = commandsReadView->find(commandName);
90 if (iter != commandsReadView.end()) {
91 return iter->second.get()->Execute(request);
92 }
93 }
94
95 // TODO Remove the below call to tableRPC.execute() and only call it for
96 // context-free RPC commands via an implementation of RPCCommand.
97
98 // Check if context-free RPC method is valid and execute it
99 return tableRPC.execute(config, request);
100}
101
102void RPCServer::RegisterCommand(std::unique_ptr<RPCCommand> command) {
103 if (command != nullptr) {
104 const std::string &commandName = command->GetName();
105 commands.getWriteView()->insert(
106 std::make_pair(commandName, std::move(command)));
107 }
108}
109
110static struct CRPCSignals {
111 boost::signals2::signal<void()> Started;
112 boost::signals2::signal<void()> Stopped;
114
115void RPCServerSignals::OnStarted(std::function<void()> slot) {
116 g_rpcSignals.Started.connect(slot);
117}
118
119void RPCServerSignals::OnStopped(std::function<void()> slot) {
120 g_rpcSignals.Stopped.connect(slot);
121}
122
123std::string CRPCTable::help(const Config &config, const std::string &strCommand,
124 const JSONRPCRequest &helpreq) const {
125 std::string strRet;
126 std::string category;
127 std::set<intptr_t> setDone;
128 std::vector<std::pair<std::string, const CRPCCommand *>> vCommands;
129 vCommands.reserve(mapCommands.size());
130
131 for (const auto &entry : mapCommands) {
132 vCommands.push_back(
133 std::make_pair(entry.second.front()->category + entry.first,
134 entry.second.front()));
135 }
136 sort(vCommands.begin(), vCommands.end());
137
138 JSONRPCRequest jreq = helpreq;
140 jreq.params = UniValue();
141
142 for (const std::pair<std::string, const CRPCCommand *> &command :
143 vCommands) {
144 const CRPCCommand *pcmd = command.second;
145 std::string strMethod = pcmd->name;
146 if ((strCommand != "" || pcmd->category == "hidden") &&
147 strMethod != strCommand) {
148 continue;
149 }
150
151 jreq.strMethod = strMethod;
152 try {
153 UniValue unused_result;
154 if (setDone.insert(pcmd->unique_id).second) {
155 pcmd->actor(config, jreq, unused_result,
156 true /* last_handler */);
157 }
158 } catch (const std::exception &e) {
159 // Help text is returned in an exception
160 std::string strHelp = std::string(e.what());
161 if (strCommand == "") {
162 if (strHelp.find('\n') != std::string::npos) {
163 strHelp = strHelp.substr(0, strHelp.find('\n'));
164 }
165
166 if (category != pcmd->category) {
167 if (!category.empty()) {
168 strRet += "\n";
169 }
170 category = pcmd->category;
171 strRet += "== " + Capitalize(category) + " ==\n";
172 }
173 }
174 strRet += strHelp + "\n";
175 }
176 }
177 if (strRet == "") {
178 strRet = strprintf("help: unknown command: %s\n", strCommand);
179 }
180
181 strRet = strRet.substr(0, strRet.size() - 1);
182 return strRet;
183}
184
185static RPCHelpMan help() {
186 return RPCHelpMan{
187 "help",
188 "List all commands, or get help for a specified command.\n",
189 {
190 {"command", RPCArg::Type::STR, RPCArg::DefaultHint{"all commands"},
191 "The command to get help on"},
192 },
193 {
194 RPCResult{RPCResult::Type::STR, "", "The help text"},
196 },
197 RPCExamples{""},
198 [&](const RPCHelpMan &self, const Config &config,
199 const JSONRPCRequest &jsonRequest) -> UniValue {
200 std::string strCommand;
201 if (jsonRequest.params.size() > 0) {
202 strCommand = jsonRequest.params[0].get_str();
203 }
204 if (strCommand == "dump_all_command_conversions") {
205 // Used for testing only, undocumented
206 return tableRPC.dumpArgMap(config, jsonRequest);
207 }
208
209 return tableRPC.help(config, strCommand, jsonRequest);
210 },
211 };
212}
213
214static RPCHelpMan stop() {
215 static const std::string RESULT{PACKAGE_NAME " stopping"};
216 return RPCHelpMan{
217 "stop",
218 // Also accept the hidden 'wait' integer argument (milliseconds)
219 // For instance, 'stop 1000' makes the call wait 1 second before
220 // returning to the client (intended for testing)
221 "\nRequest a graceful shutdown of " PACKAGE_NAME ".",
222 {
224 "how long to wait in ms", RPCArgOptions{.hidden = true}},
225 },
227 "A string with the content '" + RESULT + "'"},
228 RPCExamples{""},
229 [&](const RPCHelpMan &self, const Config &config,
230 const JSONRPCRequest &jsonRequest) -> UniValue {
231 // Event loop will exit after current HTTP requests have been
232 // handled, so this reply will get back to the client.
234 if (jsonRequest.params[0].isNum()) {
235 UninterruptibleSleep(std::chrono::milliseconds{
236 jsonRequest.params[0].getInt<int>()});
237 }
238 return RESULT;
239 },
240 };
241}
242
244 return RPCHelpMan{
245 "uptime",
246 "Returns the total uptime of the server.\n",
247 {},
249 "The number of seconds that the server has been running"},
250 RPCExamples{HelpExampleCli("uptime", "") +
251 HelpExampleRpc("uptime", "")},
252 [&](const RPCHelpMan &self, const Config &config,
253 const JSONRPCRequest &request) -> UniValue {
254 return GetTime() - GetStartupTime();
255 }};
256}
257
259 return RPCHelpMan{
260 "getrpcinfo",
261 "Returns details of the RPC server.\n",
262 {},
264 "",
265 "",
266 {
268 "active_commands",
269 "All active commands",
270 {
272 "",
273 "Information about an active command",
274 {
275 {RPCResult::Type::STR, "method",
276 "The name of the RPC command"},
277 {RPCResult::Type::NUM, "duration",
278 "The running time in microseconds"},
279 }},
280 }},
281 {RPCResult::Type::STR, "logpath",
282 "The complete file path to the debug log"},
283 }},
284 RPCExamples{HelpExampleCli("getrpcinfo", "") +
285 HelpExampleRpc("getrpcinfo", "")},
286
287 [&](const RPCHelpMan &self, const Config &config,
288 const JSONRPCRequest &request) -> UniValue {
290 UniValue active_commands(UniValue::VARR);
291 for (const RPCCommandExecutionInfo &info :
292 g_rpc_server_info.active_commands) {
294 entry.pushKV("method", info.method);
295 entry.pushKV("duration",
296 int64_t{Ticks<std::chrono::microseconds>(
297 SteadyClock::now() - info.start)});
298 active_commands.push_back(std::move(entry));
299 }
300
301 UniValue result(UniValue::VOBJ);
302 result.pushKV("active_commands", std::move(active_commands));
303
304 const std::string path = LogInstance().m_file_path.u8string();
305 UniValue log_path(UniValue::VSTR, path);
306 result.pushKV("logpath", std::move(log_path));
307
308 return result;
309 }};
310}
311
312// clang-format off
313static const CRPCCommand vRPCCommands[] = {
314 // category actor (function)
315 // ------------------- ----------------------
316 /* Overall control/query calls */
317 { "control", getrpcinfo, },
318 { "control", help, },
319 { "control", stop, },
320 { "control", uptime, },
321};
322// clang-format on
323
325 for (const auto &c : vRPCCommands) {
326 appendCommand(c.name, &c);
327 }
328}
329
330void CRPCTable::appendCommand(const std::string &name,
331 const CRPCCommand *pcmd) {
332 // Only add commands before rpc is running
334
335 mapCommands[name].push_back(pcmd);
336}
337
338bool CRPCTable::removeCommand(const std::string &name,
339 const CRPCCommand *pcmd) {
340 auto it = mapCommands.find(name);
341 if (it != mapCommands.end()) {
342 auto new_end = std::remove(it->second.begin(), it->second.end(), pcmd);
343 if (it->second.end() != new_end) {
344 it->second.erase(new_end, it->second.end());
345 return true;
346 }
347 }
348 return false;
349}
350
351void StartRPC() {
352 LogPrint(BCLog::RPC, "Starting RPC\n");
353 g_rpc_running = true;
355}
356
358 static std::once_flag g_rpc_interrupt_flag;
359 // This function could be called twice if the GUI has been started with
360 // -server=1.
361 std::call_once(g_rpc_interrupt_flag, []() {
362 LogPrint(BCLog::RPC, "Interrupting RPC\n");
363 // Interrupt e.g. running longpolls
364 g_rpc_running = false;
365 });
366}
367
368void StopRPC() {
369 static std::once_flag g_rpc_stop_flag;
370 // This function could be called twice if the GUI has been started with
371 // -server=1.
373 std::call_once(g_rpc_stop_flag, []() {
374 LogPrint(BCLog::RPC, "Stopping RPC\n");
375 WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
378 });
379}
380
382 return g_rpc_running;
383}
384
386 if (!IsRPCRunning()) {
387 throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
388 }
389}
390
391void SetRPCWarmupStatus(const std::string &newStatus) {
393 rpcWarmupStatus = newStatus;
394}
395
398 assert(fRPCInWarmup);
399 fRPCInWarmup = false;
400}
401
402bool RPCIsInWarmup(std::string *outStatus) {
404 if (outStatus) {
405 *outStatus = rpcWarmupStatus;
406 }
407 return fRPCInWarmup;
408}
409
411 const std::string &method) {
412 const std::vector<std::string> enabled_methods =
413 args.GetArgs("-deprecatedrpc");
414
415 return find(enabled_methods.begin(), enabled_methods.end(), method) !=
416 enabled_methods.end();
417}
418
419static UniValue JSONRPCExecOne(const Config &config, RPCServer &rpcServer,
420 JSONRPCRequest jreq, const UniValue &req) {
421 UniValue rpc_result(UniValue::VOBJ);
422
423 try {
424 jreq.parse(req);
425
426 UniValue result = rpcServer.ExecuteCommand(config, jreq);
427 rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
428 } catch (const UniValue &objError) {
429 rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
430 } catch (const std::exception &e) {
431 rpc_result = JSONRPCReplyObj(
432 NullUniValue, JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
433 }
434
435 return rpc_result;
436}
437
438std::string JSONRPCExecBatch(const Config &config, RPCServer &rpcServer,
439 const JSONRPCRequest &jreq, const UniValue &vReq) {
441 for (size_t i = 0; i < vReq.size(); i++) {
442 ret.push_back(JSONRPCExecOne(config, rpcServer, jreq, vReq[i]));
443 }
444
445 return ret.write() + "\n";
446}
447
453 const JSONRPCRequest &in,
454 const std::vector<std::pair<std::string, bool>> &argNames) {
455 JSONRPCRequest out = in;
457 // Build a map of parameters, and remove ones that have been processed, so
458 // that we can throw a focused error if there is an unknown one.
459 const std::vector<std::string> &keys = in.params.getKeys();
460 const std::vector<UniValue> &values = in.params.getValues();
461 std::unordered_map<std::string, const UniValue *> argsIn;
462 for (size_t i = 0; i < keys.size(); ++i) {
463 auto [_, inserted] = argsIn.emplace(keys[i], &values[i]);
464 if (!inserted) {
466 "Parameter " + keys[i] +
467 " specified multiple times");
468 }
469 }
470 // Process expected parameters. If any parameters were left unspecified in
471 // the request before a parameter that was specified, null values need to be
472 // inserted at the unspecifed parameter positions, and the "hole" variable
473 // below tracks the number of null values that need to be inserted.
474 // The "initial_hole_size" variable stores the size of the initial hole,
475 // i.e. how many initial positional arguments were left unspecified. This is
476 // used after the for-loop to add initial positional arguments from the
477 // "args" parameter, if present.
478 size_t hole = 0;
479 size_t initial_hole_size = 0;
480 const std::string *initial_param = nullptr;
481 UniValue options{UniValue::VOBJ};
482 for (const auto &[argNamePattern, named_only] : argNames) {
483 std::vector<std::string> vargNames = SplitString(argNamePattern, '|');
484 auto fr = argsIn.end();
485 for (const std::string &argName : vargNames) {
486 fr = argsIn.find(argName);
487 if (fr != argsIn.end()) {
488 break;
489 }
490 }
491
492 // Handle named-only parameters by pushing them into a temporary options
493 // object, and then pushing the accumulated options as the next
494 // positional argument.
495 if (named_only) {
496 if (fr != argsIn.end()) {
497 if (options.exists(fr->first)) {
499 "Parameter " + fr->first +
500 " specified multiple times");
501 }
502 options.pushKVEnd(fr->first, *fr->second);
503 argsIn.erase(fr);
504 }
505 continue;
506 }
507
508 if (!options.empty() || fr != argsIn.end()) {
509 for (size_t i = 0; i < hole; ++i) {
510 // Fill hole between specified parameters with JSON nulls,
511 // but not at the end (for backwards compatibility with calls
512 // that act based on number of specified parameters).
514 }
515 hole = 0;
516 if (!initial_param) {
517 initial_param = &argNamePattern;
518 }
519 } else {
520 hole += 1;
521 if (out.params.empty()) {
522 initial_hole_size = hole;
523 }
524 }
525
526 // If named input parameter "fr" is present, push it onto out.params. If
527 // options are present, push them onto out.params. If both are present,
528 // throw an error.
529 if (fr != argsIn.end()) {
530 if (!options.empty()) {
532 "Parameter " + fr->first +
533 " conflicts with parameter " +
534 options.getKeys().front());
535 }
536 out.params.push_back(*fr->second);
537 argsIn.erase(fr);
538 }
539 if (!options.empty()) {
540 out.params.push_back(std::move(options));
541 options = UniValue{UniValue::VOBJ};
542 }
543 }
544 // If leftover "args" param was found, use it as a source of positional
545 // arguments and add named arguments after. This is a convenience for
546 // clients that want to pass a combination of named and positional
547 // arguments as described in doc/JSON-RPC-interface.md#parameter-passing
548 auto positional_args{argsIn.extract("args")};
549 if (positional_args && positional_args.mapped()->isArray()) {
550 if (initial_hole_size < positional_args.mapped()->size() &&
551 initial_param) {
552 throw JSONRPCError(
554 "Parameter " + *initial_param +
555 " specified twice both as positional and named argument");
556 }
557 // Assign positional_args to out.params and append named_args after.
558 UniValue named_args{std::move(out.params)};
559 out.params = *positional_args.mapped();
560 for (size_t i{out.params.size()}; i < named_args.size(); ++i) {
561 out.params.push_back(named_args[i]);
562 }
563 }
564 // If there are still arguments in the argsIn map, this is an error.
565 if (!argsIn.empty()) {
567 "Unknown named parameter " + argsIn.begin()->first);
568 }
569 // Return request with named arguments transformed to positional arguments
570 return out;
571}
572
573static bool ExecuteCommands(const Config &config,
574 const std::vector<const CRPCCommand *> &commands,
575 const JSONRPCRequest &request, UniValue &result) {
576 for (const auto &command : commands) {
577 if (ExecuteCommand(config, *command, request, result,
578 &command == &commands.back())) {
579 return true;
580 }
581 }
582 return false;
583}
584
586 const JSONRPCRequest &request) const {
587 // Return immediately if in warmup
588 {
590 if (fRPCInWarmup) {
591 throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
592 }
593 }
594
595 // Find method
596 auto it = mapCommands.find(request.strMethod);
597 if (it != mapCommands.end()) {
598 UniValue result;
599 if (ExecuteCommands(config, it->second, request, result)) {
600 return result;
601 }
602 }
603 throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
604}
605
606static bool ExecuteCommand(const Config &config, const CRPCCommand &command,
607 const JSONRPCRequest &request, UniValue &result,
608 bool last_handler) {
609 try {
610 RPCCommandExecution execution(request.strMethod);
611 // Execute, convert arguments to array if necessary
612 if (request.params.isObject()) {
613 return command.actor(
614 config, transformNamedArguments(request, command.argNames),
615 result, last_handler);
616 } else {
617 return command.actor(config, request, result, last_handler);
618 }
619 } catch (const UniValue::type_error &e) {
620 throw JSONRPCError(RPC_TYPE_ERROR, e.what());
621 } catch (const std::exception &e) {
622 throw JSONRPCError(RPC_MISC_ERROR, e.what());
623 }
624}
625
626std::vector<std::string> CRPCTable::listCommands() const {
627 std::vector<std::string> commandList;
628 commandList.reserve(mapCommands.size());
629 for (const auto &i : mapCommands) {
630 commandList.emplace_back(i.first);
631 }
632 return commandList;
633}
634
636 const JSONRPCRequest &args_request) const {
637 JSONRPCRequest request = args_request;
639
641 for (const auto &cmd : mapCommands) {
642 UniValue result;
643 if (ExecuteCommands(config, cmd.second, request, result)) {
644 for (const auto &values : result.getValues()) {
645 ret.push_back(values);
646 }
647 }
648 }
649 return ret;
650}
651
653 if (!timerInterface) {
654 timerInterface = iface;
655 }
656}
657
659 timerInterface = iface;
660}
661
663 if (timerInterface == iface) {
664 timerInterface = nullptr;
665 }
666}
667
668void RPCRunLater(const std::string &name, std::function<void()> func,
669 int64_t nSeconds) {
670 if (!timerInterface) {
672 "No timer handler registered for RPC");
673 }
675 deadlineTimers.erase(name);
676 LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n",
677 name, nSeconds, timerInterface->Name());
678 deadlineTimers.emplace(
679 name, std::unique_ptr<RPCTimerBase>(
680 timerInterface->NewTimer(func, nSeconds * 1000)));
681}
682
#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: args.cpp:361
fs::path m_file_path
Definition: logging.h:265
std::string category
Definition: server.h:175
intptr_t unique_id
Definition: server.h:188
std::vector< std::pair< std::string, bool > > argNames
List of method arguments and whether they are named-only.
Definition: server.h:187
std::string name
Definition: server.h:176
Actor actor
Definition: server.h:177
RPC command dispatcher.
Definition: server.h:194
std::map< std::string, std::vector< const CRPCCommand * > > mapCommands
Definition: server.h:196
CRPCTable()
Definition: server.cpp:324
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
Definition: server.cpp:338
std::string help(const Config &config, const std::string &name, const JSONRPCRequest &helpreq) const
Definition: server.cpp:123
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:626
UniValue execute(const Config &config, const JSONRPCRequest &request) const
Execute a method.
Definition: server.cpp:585
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:330
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:635
Definition: config.h:19
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:164
Class for registering and managing all RPC calls.
Definition: server.h:40
UniValue ExecuteCommand(const Config &config, const JSONRPCRequest &request) const
Attempts to execute an RPC command from the given request.
Definition: server.cpp:73
RWCollection< RPCCommandMap > commands
Definition: server.h:42
void RegisterCommand(std::unique_ptr< RPCCommand > command)
Register an RPC command.
Definition: server.cpp:102
RPC timer "driver".
Definition: server.h:100
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:76
WriteView getWriteView()
Definition: rwcollection.h:82
void push_back(UniValue val)
Definition: univalue.cpp:96
const std::string & get_str() const
@ VOBJ
Definition: univalue.h:31
@ VSTR
Definition: univalue.h:33
@ VARR
Definition: univalue.h:32
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
size_t size() const
Definition: univalue.h:92
const std::vector< UniValue > & getValues() const
const std::vector< std::string > & getKeys() const
bool empty() const
Definition: univalue.h:90
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:115
bool isObject() const
Definition: univalue.h:111
std::string u8string() const
Definition: fs.h:72
BCLog::Logger & LogInstance()
Definition: logging.cpp:28
#define LogPrint(category,...)
Definition: logging.h:452
@ RPC
Definition: logging.h:76
void OnStarted(std::function< void()> slot)
Definition: server.cpp:115
void OnStopped(std::function< void()> slot)
Definition: server.cpp:119
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:58
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
Definition: request.cpp:135
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
Definition: request.cpp:39
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_TYPE_ERROR
Unexpected type was passed as parameter.
Definition: protocol.h:40
@ 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:163
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: util.cpp:180
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:652
void SetRPCWarmupFinished()
Mark warmup as done.
Definition: server.cpp:396
bool IsDeprecatedRPCEnabled(const ArgsManager &args, const std::string &method)
Definition: server.cpp:410
static RPCHelpMan uptime()
Definition: server.cpp:243
std::chrono::steady_clock SteadyClock
Definition: server.cpp:30
void StartRPC()
Definition: server.cpp:351
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:662
static RPCHelpMan getrpcinfo()
Definition: server.cpp:258
void RPCRunLater(const std::string &name, std::function< void()> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:668
bool RPCIsInWarmup(std::string *outStatus)
Returns the current warmup state.
Definition: server.cpp:402
static UniValue JSONRPCExecOne(const Config &config, RPCServer &rpcServer, JSONRPCRequest jreq, const UniValue &req)
Definition: server.cpp:419
static RPCTimerInterface * timerInterface
Definition: server.cpp:38
void StopRPC()
Definition: server.cpp:368
static RPCHelpMan stop()
Definition: server.cpp:214
static std::atomic< bool > g_rpc_running
Definition: server.cpp:33
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:452
static GlobalMutex g_deadline_timers_mutex
Definition: server.cpp:40
bool IsRPCRunning()
Query whether RPC is running.
Definition: server.cpp:381
static bool ExecuteCommands(const Config &config, const std::vector< const CRPCCommand * > &commands, const JSONRPCRequest &request, UniValue &result)
Definition: server.cpp:573
void InterruptRPC()
Definition: server.cpp:357
static struct CRPCSignals g_rpcSignals
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:185
static bool ExecuteCommand(const Config &config, const CRPCCommand &command, const JSONRPCRequest &request, UniValue &result, bool last_handler)
Definition: server.cpp:606
static RPCServerInfo g_rpc_server_info
Definition: server.cpp:57
static const CRPCCommand vRPCCommands[]
Definition: server.cpp:313
std::string JSONRPCExecBatch(const Config &config, RPCServer &rpcServer, const JSONRPCRequest &jreq, const UniValue &vReq)
Definition: server.cpp:438
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
Definition: server.cpp:391
CRPCTable tableRPC
Definition: server.cpp:683
void RPCSetTimerInterface(RPCTimerInterface *iface)
Set the factory function for timers.
Definition: server.cpp:658
void RpcInterruptionPoint()
Throw JSONRPCError if RPC is not running.
Definition: server.cpp:385
void StartShutdown()
Request shutdown of the application.
Definition: shutdown.cpp:16
boost::signals2::signal< void()> Started
Definition: server.cpp:111
boost::signals2::signal< void()> Stopped
Definition: server.cpp:112
std::string DefaultHint
Hint for default value.
Definition: util.h:212
@ 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:157
RPCCommandExecution(const std::string &method)
Definition: server.cpp:61
std::list< RPCCommandExecutionInfo >::iterator it
Definition: server.cpp:60
SteadyClock::time_point start
Definition: server.cpp:49
std::string method
Definition: server.cpp:48
@ ANY
Special type to disable type checks (for testing only)
std::list< RPCCommandExecutionInfo > active_commands GUARDED_BY(mutex)
Mutex mutex
Definition: server.cpp:53
#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()
Definition: system.cpp:119
void UninterruptibleSleep(const std::chrono::microseconds &n)
Definition: time.cpp:21
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
Definition: time.cpp:80
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:68
const UniValue NullUniValue
Definition: univalue.cpp:16
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
assert(!tx.IsCoinBase())