1 // Copyright (c) 2019 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 <memory>
9 #include <vector>
10 
11 class BanMan;
12 class CConnman;
13 class CScheduler;
14 class CTxMemPool;
15 class PeerLogicValidation;
16 namespace interfaces {
17 class Chain;
18 class ChainClient;
19 } // namespace interfaces
20 
21 //! NodeContext struct containing references to chain state and connection
22 //! state.
23 //!
24 //! This is used by init, rpc, and test code to pass object references around
25 //! without needing to declare the same variables and parameters repeatedly, or
26 //! to use globals. More variables could be added to this struct (particularly
27 //! references to validation objects) to eliminate use of globals
28 //! and make code more modular and testable. The struct isn't intended to have
29 //! any member functions. It should just be a collection of references that can
30 //! be used without pulling in unwanted dependencies or functionality.
31 struct NodeContext {
32     std::unique_ptr<CConnman> connman;
33     CTxMemPool* mempool{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
34     std::unique_ptr<PeerLogicValidation> peer_logic;
35     std::unique_ptr<BanMan> banman;
36     std::unique_ptr<interfaces::Chain> chain;
37     std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
38     std::unique_ptr<CScheduler> scheduler;
39 
40     //! Declare default constructor and destructor that are not inline, so code
41     //! instantiating the NodeContext struct doesn't need to #include class
42     //! definitions for all the unique_ptr members.
43     NodeContext();
44     ~NodeContext();
45 };
46 
47 #endif // BITCOIN_NODE_CONTEXT_H
48