mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 13:02:38 +02:00

Currently it is an alias to the global ::mempool and should be used as follows. * Node code (validation and transaction relay) can use either ::mempool or node.mempool, whichever seems a better fit. * RPC code should use the added convenience getter EnsureMempool, which makes sure the mempool exists before use. This prepares the RPC code to a future where the mempool might be disabled at runtime or compile time. * Test code should use m_node.mempool directly, as the mempool is always initialized for tests.
46 lines
1.7 KiB
C++
46 lines
1.7 KiB
C++
// 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>
|
|
|
|
class BanMan;
|
|
class CConnman;
|
|
class CTxMemPool;
|
|
class PeerLogicValidation;
|
|
namespace interfaces {
|
|
class Chain;
|
|
class ChainClient;
|
|
} // namespace interfaces
|
|
|
|
//! 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
|
|
//! references to validation objects) to eliminate use of globals
|
|
//! 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.
|
|
struct NodeContext {
|
|
std::unique_ptr<CConnman> connman;
|
|
CTxMemPool* mempool{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
|
|
std::unique_ptr<PeerLogicValidation> peer_logic;
|
|
std::unique_ptr<BanMan> banman;
|
|
std::unique_ptr<interfaces::Chain> chain;
|
|
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
|
|
|
//! 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();
|
|
};
|
|
|
|
#endif // BITCOIN_NODE_CONTEXT_H
|