2021-12-30 14:36:57 -03:00
|
|
|
// Copyright (c) 2019-2021 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;
|
2021-09-10 21:16:37 -03:00
|
|
|
class AddrMan;
|
2020-07-28 13:12:50 -04:00
|
|
|
class CBlockPolicyEstimator;
|
2019-09-17 19:59:36 -03:00
|
|
|
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;
|
2020-08-29 05:31:11 -04:00
|
|
|
class PeerManager;
|
2019-09-17 18:11:31 -03:00
|
|
|
namespace interfaces {
|
|
|
|
class Chain;
|
|
|
|
class ChainClient;
|
2017-12-05 17:57:12 -03:00
|
|
|
class Init;
|
2021-12-22 15:44:55 -03:00
|
|
|
class WalletLoader;
|
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 {
|
2017-12-05 17:57:12 -03:00
|
|
|
//! Init interface for initializing current process and connecting to other processes.
|
|
|
|
interfaces::Init* init{nullptr};
|
2021-09-10 21:16:37 -03:00
|
|
|
std::unique_ptr<AddrMan> addrman;
|
2019-09-17 19:59:36 -03:00
|
|
|
std::unique_ptr<CConnman> connman;
|
2020-07-19 14:30:46 -04:00
|
|
|
std::unique_ptr<CTxMemPool> mempool;
|
2020-07-28 13:12:50 -04:00
|
|
|
std::unique_ptr<CBlockPolicyEstimator> fee_estimator;
|
2020-08-29 05:31:11 -04:00
|
|
|
std::unique_ptr<PeerManager> peerman;
|
2020-10-06 18:35:11 -03:00
|
|
|
std::unique_ptr<ChainstateManager> chainman;
|
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.
|
2021-12-22 15:44:55 -03:00
|
|
|
interfaces::WalletLoader* wallet_loader{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
|