Changeset View
Changeset View
Standalone View
Standalone View
src/node/context.h
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_NODE_CONTEXT_H | #ifndef BITCOIN_NODE_CONTEXT_H | ||||
#define BITCOIN_NODE_CONTEXT_H | #define BITCOIN_NODE_CONTEXT_H | ||||
#include <memory> | #include <memory> | ||||
#include <vector> | #include <vector> | ||||
class BanMan; | |||||
class CConnman; | |||||
class PeerLogicValidation; | |||||
namespace interfaces { | namespace interfaces { | ||||
class Chain; | class Chain; | ||||
class ChainClient; | class ChainClient; | ||||
} // namespace interfaces | } // namespace interfaces | ||||
//! NodeContext struct containing references to chain state and connection | //! NodeContext struct containing references to chain state and connection | ||||
//! state. | //! state. | ||||
//! | //! | ||||
//! This is used by init, rpc, and test code to pass object references around | //! This is used by init, rpc, and test code to pass object references around | ||||
//! without needing to declare the same variables and parameters repeatedly, or | //! without needing to declare the same variables and parameters repeatedly, or | ||||
//! to use globals. More variables could be added to this struct (particularly | //! to use globals. More variables could be added to this struct (particularly | ||||
//! references to validation and mempool objects) to eliminate use of globals | //! references to validation and mempool objects) to eliminate use of globals | ||||
//! and make code more modular and testable. The struct isn't intended to have | //! and make code more modular and testable. The struct isn't intended to have | ||||
//! any member functions. It should just be a collection of references that can | //! any member functions. It should just be a collection of references that can | ||||
//! be used without pulling in unwanted dependencies or functionality. | //! be used without pulling in unwanted dependencies or functionality. | ||||
struct NodeContext { | struct NodeContext { | ||||
std::unique_ptr<CConnman> connman; | |||||
std::unique_ptr<PeerLogicValidation> peer_logic; | |||||
std::unique_ptr<BanMan> banman; | |||||
std::unique_ptr<interfaces::Chain> chain; | std::unique_ptr<interfaces::Chain> chain; | ||||
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients; | std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients; | ||||
//! Declare default constructor and destructor that are not inline, so code | //! Declare default constructor and destructor that are not inline, so code | ||||
//! instantiating the NodeContext struct doesn't need to #include class | //! instantiating the NodeContext struct doesn't need to #include class | ||||
//! definitions for all the unique_ptr members. | //! definitions for all the unique_ptr members. | ||||
NodeContext(); | NodeContext(); | ||||
~NodeContext(); | ~NodeContext(); | ||||
}; | }; | ||||
#endif // BITCOIN_NODE_CONTEXT_H | #endif // BITCOIN_NODE_CONTEXT_H |