Bitcoin Core
27.99.0
P2P Digital Currency
src
rpc
server_util.cpp
Go to the documentation of this file.
1
// Copyright (c) 2021-2022 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 <
common/args.h
>
8
#include <
net_processing.h
>
9
#include <
node/context.h
>
10
#include <
policy/fees.h
>
11
#include <
rpc/protocol.h
>
12
#include <
rpc/request.h
>
13
#include <txmempool.h>
14
#include <
util/any.h
>
15
#include <validation.h>
16
17
#include <any>
18
19
using
node::NodeContext
;
20
21
NodeContext
&
EnsureAnyNodeContext
(
const
std::any& context)
22
{
23
auto
node_context = util::AnyPtr<NodeContext>(context);
24
if
(!node_context) {
25
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node context not found"
);
26
}
27
return
*node_context;
28
}
29
30
CTxMemPool
&
EnsureMemPool
(
const
NodeContext
&
node
)
31
{
32
if
(!
node
.mempool) {
33
throw
JSONRPCError
(
RPC_CLIENT_MEMPOOL_DISABLED
,
"Mempool disabled or instance not found"
);
34
}
35
return
*
node
.mempool;
36
}
37
38
CTxMemPool
&
EnsureAnyMemPool
(
const
std::any& context)
39
{
40
return
EnsureMemPool
(
EnsureAnyNodeContext
(context));
41
}
42
43
44
BanMan
&
EnsureBanman
(
const
NodeContext
&
node
)
45
{
46
if
(!
node
.banman) {
47
throw
JSONRPCError
(
RPC_DATABASE_ERROR
,
"Error: Ban database not loaded"
);
48
}
49
return
*
node
.banman;
50
}
51
52
BanMan
&
EnsureAnyBanman
(
const
std::any& context)
53
{
54
return
EnsureBanman
(
EnsureAnyNodeContext
(context));
55
}
56
57
ArgsManager
&
EnsureArgsman
(
const
NodeContext
&
node
)
58
{
59
if
(!
node
.args) {
60
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node args not found"
);
61
}
62
return
*
node
.args;
63
}
64
65
ArgsManager
&
EnsureAnyArgsman
(
const
std::any& context)
66
{
67
return
EnsureArgsman
(
EnsureAnyNodeContext
(context));
68
}
69
70
ChainstateManager
&
EnsureChainman
(
const
NodeContext
&
node
)
71
{
72
if
(!
node
.chainman) {
73
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node chainman not found"
);
74
}
75
return
*
node
.chainman;
76
}
77
78
ChainstateManager
&
EnsureAnyChainman
(
const
std::any& context)
79
{
80
return
EnsureChainman
(
EnsureAnyNodeContext
(context));
81
}
82
83
CBlockPolicyEstimator
&
EnsureFeeEstimator
(
const
NodeContext
&
node
)
84
{
85
if
(!
node
.fee_estimator) {
86
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Fee estimation disabled"
);
87
}
88
return
*
node
.fee_estimator;
89
}
90
91
CBlockPolicyEstimator
&
EnsureAnyFeeEstimator
(
const
std::any& context)
92
{
93
return
EnsureFeeEstimator
(
EnsureAnyNodeContext
(context));
94
}
95
96
CConnman
&
EnsureConnman
(
const
NodeContext
&
node
)
97
{
98
if
(!
node
.connman) {
99
throw
JSONRPCError
(
RPC_CLIENT_P2P_DISABLED
,
"Error: Peer-to-peer functionality missing or disabled"
);
100
}
101
return
*
node
.connman;
102
}
103
104
PeerManager
&
EnsurePeerman
(
const
NodeContext
&
node
)
105
{
106
if
(!
node
.peerman) {
107
throw
JSONRPCError
(
RPC_CLIENT_P2P_DISABLED
,
"Error: Peer-to-peer functionality missing or disabled"
);
108
}
109
return
*
node
.peerman;
110
}
111
112
AddrMan
&
EnsureAddrman
(
const
NodeContext
&
node
)
113
{
114
if
(!
node
.addrman) {
115
throw
JSONRPCError
(
RPC_CLIENT_P2P_DISABLED
,
"Error: Address manager functionality missing or disabled"
);
116
}
117
return
*
node
.addrman;
118
}
119
120
AddrMan
&
EnsureAnyAddrman
(
const
std::any& context)
121
{
122
return
EnsureAddrman
(
EnsureAnyNodeContext
(context));
123
}
any.h
args.h
AddrMan
Stochastic address manager.
Definition:
addrman.h:88
ArgsManager
Definition:
args.h:97
BanMan
Definition:
banman.h:59
CBlockPolicyEstimator
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Definition:
fees.h:149
CConnman
Definition:
net.h:1036
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition:
txmempool.h:302
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition:
validation.h:850
PeerManager
Definition:
net_processing.h:47
node
Definition:
init.h:25
net_processing.h
context.h
fees.h
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition:
request.cpp:58
request.h
protocol.h
RPC_CLIENT_MEMPOOL_DISABLED
@ RPC_CLIENT_MEMPOOL_DISABLED
Chain errors.
Definition:
protocol.h:68
RPC_INTERNAL_ERROR
@ RPC_INTERNAL_ERROR
Definition:
protocol.h:35
RPC_DATABASE_ERROR
@ RPC_DATABASE_ERROR
Database error.
Definition:
protocol.h:44
RPC_CLIENT_P2P_DISABLED
@ RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition:
protocol.h:64
EnsureArgsman
ArgsManager & EnsureArgsman(const NodeContext &node)
Definition:
server_util.cpp:57
EnsureAnyArgsman
ArgsManager & EnsureAnyArgsman(const std::any &context)
Definition:
server_util.cpp:65
EnsureBanman
BanMan & EnsureBanman(const NodeContext &node)
Definition:
server_util.cpp:44
EnsureAnyAddrman
AddrMan & EnsureAnyAddrman(const std::any &context)
Definition:
server_util.cpp:120
EnsureAnyChainman
ChainstateManager & EnsureAnyChainman(const std::any &context)
Definition:
server_util.cpp:78
EnsureAnyBanman
BanMan & EnsureAnyBanman(const std::any &context)
Definition:
server_util.cpp:52
EnsureAnyMemPool
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition:
server_util.cpp:38
EnsureAnyNodeContext
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition:
server_util.cpp:21
EnsureAnyFeeEstimator
CBlockPolicyEstimator & EnsureAnyFeeEstimator(const std::any &context)
Definition:
server_util.cpp:91
EnsureConnman
CConnman & EnsureConnman(const NodeContext &node)
Definition:
server_util.cpp:96
EnsurePeerman
PeerManager & EnsurePeerman(const NodeContext &node)
Definition:
server_util.cpp:104
EnsureFeeEstimator
CBlockPolicyEstimator & EnsureFeeEstimator(const NodeContext &node)
Definition:
server_util.cpp:83
EnsureAddrman
AddrMan & EnsureAddrman(const NodeContext &node)
Definition:
server_util.cpp:112
EnsureMemPool
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition:
server_util.cpp:30
EnsureChainman
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition:
server_util.cpp:70
server_util.h
node::NodeContext
NodeContext struct containing references to chain state and connection state.
Definition:
context.h:49
Generated on Wed Apr 24 2024 20:02:52 for Bitcoin Core by
1.9.1