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