Bitcoin Core
24.1.0
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 <
policy/fees.h
>
10
#include <
rpc/protocol.h
>
11
#include <
rpc/request.h
>
12
#include <
txmempool.h
>
13
#include <
util/system.h
>
14
#include <validation.h>
15
16
#include <any>
17
18
using
node::NodeContext
;
19
20
NodeContext
&
EnsureAnyNodeContext
(
const
std::any&
context
)
21
{
22
auto
node_context = util::AnyPtr<NodeContext>(
context
);
23
if
(!node_context) {
24
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node context not found"
);
25
}
26
return
*node_context;
27
}
28
29
CTxMemPool
&
EnsureMemPool
(
const
NodeContext
&
node
)
30
{
31
if
(!
node
.mempool) {
32
throw
JSONRPCError
(
RPC_CLIENT_MEMPOOL_DISABLED
,
"Mempool disabled or instance not found"
);
33
}
34
return
*
node
.mempool;
35
}
36
37
CTxMemPool
&
EnsureAnyMemPool
(
const
std::any&
context
)
38
{
39
return
EnsureMemPool
(
EnsureAnyNodeContext
(
context
));
40
}
41
42
ArgsManager
&
EnsureArgsman
(
const
NodeContext
&
node
)
43
{
44
if
(!
node
.args) {
45
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node args not found"
);
46
}
47
return
*
node
.args;
48
}
49
50
ArgsManager
&
EnsureAnyArgsman
(
const
std::any&
context
)
51
{
52
return
EnsureArgsman
(
EnsureAnyNodeContext
(
context
));
53
}
54
55
ChainstateManager
&
EnsureChainman
(
const
NodeContext
&
node
)
56
{
57
if
(!
node
.chainman) {
58
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Node chainman not found"
);
59
}
60
return
*
node
.chainman;
61
}
62
63
ChainstateManager
&
EnsureAnyChainman
(
const
std::any&
context
)
64
{
65
return
EnsureChainman
(
EnsureAnyNodeContext
(
context
));
66
}
67
68
CBlockPolicyEstimator
&
EnsureFeeEstimator
(
const
NodeContext
&
node
)
69
{
70
if
(!
node
.fee_estimator) {
71
throw
JSONRPCError
(
RPC_INTERNAL_ERROR
,
"Fee estimation disabled"
);
72
}
73
return
*
node
.fee_estimator;
74
}
75
76
CBlockPolicyEstimator
&
EnsureAnyFeeEstimator
(
const
std::any&
context
)
77
{
78
return
EnsureFeeEstimator
(
EnsureAnyNodeContext
(
context
));
79
}
80
81
CConnman
&
EnsureConnman
(
const
NodeContext
&
node
)
82
{
83
if
(!
node
.connman) {
84
throw
JSONRPCError
(
RPC_CLIENT_P2P_DISABLED
,
"Error: Peer-to-peer functionality missing or disabled"
);
85
}
86
return
*
node
.connman;
87
}
88
89
PeerManager
&
EnsurePeerman
(
const
NodeContext
&
node
)
90
{
91
if
(!
node
.peerman) {
92
throw
JSONRPCError
(
RPC_CLIENT_P2P_DISABLED
,
"Error: Peer-to-peer functionality missing or disabled"
);
93
}
94
return
*
node
.peerman;
95
}
net_processing.h
EnsureMemPool
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition:
server_util.cpp:29
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition:
validation.h:799
RPC_INTERNAL_ERROR
Definition:
protocol.h:35
ArgsManager
Definition:
system.h:172
context.h
RPC_CLIENT_MEMPOOL_DISABLED
Chain errors.
Definition:
protocol.h:68
protocol.h
node::NodeContext
NodeContext struct containing references to chain state and connection state.
Definition:
context.h:43
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition:
request.cpp:56
txmempool.h
CBlockPolicyEstimator
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Definition:
fees.h:132
PeerManager
Definition:
net_processing.h:41
EnsureAnyFeeEstimator
CBlockPolicyEstimator & EnsureAnyFeeEstimator(const std::any &context)
Definition:
server_util.cpp:76
EnsureFeeEstimator
CBlockPolicyEstimator & EnsureFeeEstimator(const NodeContext &node)
Definition:
server_util.cpp:68
context
WalletContext context
Definition:
notifications.cpp:37
CConnman
Definition:
net.h:666
EnsureAnyMemPool
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition:
server_util.cpp:37
fees.h
node
Definition:
init.h:25
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition:
txmempool.h:431
server_util.h
EnsureChainman
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition:
server_util.cpp:55
system.h
request.h
EnsureAnyArgsman
ArgsManager & EnsureAnyArgsman(const std::any &context)
Definition:
server_util.cpp:50
EnsurePeerman
PeerManager & EnsurePeerman(const NodeContext &node)
Definition:
server_util.cpp:89
RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition:
protocol.h:64
EnsureAnyChainman
ChainstateManager & EnsureAnyChainman(const std::any &context)
Definition:
server_util.cpp:63
EnsureAnyNodeContext
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition:
server_util.cpp:20
EnsureArgsman
ArgsManager & EnsureArgsman(const NodeContext &node)
Definition:
server_util.cpp:42
EnsureConnman
CConnman & EnsureConnman(const NodeContext &node)
Definition:
server_util.cpp:81
Generated on Tue May 16 2023 12:00:00 for Bitcoin Core by
1.8.14