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