Bitcoin Core  22.99.0
P2P Digital Currency
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 
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 
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 
38 {
40 }
41 
43 {
44  if (!node.args) {
45  throw JSONRPCError(RPC_INTERNAL_ERROR, "Node args not found");
46  }
47  return *node.args;
48 }
49 
51 {
53 }
54 
56 {
57  if (!node.chainman) {
58  throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found");
59  }
60  return *node.chainman;
61 }
62 
64 {
66 }
67 
69 {
70  if (!node.fee_estimator) {
71  throw JSONRPCError(RPC_INTERNAL_ERROR, "Fee estimation disabled");
72  }
73  return *node.fee_estimator;
74 }
75 
77 {
79 }
80 
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 
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 }
RPC_INTERNAL_ERROR
@ RPC_INTERNAL_ERROR
Definition: protocol.h:35
RPC_CLIENT_P2P_DISABLED
@ RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition: protocol.h:64
EnsurePeerman
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:89
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:429
node::NodeContext
NodeContext struct containing references to chain state and connection state.
Definition: context.h:40
RPC_CLIENT_MEMPOOL_DISABLED
@ RPC_CLIENT_MEMPOOL_DISABLED
Chain errors.
Definition: protocol.h:68
protocol.h
EnsureAnyArgsman
ArgsManager & EnsureAnyArgsman(const std::any &context)
Definition: server_util.cpp:50
EnsureChainman
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition: server_util.cpp:55
EnsureAnyFeeEstimator
CBlockPolicyEstimator & EnsureAnyFeeEstimator(const std::any &context)
Definition: server_util.cpp:76
server_util.h
context.h
txmempool.h
EnsureAnyNodeContext
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:20
EnsureAnyChainman
ChainstateManager & EnsureAnyChainman(const std::any &context)
Definition: server_util.cpp:63
EnsureArgsman
ArgsManager & EnsureArgsman(const NodeContext &node)
Definition: server_util.cpp:42
CBlockPolicyEstimator
Definition: fees.h:131
context
WalletContext context
Definition: notifications.cpp:37
EnsureConnman
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:81
PeerManager
Definition: net_processing.h:37
request.h
net_processing.h
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:761
system.h
CConnman
Definition: net.h:741
fees.h
ArgsManager
Definition: system.h:158
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:51
EnsureMemPool
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition: server_util.cpp:29
node
Definition: init.h:22
EnsureFeeEstimator
CBlockPolicyEstimator & EnsureFeeEstimator(const NodeContext &node)
Definition: server_util.cpp:68
EnsureAnyMemPool
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition: server_util.cpp:37