Branch data Line data Source code
1 : : // Copyright (c) 2019-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 : : #ifndef BITCOIN_NODE_CONTEXT_H 6 : : #define BITCOIN_NODE_CONTEXT_H 7 : : 8 : : #include <kernel/context.h> 9 : : 10 : : #include <atomic> 11 : : #include <cassert> 12 : : #include <cstdlib> 13 : : #include <functional> 14 : : #include <memory> 15 : : #include <vector> 16 : : 17 : : class ArgsManager; 18 : : class AddrMan; 19 : : class BanMan; 20 : : class BaseIndex; 21 : : class CBlockPolicyEstimator; 22 : : class CConnman; 23 : : class CScheduler; 24 : : class CTxMemPool; 25 : : class ChainstateManager; 26 : : class NetGroupManager; 27 : : class PeerManager; 28 : : namespace interfaces { 29 : : class Chain; 30 : : class ChainClient; 31 : : class Init; 32 : : class WalletLoader; 33 : : } // namespace interfaces 34 : : 35 : : namespace node { 36 : : class KernelNotifications; 37 : : 38 : : //! NodeContext struct containing references to chain state and connection 39 : : //! state. 40 : : //! 41 : : //! This is used by init, rpc, and test code to pass object references around 42 : : //! without needing to declare the same variables and parameters repeatedly, or 43 : : //! to use globals. More variables could be added to this struct (particularly 44 : : //! references to validation objects) to eliminate use of globals 45 : : //! and make code more modular and testable. The struct isn't intended to have 46 : : //! any member functions. It should just be a collection of references that can 47 : : //! be used without pulling in unwanted dependencies or functionality. 48 : : struct NodeContext { 49 : : //! libbitcoin_kernel context 50 : : std::unique_ptr<kernel::Context> kernel; 51 : : //! Init interface for initializing current process and connecting to other processes. 52 : : interfaces::Init* init{nullptr}; 53 : : std::unique_ptr<AddrMan> addrman; 54 : : std::unique_ptr<CConnman> connman; 55 : : std::unique_ptr<CTxMemPool> mempool; 56 : : std::unique_ptr<const NetGroupManager> netgroupman; 57 : : std::unique_ptr<CBlockPolicyEstimator> fee_estimator; 58 : : std::unique_ptr<PeerManager> peerman; 59 : : std::unique_ptr<ChainstateManager> chainman; 60 : : std::unique_ptr<BanMan> banman; 61 : : ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct 62 : : std::vector<BaseIndex*> indexes; // raw pointers because memory is not managed by this struct 63 : : std::unique_ptr<interfaces::Chain> chain; 64 : : //! List of all chain clients (wallet processes or other client) connected to node. 65 : : std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients; 66 : : //! Reference to chain client that should used to load or create wallets 67 : : //! opened by the gui. 68 : : interfaces::WalletLoader* wallet_loader{nullptr}; 69 : : std::unique_ptr<CScheduler> scheduler; 70 : 0 : std::function<void()> rpc_interruption_point = [] {}; 71 : : std::unique_ptr<KernelNotifications> notifications; 72 : : std::atomic<int> exit_status{EXIT_SUCCESS}; 73 : : 74 : : //! Declare default constructor and destructor that are not inline, so code 75 : : //! instantiating the NodeContext struct doesn't need to #include class 76 : : //! definitions for all the unique_ptr members. 77 : : NodeContext(); 78 : : ~NodeContext(); 79 : : }; 80 : : } // namespace node 81 : : 82 : : #endif // BITCOIN_NODE_CONTEXT_H