Bitcoin ABC
0.28.12
P2P Digital Currency
src
rpc
server_util.cpp
Go to the documentation of this file.
1
// Copyright (c) 2021 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <
rpc/server_util.h
>
6
7
#include <
net_processing.h
>
8
#include <
node/context.h
>
9
#include <
rpc/protocol.h
>
10
#include <
rpc/request.h
>
11
#include <
txmempool.h
>
12
#include <
util/system.h
>
13
#include <validation.h>
14
15
#include <any>
16
17
using
node::NodeContext
;
18
19
NodeContext
&
EnsureAnyNodeContext
(
const
std::any &context) {
20
auto
node_context = util::AnyPtr<NodeContext>(context);
21
if
(!node_context) {
22
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node context not found"
);
23
}
24
return
*node_context;
25
}
26
27
CTxMemPool
&
EnsureMemPool
(
const
NodeContext
&
node
) {
28
if
(!
node
.mempool) {
29
throw
JSONRPCError
(
RPC_CLIENT_MEMPOOL_DISABLED
,
30
"Mempool disabled or instance not found"
);
31
}
32
return
*
node
.mempool;
33
}
34
35
CTxMemPool
&
EnsureAnyMemPool
(
const
std::any &context) {
36
return
EnsureMemPool
(
EnsureAnyNodeContext
(context));
37
}
38
39
ArgsManager
&
EnsureArgsman
(
const
NodeContext
&
node
) {
40
if
(!
node
.args) {
41
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node args not found"
);
42
}
43
return
*
node
.args;
44
}
45
46
ArgsManager
&
EnsureAnyArgsman
(
const
std::any &context) {
47
return
EnsureArgsman
(
EnsureAnyNodeContext
(context));
48
}
49
50
ChainstateManager
&
EnsureChainman
(
const
NodeContext
&
node
) {
51
if
(!
node
.chainman) {
52
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node chainman not found"
);
53
}
54
return
*
node
.chainman;
55
}
56
57
ChainstateManager
&
EnsureAnyChainman
(
const
std::any &context) {
58
return
EnsureChainman
(
EnsureAnyNodeContext
(context));
59
}
60
61
CConnman
&
EnsureConnman
(
const
NodeContext
&
node
) {
62
if
(!
node
.connman) {
63
throw
JSONRPCError
(
64
RPC_CLIENT_P2P_DISABLED
,
65
"Error: Peer-to-peer functionality missing or disabled"
);
66
}
67
return
*
node
.connman;
68
}
69
70
PeerManager
&
EnsurePeerman
(
const
NodeContext
&
node
) {
71
if
(!
node
.peerman) {
72
throw
JSONRPCError
(
73
RPC_CLIENT_P2P_DISABLED
,
74
"Error: Peer-to-peer functionality missing or disabled"
);
75
}
76
return
*
node
.peerman;
77
}
ArgsManager
Definition:
system.h:154
CConnman
Definition:
net.h:845
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition:
txmempool.h:209
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition:
validation.h:1157
PeerManager
Definition:
net_processing.h:52
node
Definition:
init.h:28
net_processing.h
context.h
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition:
request.cpp:57
request.h
protocol.h
RPC_CLIENT_MEMPOOL_DISABLED
@ RPC_CLIENT_MEMPOOL_DISABLED
Chain errors.
Definition:
protocol.h:86
RPC_INTERNAL_ERROR
@ RPC_INTERNAL_ERROR
Definition:
protocol.h:33
RPC_CLIENT_P2P_DISABLED
@ RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition:
protocol.h:81
EnsureArgsman
ArgsManager & EnsureArgsman(const NodeContext &node)
Definition:
server_util.cpp:39
EnsureAnyArgsman
ArgsManager & EnsureAnyArgsman(const std::any &context)
Definition:
server_util.cpp:46
EnsureAnyChainman
ChainstateManager & EnsureAnyChainman(const std::any &context)
Definition:
server_util.cpp:57
EnsureAnyMemPool
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition:
server_util.cpp:35
EnsureAnyNodeContext
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition:
server_util.cpp:19
EnsureConnman
CConnman & EnsureConnman(const NodeContext &node)
Definition:
server_util.cpp:61
EnsurePeerman
PeerManager & EnsurePeerman(const NodeContext &node)
Definition:
server_util.cpp:70
EnsureMemPool
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition:
server_util.cpp:27
EnsureChainman
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition:
server_util.cpp:50
server_util.h
node::NodeContext
NodeContext struct containing references to chain state and connection state.
Definition:
context.h:38
system.h
txmempool.h
Generated on Thu Mar 28 2024 20:53:37 for Bitcoin ABC by
1.9.1