mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Pass NodeContext, ConnMan, BanMan references more places
So g_connman and g_banman globals can be removed next commit.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <net.h>
|
||||
#include <net_processing.h>
|
||||
#include <node/coin.h>
|
||||
#include <node/context.h>
|
||||
#include <node/transaction.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/policy.h>
|
||||
@@ -238,6 +239,7 @@ public:
|
||||
class ChainImpl : public Chain
|
||||
{
|
||||
public:
|
||||
explicit ChainImpl(NodeContext& node) : m_node(node) {}
|
||||
std::unique_ptr<Chain::Lock> lock(bool try_lock) override
|
||||
{
|
||||
auto result = MakeUnique<LockImpl>(::cs_main, "cs_main", __FILE__, __LINE__, try_lock);
|
||||
@@ -286,7 +288,7 @@ public:
|
||||
}
|
||||
bool broadcastTransaction(const CTransactionRef& tx, std::string& err_string, const CAmount& max_tx_fee, bool relay) override
|
||||
{
|
||||
const TransactionError err = BroadcastTransaction(tx, err_string, max_tx_fee, relay, /*wait_callback*/ false);
|
||||
const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback*/ false);
|
||||
// Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures.
|
||||
// Note: this will need to be updated if BroadcastTransactions() is updated to return other non-mempool failures
|
||||
// that Chain clients do not need to know about.
|
||||
@@ -378,9 +380,10 @@ public:
|
||||
notifications.TransactionAddedToMempool(entry.GetSharedTx());
|
||||
}
|
||||
}
|
||||
NodeContext& m_node;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Chain> MakeChain() { return MakeUnique<ChainImpl>(); }
|
||||
std::unique_ptr<Chain> MakeChain(NodeContext& node) { return MakeUnique<ChainImpl>(node); }
|
||||
|
||||
} // namespace interfaces
|
||||
|
||||
@@ -24,6 +24,7 @@ class uint256;
|
||||
enum class RBFTransactionState;
|
||||
struct CBlockLocator;
|
||||
struct FeeCalculation;
|
||||
struct NodeContext;
|
||||
|
||||
namespace interfaces {
|
||||
|
||||
@@ -291,7 +292,7 @@ public:
|
||||
};
|
||||
|
||||
//! Return implementation of Chain interface.
|
||||
std::unique_ptr<Chain> MakeChain();
|
||||
std::unique_ptr<Chain> MakeChain(NodeContext& node);
|
||||
|
||||
//! Return implementation of ChainClient interface for a wallet client. This
|
||||
//! function will be undefined in builds where ENABLE_WALLET is false.
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <net_processing.h>
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
#include <node/context.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/settings.h>
|
||||
@@ -52,7 +53,6 @@ namespace {
|
||||
class NodeImpl : public Node
|
||||
{
|
||||
public:
|
||||
NodeImpl() { m_context.chain = MakeChain(); }
|
||||
void initError(const std::string& message) override { InitError(message); }
|
||||
bool parseParameters(int argc, const char* const argv[], std::string& error) override
|
||||
{
|
||||
@@ -75,10 +75,14 @@ public:
|
||||
return AppInitBasicSetup() && AppInitParameterInteraction() && AppInitSanityChecks() &&
|
||||
AppInitLockDataDirectory();
|
||||
}
|
||||
bool appInitMain() override { return AppInitMain(m_context); }
|
||||
bool appInitMain() override
|
||||
{
|
||||
m_context.chain = MakeChain(m_context);
|
||||
return AppInitMain(m_context);
|
||||
}
|
||||
void appShutdown() override
|
||||
{
|
||||
Interrupt();
|
||||
Interrupt(m_context);
|
||||
Shutdown(m_context);
|
||||
}
|
||||
void startShutdown() override { StartShutdown(); }
|
||||
@@ -315,6 +319,7 @@ public:
|
||||
/* verification progress is unused when a header was received */ 0);
|
||||
}));
|
||||
}
|
||||
NodeContext* context() override { return &m_context; }
|
||||
NodeContext m_context;
|
||||
};
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class RPCTimerInterface;
|
||||
class UniValue;
|
||||
class proxyType;
|
||||
struct CNodeStateStats;
|
||||
struct NodeContext;
|
||||
enum class WalletCreationStatus;
|
||||
|
||||
namespace interfaces {
|
||||
@@ -254,6 +255,9 @@ public:
|
||||
using NotifyHeaderTipFn =
|
||||
std::function<void(bool initial_download, int height, int64_t block_time, double verification_progress)>;
|
||||
virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
|
||||
|
||||
//! Return pointer to internal chain interface, useful for testing.
|
||||
virtual NodeContext* context() { return nullptr; }
|
||||
};
|
||||
|
||||
//! Return implementation of Node interface.
|
||||
|
||||
Reference in New Issue
Block a user