Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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}
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 init.h:28
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
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)
NodeContext & EnsureAnyNodeContext(const std::any &context)
CTxMemPool & EnsureMemPool(const NodeContext &node)
PeerManager & EnsurePeerman(const NodeContext &node)
ChainstateManager & EnsureChainman(const NodeContext &node)
CTxMemPool & EnsureAnyMemPool(const std::any &context)
ArgsManager & EnsureArgsman(const NodeContext &node)
avalanche::Processor & EnsureAvalanche(const NodeContext &node)
CConnman & EnsureConnman(const NodeContext &node)
ArgsManager & EnsureAnyArgsman(const std::any &context)
NodeContext struct containing references to chain state and connection state.
Definition context.h:43