2019-09-17 18:11:31 -03:00
|
|
|
// Copyright (c) 2019 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_NODE_CONTEXT_H
|
|
|
|
#define BITCOIN_NODE_CONTEXT_H
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-09-17 19:59:36 -03:00
|
|
|
class BanMan;
|
|
|
|
class CConnman;
|
2020-02-12 16:08:28 -03:00
|
|
|
class CScheduler;
|
2019-11-08 12:29:41 -03:00
|
|
|
class CTxMemPool;
|
2019-09-17 19:59:36 -03:00
|
|
|
class PeerLogicValidation;
|
2019-09-17 18:11:31 -03:00
|
|
|
namespace interfaces {
|
|
|
|
class Chain;
|
|
|
|
class ChainClient;
|
|
|
|
} // namespace interfaces
|
|
|
|
|
2019-09-17 19:28:03 -03:00
|
|
|
//! NodeContext struct containing references to chain state and connection
|
|
|
|
//! state.
|
|
|
|
//!
|
|
|
|
//! 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
|
|
|
|
//! to use globals. More variables could be added to this struct (particularly
|
2019-11-08 12:29:41 -03:00
|
|
|
//! references to validation objects) to eliminate use of globals
|
2019-09-17 19:28:03 -03:00
|
|
|
//! 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
|
|
|
|
//! be used without pulling in unwanted dependencies or functionality.
|
2019-11-08 12:29:41 -03:00
|
|
|
struct NodeContext {
|
2019-09-17 19:59:36 -03:00
|
|
|
std::unique_ptr<CConnman> connman;
|
2019-11-08 12:29:41 -03:00
|
|
|
CTxMemPool* mempool{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
|
2019-09-17 19:59:36 -03:00
|
|
|
std::unique_ptr<PeerLogicValidation> peer_logic;
|
|
|
|
std::unique_ptr<BanMan> banman;
|
2019-09-17 18:11:31 -03:00
|
|
|
std::unique_ptr<interfaces::Chain> chain;
|
|
|
|
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
2020-02-12 16:08:28 -03:00
|
|
|
std::unique_ptr<CScheduler> scheduler;
|
2019-09-17 19:28:03 -03:00
|
|
|
|
|
|
|
//! Declare default constructor and destructor that are not inline, so code
|
|
|
|
//! instantiating the NodeContext struct doesn't need to #include class
|
|
|
|
//! definitions for all the unique_ptr members.
|
|
|
|
NodeContext();
|
|
|
|
~NodeContext();
|
2019-09-17 18:11:31 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BITCOIN_NODE_CONTEXT_H
|