Bitcoin Core  24.99.0
P2P Digital Currency
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 <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 }
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Definition: fees.h:133
Definition: net.h:666
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:316
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:802
Definition: init.h:25
WalletContext context
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:56
@ RPC_CLIENT_MEMPOOL_DISABLED
Chain errors.
Definition: protocol.h:68
@ RPC_INTERNAL_ERROR
Definition: protocol.h:35
@ RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition: protocol.h:64
ArgsManager & EnsureArgsman(const NodeContext &node)
Definition: server_util.cpp:42
ArgsManager & EnsureAnyArgsman(const std::any &context)
Definition: server_util.cpp:50
ChainstateManager & EnsureAnyChainman(const std::any &context)
Definition: server_util.cpp:63
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition: server_util.cpp:37
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:20
CBlockPolicyEstimator & EnsureAnyFeeEstimator(const std::any &context)
Definition: server_util.cpp:76
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:81
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:89
CBlockPolicyEstimator & EnsureFeeEstimator(const NodeContext &node)
Definition: server_util.cpp:68
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition: server_util.cpp:29
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition: server_util.cpp:55
NodeContext struct containing references to chain state and connection state.
Definition: context.h:43