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