Bitcoin ABC 0.30.5
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
8#include <common/args.h>
9#include <net_processing.h>
10#include <node/context.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
20
21NodeContext &EnsureAnyNodeContext(const std::any &context) {
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 if (!node.mempool) {
32 "Mempool disabled or instance not found");
33 }
34 return *node.mempool;
35}
36
37CTxMemPool &EnsureAnyMemPool(const std::any &context) {
38 return EnsureMemPool(EnsureAnyNodeContext(context));
39}
40
42 if (!node.args) {
43 throw JSONRPCError(RPC_INTERNAL_ERROR, "Node args not found");
44 }
45 return *node.args;
46}
47
48ArgsManager &EnsureAnyArgsman(const std::any &context) {
49 return EnsureArgsman(EnsureAnyNodeContext(context));
50}
51
53 if (!node.chainman) {
54 throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found");
55 }
56 return *node.chainman;
57}
58
59ChainstateManager &EnsureAnyChainman(const std::any &context) {
60 return EnsureChainman(EnsureAnyNodeContext(context));
61}
62
64 if (!node.connman) {
65 throw JSONRPCError(
67 "Error: Peer-to-peer functionality missing or disabled");
68 }
69 return *node.connman;
70}
71
73 if (!node.peerman) {
74 throw JSONRPCError(
76 "Error: Peer-to-peer functionality missing or disabled");
77 }
78 return *node.peerman;
79}
80
82 if (!node.avalanche) {
84 "Error: Avalanche processor missing or disabled");
85 }
86 return *node.avalanche;
87}
Definition: net.h:856
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:212
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1219
Definition: init.h:28
UniValue JSONRPCError(int code, const std::string &message)
Definition: request.cpp:58
@ RPC_CLIENT_MEMPOOL_DISABLED
Chain errors.
Definition: protocol.h:86
@ RPC_INTERNAL_ERROR
Definition: protocol.h:33
@ RPC_CLIENT_P2P_DISABLED
No valid connection manager instance found.
Definition: protocol.h:81
ChainstateManager & EnsureAnyChainman(const std::any &context)
Definition: server_util.cpp:59
NodeContext & EnsureAnyNodeContext(const std::any &context)
Definition: server_util.cpp:21
CTxMemPool & EnsureMemPool(const NodeContext &node)
Definition: server_util.cpp:29
PeerManager & EnsurePeerman(const NodeContext &node)
Definition: server_util.cpp:72
ChainstateManager & EnsureChainman(const NodeContext &node)
Definition: server_util.cpp:52
CTxMemPool & EnsureAnyMemPool(const std::any &context)
Definition: server_util.cpp:37
ArgsManager & EnsureArgsman(const NodeContext &node)
Definition: server_util.cpp:41
avalanche::Processor & EnsureAvalanche(const NodeContext &node)
Definition: server_util.cpp:81
CConnman & EnsureConnman(const NodeContext &node)
Definition: server_util.cpp:63
ArgsManager & EnsureAnyArgsman(const std::any &context)
Definition: server_util.cpp:48
NodeContext struct containing references to chain state and connection state.
Definition: context.h:43