mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-26 00:22:42 +02: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:
10
src/node/context.cpp
Normal file
10
src/node/context.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// 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.
|
||||
|
||||
#include <node/context.h>
|
||||
|
||||
#include <interfaces/chain.h>
|
||||
|
||||
NodeContext::NodeContext() {}
|
||||
NodeContext::~NodeContext() {}
|
@@ -13,11 +13,26 @@ class Chain;
|
||||
class ChainClient;
|
||||
} // namespace interfaces
|
||||
|
||||
//! Pointers to interfaces used during init and destroyed on shutdown.
|
||||
//! 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 and mempool 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<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
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include <consensus/validation.h>
|
||||
#include <net.h>
|
||||
#include <net_processing.h>
|
||||
#include <node/context.h>
|
||||
#include <util/validation.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
@@ -13,7 +14,7 @@
|
||||
|
||||
#include <future>
|
||||
|
||||
TransactionError BroadcastTransaction(const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
|
||||
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
|
||||
{
|
||||
// BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
|
||||
// g_connman is assigned both before chain clients and before RPC server is accepting calls,
|
||||
|
@@ -9,6 +9,8 @@
|
||||
#include <primitives/transaction.h>
|
||||
#include <util/error.h>
|
||||
|
||||
struct NodeContext;
|
||||
|
||||
/**
|
||||
* Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
|
||||
*
|
||||
@@ -18,6 +20,7 @@
|
||||
* NOT be set while cs_main, cs_mempool or cs_wallet are held to avoid
|
||||
* deadlock.
|
||||
*
|
||||
* @param[in] node reference to node context
|
||||
* @param[in] tx the transaction to broadcast
|
||||
* @param[out] &err_string reference to std::string to fill with error string if available
|
||||
* @param[in] max_tx_fee reject txs with fees higher than this (if 0, accept any fee)
|
||||
@@ -25,6 +28,6 @@
|
||||
* @param[in] wait_callback, wait until callbacks have been processed to avoid stale result due to a sequentially RPC.
|
||||
* return error
|
||||
*/
|
||||
NODISCARD TransactionError BroadcastTransaction(CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback);
|
||||
NODISCARD TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback);
|
||||
|
||||
#endif // BITCOIN_NODE_TRANSACTION_H
|
||||
|
Reference in New Issue
Block a user