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