Bitcoin Core 29.99.0
P2P Digital Currency
server.h
Go to the documentation of this file.
1// Copyright (c) 2010 Satoshi Nakamoto
2// Copyright (c) 2009-present 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#ifndef BITCOIN_RPC_SERVER_H
7#define BITCOIN_RPC_SERVER_H
8
9#include <rpc/request.h>
10#include <rpc/util.h>
11
12#include <cstdint>
13#include <functional>
14#include <map>
15#include <string>
16
17#include <univalue.h>
18
19class CRPCCommand;
20
22bool IsRPCRunning();
23
26
31void SetRPCWarmupStatus(const std::string& newStatus);
33/* Mark warmup as done. RPC calls will be processed from now on. */
35
36/* returns the current warmup state. */
37bool RPCIsInWarmup(std::string *outStatus);
38
40
42{
43public:
47 using Actor = std::function<bool(const JSONRPCRequest& request, UniValue& result, bool last_handler)>;
48
50 CRPCCommand(std::string category, std::string name, Actor actor, std::vector<std::pair<std::string, bool>> args, intptr_t unique_id)
51 : category(std::move(category)), name(std::move(name)), actor(std::move(actor)), argNames(std::move(args)),
53 {
54 }
55
60 fn().m_name,
61 [fn](const JSONRPCRequest& request, UniValue& result, bool) { result = fn().HandleRequest(request); return true; },
62 fn().GetArgNames(),
63 intptr_t(fn))
64 {
65 }
66
67 std::string category;
68 std::string name;
79 std::vector<std::pair<std::string, bool>> argNames;
80 intptr_t unique_id;
81};
82
87{
88private:
89 std::map<std::string, std::vector<const CRPCCommand*>> mapCommands;
90public:
91 CRPCTable();
92 std::string help(const std::string& name, const JSONRPCRequest& helpreq) const;
93
100 UniValue execute(const JSONRPCRequest &request) const;
101
106 std::vector<std::string> listCommands() const;
107
111 UniValue dumpArgMap(const JSONRPCRequest& request) const;
112
125 void appendCommand(const std::string& name, const CRPCCommand* pcmd);
126 bool removeCommand(const std::string& name, const CRPCCommand* pcmd);
127};
128
129bool IsDeprecatedRPCEnabled(const std::string& method);
130
131extern CRPCTable tableRPC;
132
133void StartRPC();
134void InterruptRPC();
135void StopRPC();
136UniValue JSONRPCExec(const JSONRPCRequest& jreq, bool catch_errors);
137
138#endif // BITCOIN_RPC_SERVER_H
ArgsManager & args
Definition: bitcoind.cpp:277
std::string category
Definition: server.h:67
CRPCCommand(std::string category, std::string name, Actor actor, std::vector< std::pair< std::string, bool > > args, intptr_t unique_id)
Constructor taking Actor callback supporting multiple handlers.
Definition: server.h:50
intptr_t unique_id
Definition: server.h:80
std::vector< std::pair< std::string, bool > > argNames
List of method arguments and whether they are named-only.
Definition: server.h:79
std::string name
Definition: server.h:68
std::function< bool(const JSONRPCRequest &request, UniValue &result, bool last_handler)> Actor
RPC method handler reading request and assigning result.
Definition: server.h:47
Actor actor
Definition: server.h:69
CRPCCommand(std::string category, RpcMethodFnType fn)
Simplified constructor taking plain RpcMethodFnType function pointer.
Definition: server.h:57
RPC command dispatcher.
Definition: server.h:87
CRPCTable()
Definition: server.cpp:248
std::map< std::string, std::vector< const CRPCCommand * > > mapCommands
Definition: server.h:89
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
Definition: server.cpp:262
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:521
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
Definition: server.cpp:484
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:255
std::string help(const std::string &name, const JSONRPCRequest &helpreq) const
Definition: server.cpp:68
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:529
const char * name
Definition: rest.cpp:50
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:341
void SetRPCWarmupFinished()
Definition: server.cpp:326
void StartRPC()
Definition: server.cpp:275
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:333
RPCHelpMan(* RpcMethodFnType)()
Definition: server.h:39
void StopRPC()
Definition: server.cpp:292
bool IsRPCRunning()
Query whether RPC is running.
Definition: server.cpp:304
void SetRPCWarmupStarting()
Definition: server.cpp:320
void InterruptRPC()
Definition: server.cpp:281
UniValue JSONRPCExec(const JSONRPCRequest &jreq, bool catch_errors)
Definition: server.cpp:348
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
Definition: server.cpp:314
CRPCTable tableRPC
Definition: server.cpp:546
void RpcInterruptionPoint()
Throw JSONRPCError if RPC is not running.
Definition: server.cpp:309