2020-04-16 13:14:08 -04:00
|
|
|
// Copyright (c) 2019-2020 The Bitcoin Core developers
|
2019-09-17 18:11:31 -03:00
|
|
|
// 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
|
|
|
|
|
2020-04-18 08:05:52 -04:00
|
|
|
#include <cassert>
|
2020-06-18 15:19:26 -04:00
|
|
|
#include <functional>
|
2019-09-17 18:11:31 -03:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-04-08 19:47:56 -04:00
|
|
|
class ArgsManager;
|
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;
|
2020-04-18 08:05:52 -04:00
|
|
|
class ChainstateManager;
|
2019-09-17 19:59:36 -03:00
|
|
|
class PeerLogicValidation;
|
2019-09-17 18:11:31 -03:00
|
|
|
namespace interfaces {
|
|
|
|
class Chain;
|
|
|
|
class ChainClient;
|
2020-05-28 09:48:30 -04:00
|
|
|
class WalletClient;
|
2019-09-17 18:11:31 -03:00
|
|
|
} // 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;
|
2020-04-18 08:05:52 -04:00
|
|
|
ChainstateManager* chainman{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<BanMan> banman;
|
2020-04-08 19:47:56 -04:00
|
|
|
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
|
2019-09-17 18:11:31 -03:00
|
|
|
std::unique_ptr<interfaces::Chain> chain;
|
2020-05-28 09:48:30 -04:00
|
|
|
//! List of all chain clients (wallet processes or other client) connected to node.
|
2019-09-17 18:11:31 -03:00
|
|
|
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
2020-05-28 09:48:30 -04:00
|
|
|
//! Reference to chain client that should used to load or create wallets
|
|
|
|
//! opened by the gui.
|
|
|
|
interfaces::WalletClient* wallet_client{nullptr};
|
2020-02-12 16:08:28 -03:00
|
|
|
std::unique_ptr<CScheduler> scheduler;
|
2020-06-18 15:19:26 -04:00
|
|
|
std::function<void()> rpc_interruption_point = [] {};
|
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
|