Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
rpc
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
19
class
CRPCCommand
;
20
22
bool
IsRPCRunning
();
23
25
void
RpcInterruptionPoint
();
26
31
void
SetRPCWarmupStatus
(
const
std::string& newStatus);
32
void
SetRPCWarmupStarting
();
33
/* Mark warmup as done. RPC calls will be processed from now on. */
34
void
SetRPCWarmupFinished
();
35
36
/* returns the current warmup state. */
37
bool
RPCIsInWarmup
(std::string *outStatus);
38
39
typedef
RPCHelpMan
(*
RpcMethodFnType
)();
40
41
class
CRPCCommand
42
{
43
public
:
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
)),
52
unique_id
(
unique_id
)
53
{
54
}
55
57
CRPCCommand
(std::string
category
,
RpcMethodFnType
fn)
58
:
CRPCCommand
(
59
category
,
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
;
69
Actor
actor
;
79
std::vector<std::pair<std::string, bool>>
argNames
;
80
intptr_t
unique_id
;
81
};
82
86
class
CRPCTable
87
{
88
private
:
89
std::map<std::string, std::vector<const CRPCCommand*>>
mapCommands
;
90
public
:
91
CRPCTable
();
92
std::string
help
(std::string_view
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
129
bool
IsDeprecatedRPCEnabled
(
const
std::string& method);
130
131
extern
CRPCTable
tableRPC
;
132
133
void
StartRPC
();
134
void
InterruptRPC
();
135
void
StopRPC
();
136
UniValue
JSONRPCExec
(
const
JSONRPCRequest
& jreq,
bool
catch_errors);
137
138
#endif
// BITCOIN_RPC_SERVER_H
args
ArgsManager & args
Definition
bitcoind.cpp:277
CRPCCommand
Definition
server.h:42
CRPCCommand::category
std::string category
Definition
server.h:67
CRPCCommand::CRPCCommand
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
CRPCCommand::unique_id
intptr_t unique_id
Definition
server.h:80
CRPCCommand::argNames
std::vector< std::pair< std::string, bool > > argNames
Definition
server.h:79
CRPCCommand::name
std::string name
Definition
server.h:68
CRPCCommand::Actor
std::function< bool(const JSONRPCRequest &request, UniValue &result, bool last_handler)> Actor
Definition
server.h:47
CRPCCommand::actor
Actor actor
Definition
server.h:69
CRPCCommand::CRPCCommand
CRPCCommand(std::string category, RpcMethodFnType fn)
Simplified constructor taking plain RpcMethodFnType function pointer.
Definition
server.h:57
CRPCTable
RPC command dispatcher.
Definition
server.h:87
CRPCTable::CRPCTable
CRPCTable()
Definition
server.cpp:246
CRPCTable::mapCommands
std::map< std::string, std::vector< const CRPCCommand * > > mapCommands
Definition
server.h:89
CRPCTable::removeCommand
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
Definition
server.cpp:260
CRPCTable::listCommands
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition
server.cpp:519
CRPCTable::execute
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
Definition
server.cpp:482
CRPCTable::appendCommand
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition
server.cpp:253
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:527
JSONRPCRequest
Definition
request.h:53
RPCHelpMan
Definition
util.h:419
UniValue
Definition
univalue.h:22
std
Definition
common.h:29
request.h
name
const char * name
Definition
rest.cpp:48
help
static RPCHelpMan help()
Definition
server.cpp:119
tableRPC
CRPCTable tableRPC
Definition
server.cpp:544
IsDeprecatedRPCEnabled
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition
server.cpp:339
SetRPCWarmupFinished
void SetRPCWarmupFinished()
Definition
server.cpp:324
StartRPC
void StartRPC()
Definition
server.cpp:273
RPCIsInWarmup
bool RPCIsInWarmup(std::string *outStatus)
Definition
server.cpp:331
RpcMethodFnType
RPCHelpMan(* RpcMethodFnType)()
Definition
server.h:39
StopRPC
void StopRPC()
Definition
server.cpp:290
IsRPCRunning
bool IsRPCRunning()
Query whether RPC is running.
Definition
server.cpp:302
SetRPCWarmupStarting
void SetRPCWarmupStarting()
Definition
server.cpp:318
InterruptRPC
void InterruptRPC()
Definition
server.cpp:279
JSONRPCExec
UniValue JSONRPCExec(const JSONRPCRequest &jreq, bool catch_errors)
Definition
server.cpp:346
SetRPCWarmupStatus
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
Definition
server.cpp:312
RpcInterruptionPoint
void RpcInterruptionPoint()
Throw JSONRPCError if RPC is not running.
Definition
server.cpp:307
univalue.h
Generated on
for Bitcoin Core by
1.17.0