Merge bitcoin/bitcoin#23497: Add src/node/ and src/wallet/ code to node:: and wallet:: namespaces

e5b6aef61221b621ad77b5f075a16897e08835bf Move CBlockFileInfo::ToString method where class is declared (Russell Yanofsky)
f7086fd8ff084ab0dd656d75b7485e59263bdfd8 Add src/wallet/* code to wallet:: namespace (Russell Yanofsky)
90fc8b089d591cabff60ee829a33f96c37fd27ba Add src/node/* code to node:: namespace (Russell Yanofsky)

Pull request description:

  There are no code changes, this is just adding `namespace` and `using` declarations and `node::` or `wallet::` qualifiers in some places.

  Motivations for this change are:

  - To make it easier to see when node and wallet code is being accessed places where it shouldn't be. For example if GUI code is accessing node and wallet internals or if wallet and node code are referencing each other.
  - To make source code organization clearer ([#15732](https://github.com/bitcoin/bitcoin/issues/15732)), being able to know that `wallet::` code is in `src/wallet/`, `node::` code is in `src/node/`, `init::` code is in `src/init/`, `util::` code is in `src/util/`, etc.

  Reviewing with `git log -p -n1 -U0 --word-diff-regex=.` can be helpful to verify this is only updating declarations, not changing code.

ACKs for top commit:
  achow101:
    ACK e5b6aef61221b621ad77b5f075a16897e08835bf
  MarcoFalke:
    Concept ACK e5b6aef61221b621ad77b5f075a16897e08835bf 🍨

Tree-SHA512: 3797745c90246794e2d55a2ee6e8b0ad5c811e4e03a242d3fdfeb68032f8787f0d48ed4097f6b7730f540220c0af99ef423cd9dbe7f76b2ec12e769a757a2c8d
This commit is contained in:
MarcoFalke 2022-01-11 11:10:49 +01:00
commit c561f2f06e
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548
166 changed files with 581 additions and 141 deletions

View File

@ -11,6 +11,19 @@
#include <set> #include <set>
using node::NodeContext;
using wallet::AttemptSelection;
using wallet::CInputCoin;
using wallet::COutput;
using wallet::CWallet;
using wallet::CWalletTx;
using wallet::CoinEligibilityFilter;
using wallet::CoinSelectionParams;
using wallet::CreateDummyWalletDatabase;
using wallet::OutputGroup;
using wallet::SelectCoinsBnB;
using wallet::TxStateInactive;
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs) static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
{ {
static int nextLockTime = 0; static int nextLockTime = 0;

View File

@ -14,6 +14,12 @@
#include <optional> #include <optional>
using wallet::CWallet;
using wallet::CreateMockWalletDatabase;
using wallet::DBErrors;
using wallet::GetBalance;
using wallet::WALLET_FLAG_DESCRIPTORS;
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine) static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine)
{ {
const auto test_setup = MakeNoLogFileContext<const TestingSetup>(); const auto test_setup = MakeNoLogFileContext<const TestingSetup>();

View File

@ -123,7 +123,7 @@ int main(int argc, char* argv[])
ECCVerifyHandle globalVerifyHandle; ECCVerifyHandle globalVerifyHandle;
ECC_Start(); ECC_Start();
if (!WalletTool::ExecuteWalletToolFunc(args, command->command)) { if (!wallet::WalletTool::ExecuteWalletToolFunc(args, command->command)) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
ECC_Stop(); ECC_Stop();

View File

@ -30,6 +30,8 @@
#include <functional> #include <functional>
#include <optional> #include <optional>
using node::NodeContext;
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr; const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
UrlDecodeFn* const URL_DECODE = urlDecode; UrlDecodeFn* const URL_DECODE = urlDecode;

View File

@ -4,6 +4,12 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chain.h> #include <chain.h>
#include <util/time.h>
std::string CBlockFileInfo::ToString() const
{
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast));
}
void CChain::SetTip(CBlockIndex *pindex) { void CChain::SetTip(CBlockIndex *pindex) {
if (pindex == nullptr) { if (pindex == nullptr) {

View File

@ -6,7 +6,6 @@
#include <walletinitinterface.h> #include <walletinitinterface.h>
class ArgsManager; class ArgsManager;
class CWallet;
namespace interfaces { namespace interfaces {
class Chain; class Chain;
@ -21,7 +20,7 @@ public:
bool HasWalletSupport() const override {return false;} bool HasWalletSupport() const override {return false;}
void AddWalletOptions(ArgsManager& argsman) const override; void AddWalletOptions(ArgsManager& argsman) const override;
bool ParameterInteraction() const override {return true;} bool ParameterInteraction() const override {return true;}
void Construct(NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");} void Construct(node::NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
}; };
void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
@ -59,11 +58,6 @@ const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();
namespace interfaces { namespace interfaces {
std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet)
{
throw std::logic_error("Wallet function called in non-wallet build.");
}
std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args) std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args)
{ {
throw std::logic_error("Wallet function called in non-wallet build."); throw std::logic_error("Wallet function called in non-wallet build.");

View File

@ -14,6 +14,8 @@
#include <validation.h> // For g_chainman #include <validation.h> // For g_chainman
#include <warnings.h> #include <warnings.h>
using node::ReadBlockFromDisk;
constexpr uint8_t DB_BEST_BLOCK{'B'}; constexpr uint8_t DB_BEST_BLOCK{'B'};
constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds

View File

@ -9,6 +9,8 @@
#include <node/blockstorage.h> #include <node/blockstorage.h>
#include <util/system.h> #include <util/system.h>
using node::UndoReadFromDisk;
/* The index database stores three items for each block: the disk location of the encoded filter, /* The index database stores three items for each block: the disk location of the encoded filter,
* its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by * its dSHA256 hash, and the header. Those belonging to blocks on the active chain are indexed by
* height, and those belonging to blocks that have been reorganized out of the active chain are * height, and those belonging to blocks that have been reorganized out of the active chain are

View File

@ -12,6 +12,12 @@
#include <undo.h> #include <undo.h>
#include <validation.h> #include <validation.h>
using node::CCoinsStats;
using node::GetBogoSize;
using node::ReadBlockFromDisk;
using node::TxOutSer;
using node::UndoReadFromDisk;
static constexpr uint8_t DB_BLOCK_HASH{'s'}; static constexpr uint8_t DB_BLOCK_HASH{'s'};
static constexpr uint8_t DB_BLOCK_HEIGHT{'t'}; static constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
static constexpr uint8_t DB_MUHASH{'M'}; static constexpr uint8_t DB_MUHASH{'M'};

View File

@ -52,7 +52,7 @@ public:
explicit CoinStatsIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false); explicit CoinStatsIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
// Look up stats for a specific block using CBlockIndex // Look up stats for a specific block using CBlockIndex
bool LookUpStats(const CBlockIndex* block_index, CCoinsStats& coins_stats) const; bool LookUpStats(const CBlockIndex* block_index, node::CCoinsStats& coins_stats) const;
}; };
/// The global UTXO set hash object. /// The global UTXO set hash object.

View File

@ -9,6 +9,8 @@
#include <util/system.h> #include <util/system.h>
#include <validation.h> #include <validation.h>
using node::OpenBlockFile;
constexpr uint8_t DB_TXINDEX{'t'}; constexpr uint8_t DB_TXINDEX{'t'};
std::unique_ptr<TxIndex> g_txindex; std::unique_ptr<TxIndex> g_txindex;

View File

@ -95,6 +95,22 @@
#include <zmq/zmqrpc.h> #include <zmq/zmqrpc.h>
#endif #endif
using node::CacheSizes;
using node::CalculateCacheSizes;
using node::ChainstateLoadVerifyError;
using node::ChainstateLoadingError;
using node::CleanupBlockRevFiles;
using node::DEFAULT_PRINTPRIORITY;
using node::DEFAULT_STOPAFTERBLOCKIMPORT;
using node::LoadChainstate;
using node::NodeContext;
using node::ThreadImport;
using node::VerifyLoadedChainstate;
using node::fHavePruned;
using node::fPruneMode;
using node::fReindex;
using node::nPruneTarget;
static const bool DEFAULT_PROXYRANDOMIZE = true; static const bool DEFAULT_PROXYRANDOMIZE = true;
static const bool DEFAULT_REST_ENABLE = false; static const bool DEFAULT_REST_ENABLE = false;

View File

@ -16,14 +16,16 @@ static constexpr bool DEFAULT_DAEMON = false;
static constexpr bool DEFAULT_DAEMONWAIT = false; static constexpr bool DEFAULT_DAEMONWAIT = false;
class ArgsManager; class ArgsManager;
struct NodeContext;
namespace interfaces { namespace interfaces {
struct BlockAndHeaderTipInfo; struct BlockAndHeaderTipInfo;
} }
namespace node {
struct NodeContext;
} // namespace node
/** Interrupt threads */ /** Interrupt threads */
void Interrupt(NodeContext& node); void Interrupt(node::NodeContext& node);
void Shutdown(NodeContext& node); void Shutdown(node::NodeContext& node);
//!Initialize the logging infrastructure //!Initialize the logging infrastructure
void InitLogging(const ArgsManager& args); void InitLogging(const ArgsManager& args);
//!Parameter interaction: change current parameters depending on various rules //!Parameter interaction: change current parameters depending on various rules
@ -55,13 +57,13 @@ bool AppInitLockDataDirectory();
/** /**
* Initialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory. * Initialize node and wallet interface pointers. Has no prerequisites or side effects besides allocating memory.
*/ */
bool AppInitInterfaces(NodeContext& node); bool AppInitInterfaces(node::NodeContext& node);
/** /**
* Bitcoin core main initialization. * Bitcoin core main initialization.
* @note This should only be done after daemonization. Call Shutdown() if this function fails. * @note This should only be done after daemonization. Call Shutdown() if this function fails.
* @pre Parameters should be parsed and config file should be read, AppInitLockDataDirectory should have been called. * @pre Parameters should be parsed and config file should be read, AppInitLockDataDirectory should have been called.
*/ */
bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr); bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info = nullptr);
/** /**
* Register all arguments with the ArgsManager * Register all arguments with the ArgsManager

View File

@ -33,7 +33,7 @@ public:
} }
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); } std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
interfaces::Ipc* ipc() override { return m_ipc.get(); } interfaces::Ipc* ipc() override { return m_ipc.get(); }
NodeContext m_node; node::NodeContext m_node;
std::unique_ptr<interfaces::Ipc> m_ipc; std::unique_ptr<interfaces::Ipc> m_ipc;
}; };
} // namespace } // namespace

View File

@ -20,7 +20,7 @@ const char* EXE_NAME = "bitcoin-node";
class BitcoinNodeInit : public interfaces::Init class BitcoinNodeInit : public interfaces::Init
{ {
public: public:
BitcoinNodeInit(NodeContext& node, const char* arg0) BitcoinNodeInit(node::NodeContext& node, const char* arg0)
: m_node(node), : m_node(node),
m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this)) m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
{ {
@ -35,14 +35,14 @@ public:
} }
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); } std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
interfaces::Ipc* ipc() override { return m_ipc.get(); } interfaces::Ipc* ipc() override { return m_ipc.get(); }
NodeContext& m_node; node::NodeContext& m_node;
std::unique_ptr<interfaces::Ipc> m_ipc; std::unique_ptr<interfaces::Ipc> m_ipc;
}; };
} // namespace } // namespace
} // namespace init } // namespace init
namespace interfaces { namespace interfaces {
std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status) std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status)
{ {
auto init = std::make_unique<init::BitcoinNodeInit>(node, argc > 0 ? argv[0] : ""); auto init = std::make_unique<init::BitcoinNodeInit>(node, argc > 0 ? argv[0] : "");
// Check if bitcoin-node is being invoked as an IPC server. If so, then // Check if bitcoin-node is being invoked as an IPC server. If so, then

View File

@ -29,7 +29,7 @@ public:
return MakeWalletLoader(chain, *Assert(m_node.args)); return MakeWalletLoader(chain, *Assert(m_node.args));
} }
std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); } std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
NodeContext m_node; node::NodeContext m_node;
}; };
} // namespace } // namespace
} // namespace init } // namespace init

View File

@ -12,6 +12,8 @@
#include <memory> #include <memory>
using node::NodeContext;
namespace init { namespace init {
namespace { namespace {
class BitcoindInit : public interfaces::Init class BitcoindInit : public interfaces::Init

View File

@ -28,7 +28,9 @@ enum class RBFTransactionState;
struct bilingual_str; struct bilingual_str;
struct CBlockLocator; struct CBlockLocator;
struct FeeCalculation; struct FeeCalculation;
namespace node {
struct NodeContext; struct NodeContext;
} // namespace node
namespace interfaces { namespace interfaces {
@ -316,7 +318,7 @@ public:
}; };
//! Return implementation of Chain interface. //! Return implementation of Chain interface.
std::unique_ptr<Chain> MakeChain(NodeContext& node); std::unique_ptr<Chain> MakeChain(node::NodeContext& node);
} // namespace interfaces } // namespace interfaces

View File

@ -7,7 +7,9 @@
#include <memory> #include <memory>
namespace node {
struct NodeContext; struct NodeContext;
} // namespace node
namespace interfaces { namespace interfaces {
class Chain; class Chain;
@ -40,7 +42,7 @@ public:
//! status code to exit with. If this returns non-null, the caller can start up //! status code to exit with. If this returns non-null, the caller can start up
//! normally and use the Init object to spawn and connect to other processes //! normally and use the Init object to spawn and connect to other processes
//! while it is running. //! while it is running.
std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status); std::unique_ptr<Init> MakeNodeInit(node::NodeContext& node, int argc, char* argv[], int& exit_status);
//! Return implementation of Init interface for the wallet process. //! Return implementation of Init interface for the wallet process.
std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status); std::unique_ptr<Init> MakeWalletInit(int argc, char* argv[], int& exit_status);

View File

@ -22,7 +22,6 @@
#include <vector> #include <vector>
class BanMan; class BanMan;
class CCoinControl;
class CFeeRate; class CFeeRate;
class CNodeStats; class CNodeStats;
class Coin; class Coin;
@ -32,8 +31,13 @@ class proxyType;
enum class SynchronizationState; enum class SynchronizationState;
enum class TransactionError; enum class TransactionError;
struct CNodeStateStats; struct CNodeStateStats;
struct NodeContext;
struct bilingual_str; struct bilingual_str;
namespace node {
struct NodeContext;
} // namespace node
namespace wallet {
class CCoinControl;
} // namespace wallet
namespace interfaces { namespace interfaces {
class Handler; class Handler;
@ -242,12 +246,12 @@ public:
//! Get and set internal node context. Useful for testing, but not //! Get and set internal node context. Useful for testing, but not
//! accessible across processes. //! accessible across processes.
virtual NodeContext* context() { return nullptr; } virtual node::NodeContext* context() { return nullptr; }
virtual void setContext(NodeContext* context) { } virtual void setContext(node::NodeContext* context) { }
}; };
//! Return implementation of Node interface. //! Return implementation of Node interface.
std::unique_ptr<Node> MakeNode(NodeContext& context); std::unique_ptr<Node> MakeNode(node::NodeContext& context);
//! Block tip (could be a header or not, depends on the subscribed signal). //! Block tip (could be a header or not, depends on the subscribed signal).
struct BlockTip { struct BlockTip {

View File

@ -24,19 +24,21 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
class CCoinControl;
class CFeeRate; class CFeeRate;
class CKey; class CKey;
class CWallet;
enum class FeeReason; enum class FeeReason;
enum class OutputType; enum class OutputType;
enum class TransactionError; enum class TransactionError;
struct PartiallySignedTransaction;
struct bilingual_str;
namespace wallet {
class CCoinControl;
class CWallet;
enum isminetype : unsigned int; enum isminetype : unsigned int;
struct CRecipient; struct CRecipient;
struct PartiallySignedTransaction;
struct WalletContext; struct WalletContext;
struct bilingual_str;
using isminefilter = std::underlying_type<isminetype>::type; using isminefilter = std::underlying_type<isminetype>::type;
} // namespace wallet
namespace interfaces { namespace interfaces {
@ -108,7 +110,7 @@ public:
//! Look up address in wallet, return whether exists. //! Look up address in wallet, return whether exists.
virtual bool getAddress(const CTxDestination& dest, virtual bool getAddress(const CTxDestination& dest,
std::string* name, std::string* name,
isminetype* is_mine, wallet::isminetype* is_mine,
std::string* purpose) = 0; std::string* purpose) = 0;
//! Get wallet address list. //! Get wallet address list.
@ -136,8 +138,8 @@ public:
virtual void listLockedCoins(std::vector<COutPoint>& outputs) = 0; virtual void listLockedCoins(std::vector<COutPoint>& outputs) = 0;
//! Create transaction. //! Create transaction.
virtual CTransactionRef createTransaction(const std::vector<CRecipient>& recipients, virtual CTransactionRef createTransaction(const std::vector<wallet::CRecipient>& recipients,
const CCoinControl& coin_control, const wallet::CCoinControl& coin_control,
bool sign, bool sign,
int& change_pos, int& change_pos,
CAmount& fee, CAmount& fee,
@ -159,7 +161,7 @@ public:
//! Create bump transaction. //! Create bump transaction.
virtual bool createBumpTransaction(const uint256& txid, virtual bool createBumpTransaction(const uint256& txid,
const CCoinControl& coin_control, const wallet::CCoinControl& coin_control,
std::vector<bilingual_str>& errors, std::vector<bilingual_str>& errors,
CAmount& old_fee, CAmount& old_fee,
CAmount& new_fee, CAmount& new_fee,
@ -214,19 +216,19 @@ public:
virtual CAmount getBalance() = 0; virtual CAmount getBalance() = 0;
//! Get available balance. //! Get available balance.
virtual CAmount getAvailableBalance(const CCoinControl& coin_control) = 0; virtual CAmount getAvailableBalance(const wallet::CCoinControl& coin_control) = 0;
//! Return whether transaction input belongs to wallet. //! Return whether transaction input belongs to wallet.
virtual isminetype txinIsMine(const CTxIn& txin) = 0; virtual wallet::isminetype txinIsMine(const CTxIn& txin) = 0;
//! Return whether transaction output belongs to wallet. //! Return whether transaction output belongs to wallet.
virtual isminetype txoutIsMine(const CTxOut& txout) = 0; virtual wallet::isminetype txoutIsMine(const CTxOut& txout) = 0;
//! Return debit amount if transaction input belongs to wallet. //! Return debit amount if transaction input belongs to wallet.
virtual CAmount getDebit(const CTxIn& txin, isminefilter filter) = 0; virtual CAmount getDebit(const CTxIn& txin, wallet::isminefilter filter) = 0;
//! Return credit amount if transaction input belongs to wallet. //! Return credit amount if transaction input belongs to wallet.
virtual CAmount getCredit(const CTxOut& txout, isminefilter filter) = 0; virtual CAmount getCredit(const CTxOut& txout, wallet::isminefilter filter) = 0;
//! Return AvailableCoins + LockedCoins grouped by wallet address. //! Return AvailableCoins + LockedCoins grouped by wallet address.
//! (put change in one group with wallet address) //! (put change in one group with wallet address)
@ -241,7 +243,7 @@ public:
//! Get minimum fee. //! Get minimum fee.
virtual CAmount getMinimumFee(unsigned int tx_bytes, virtual CAmount getMinimumFee(unsigned int tx_bytes,
const CCoinControl& coin_control, const wallet::CCoinControl& coin_control,
int* returned_target, int* returned_target,
FeeReason* reason) = 0; FeeReason* reason) = 0;
@ -308,7 +310,7 @@ public:
virtual std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) = 0; virtual std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) = 0;
//! Return pointer to internal wallet class, useful for testing. //! Return pointer to internal wallet class, useful for testing.
virtual CWallet* wallet() { return nullptr; } virtual wallet::CWallet* wallet() { return nullptr; }
}; };
//! Wallet chain client that in addition to having chain client methods for //! Wallet chain client that in addition to having chain client methods for
@ -342,18 +344,18 @@ public:
virtual std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) = 0; virtual std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) = 0;
//! Return pointer to internal context, useful for testing. //! Return pointer to internal context, useful for testing.
virtual WalletContext* context() { return nullptr; } virtual wallet::WalletContext* context() { return nullptr; }
}; };
//! Information about one wallet address. //! Information about one wallet address.
struct WalletAddress struct WalletAddress
{ {
CTxDestination dest; CTxDestination dest;
isminetype is_mine; wallet::isminetype is_mine;
std::string name; std::string name;
std::string purpose; std::string purpose;
WalletAddress(CTxDestination dest, isminetype is_mine, std::string name, std::string purpose) WalletAddress(CTxDestination dest, wallet::isminetype is_mine, std::string name, std::string purpose)
: dest(std::move(dest)), is_mine(is_mine), name(std::move(name)), purpose(std::move(purpose)) : dest(std::move(dest)), is_mine(is_mine), name(std::move(name)), purpose(std::move(purpose))
{ {
} }
@ -383,10 +385,10 @@ struct WalletBalances
struct WalletTx struct WalletTx
{ {
CTransactionRef tx; CTransactionRef tx;
std::vector<isminetype> txin_is_mine; std::vector<wallet::isminetype> txin_is_mine;
std::vector<isminetype> txout_is_mine; std::vector<wallet::isminetype> txout_is_mine;
std::vector<CTxDestination> txout_address; std::vector<CTxDestination> txout_address;
std::vector<isminetype> txout_address_is_mine; std::vector<wallet::isminetype> txout_address_is_mine;
CAmount credit; CAmount credit;
CAmount debit; CAmount debit;
CAmount change; CAmount change;
@ -421,7 +423,7 @@ struct WalletTxOut
//! Return implementation of Wallet interface. This function is defined in //! Return implementation of Wallet interface. This function is defined in
//! dummywallet.cpp and throws if the wallet component is not compiled. //! dummywallet.cpp and throws if the wallet component is not compiled.
std::unique_ptr<Wallet> MakeWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet); std::unique_ptr<Wallet> MakeWallet(wallet::WalletContext& context, const std::shared_ptr<wallet::CWallet>& wallet);
//! Return implementation of ChainClient interface for a wallet loader. This //! Return implementation of ChainClient interface for a wallet loader. This
//! function will be undefined in builds where ENABLE_WALLET is false. //! function will be undefined in builds where ENABLE_WALLET is false.

View File

@ -45,6 +45,12 @@
#include <optional> #include <optional>
#include <typeinfo> #include <typeinfo>
using node::ReadBlockFromDisk;
using node::ReadRawBlockFromDisk;
using node::fImporting;
using node::fPruneMode;
using node::fReindex;
/** How long to cache transactions in mapRelay for normal relay */ /** How long to cache transactions in mapRelay for normal relay */
static constexpr auto RELAY_TX_CACHE_TIME = 15min; static constexpr auto RELAY_TX_CACHE_TIME = 15min;
/** How long a transaction has to be in the mempool before it can unconditionally be relayed (even when not in mapRelay). */ /** How long a transaction has to be in the mempool before it can unconditionally be relayed (even when not in mapRelay). */

View File

@ -21,6 +21,7 @@
#include <util/system.h> #include <util/system.h>
#include <validation.h> #include <validation.h>
namespace node {
std::atomic_bool fImporting(false); std::atomic_bool fImporting(false);
std::atomic_bool fReindex(false); std::atomic_bool fReindex(false);
bool fHavePruned = false; bool fHavePruned = false;
@ -474,11 +475,6 @@ void CleanupBlockRevFiles()
} }
} }
std::string CBlockFileInfo::ToString() const
{
return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, FormatISO8601Date(nTimeFirst), FormatISO8601Date(nTimeLast));
}
CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n) CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
{ {
LOCK(cs_LastBlockFile); LOCK(cs_LastBlockFile);
@ -940,3 +936,4 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
} // End scope of CImportingNow } // End scope of CImportingNow
chainman.ActiveChainstate().LoadMempool(args); chainman.ActiveChainstate().LoadMempool(args);
} }
} // namespace node

View File

@ -29,6 +29,7 @@ namespace Consensus {
struct Params; struct Params;
} }
namespace node {
static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false}; static constexpr bool DEFAULT_STOPAFTERBLOCKIMPORT{false};
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */ /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
@ -185,5 +186,6 @@ bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const CBlockIndex* pindex
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex); bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex);
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args); void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args);
} // namespace node
#endif // BITCOIN_NODE_BLOCKSTORAGE_H #endif // BITCOIN_NODE_BLOCKSTORAGE_H

View File

@ -8,6 +8,7 @@
#include <util/system.h> #include <util/system.h>
#include <validation.h> #include <validation.h>
namespace node {
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes) CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
{ {
int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20); int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
@ -30,3 +31,4 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
sizes.coins = nTotalCache; // the rest goes to in-memory cache sizes.coins = nTotalCache; // the rest goes to in-memory cache
return sizes; return sizes;
} }
} // namespace node

View File

@ -10,6 +10,7 @@
class ArgsManager; class ArgsManager;
namespace node {
struct CacheSizes { struct CacheSizes {
int64_t block_tree_db; int64_t block_tree_db;
int64_t coins_db; int64_t coins_db;
@ -18,5 +19,6 @@ struct CacheSizes {
int64_t filter_index; int64_t filter_index;
}; };
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0); CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0);
} // namespace node
#endif // BITCOIN_NODE_CACHES_H #endif // BITCOIN_NODE_CACHES_H

View File

@ -8,6 +8,7 @@
#include <node/blockstorage.h> #include <node/blockstorage.h>
#include <validation.h> #include <validation.h>
namespace node {
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
ChainstateManager& chainman, ChainstateManager& chainman,
CTxMemPool* mempool, CTxMemPool* mempool,
@ -156,3 +157,4 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
return std::nullopt; return std::nullopt;
} }
} // namespace node

View File

@ -10,11 +10,12 @@
#include <optional> #include <optional>
class ChainstateManager; class ChainstateManager;
class CTxMemPool;
namespace Consensus { namespace Consensus {
struct Params; struct Params;
} } // namespace Consensus
class CTxMemPool;
namespace node {
enum class ChainstateLoadingError { enum class ChainstateLoadingError {
ERROR_LOADING_BLOCK_DB, ERROR_LOADING_BLOCK_DB,
ERROR_BAD_GENESIS_BLOCK, ERROR_BAD_GENESIS_BLOCK,
@ -81,5 +82,6 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
unsigned int check_blocks, unsigned int check_blocks,
unsigned int check_level, unsigned int check_level,
std::function<int64_t()> get_unix_time_seconds); std::function<int64_t()> get_unix_time_seconds);
} // namespace node
#endif // BITCOIN_NODE_CHAINSTATE_H #endif // BITCOIN_NODE_CHAINSTATE_H

View File

@ -8,6 +8,7 @@
#include <txmempool.h> #include <txmempool.h>
#include <validation.h> #include <validation.h>
namespace node {
void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins) void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
{ {
assert(node.mempool); assert(node.mempool);
@ -22,3 +23,4 @@ void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
} }
} }
} }
} // namespace node

View File

@ -9,6 +9,8 @@
class COutPoint; class COutPoint;
class Coin; class Coin;
namespace node {
struct NodeContext; struct NodeContext;
/** /**
@ -19,6 +21,7 @@ struct NodeContext;
* @param[in] node The node context to use for lookup * @param[in] node The node context to use for lookup
* @param[in,out] coins map to fill * @param[in,out] coins map to fill
*/ */
void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins); void FindCoins(const node::NodeContext& node, std::map<COutPoint, Coin>& coins);
} // namespace node
#endif // BITCOIN_NODE_COIN_H #endif // BITCOIN_NODE_COIN_H

View File

@ -17,6 +17,7 @@
#include <map> #include <map>
namespace node {
// Database-independent metric indicating the UTXO set size // Database-independent metric indicating the UTXO set size
uint64_t GetBogoSize(const CScript& script_pub_key) uint64_t GetBogoSize(const CScript& script_pub_key)
{ {
@ -181,3 +182,4 @@ static void FinalizeHash(MuHash3072& muhash, CCoinsStats& stats)
stats.hashSerialized = out; stats.hashSerialized = out;
} }
static void FinalizeHash(std::nullptr_t, CCoinsStats& stats) {} static void FinalizeHash(std::nullptr_t, CCoinsStats& stats) {}
} // namespace node

View File

@ -15,9 +15,12 @@
#include <cstdint> #include <cstdint>
#include <functional> #include <functional>
class BlockManager;
class CCoinsView; class CCoinsView;
namespace node {
class BlockManager;
} // namespace node
namespace node {
enum class CoinStatsHashType { enum class CoinStatsHashType {
HASH_SERIALIZED, HASH_SERIALIZED,
MUHASH, MUHASH,
@ -71,10 +74,11 @@ struct CCoinsStats {
}; };
//! Calculate statistics about the unspent transaction output set //! Calculate statistics about the unspent transaction output set
bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr); bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr);
uint64_t GetBogoSize(const CScript& script_pub_key); uint64_t GetBogoSize(const CScript& script_pub_key);
CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin); CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin);
} // namespace node
#endif // BITCOIN_NODE_COINSTATS_H #endif // BITCOIN_NODE_COINSTATS_H

View File

@ -14,5 +14,7 @@
#include <txmempool.h> #include <txmempool.h>
#include <validation.h> #include <validation.h>
namespace node {
NodeContext::NodeContext() {} NodeContext::NodeContext() {}
NodeContext::~NodeContext() {} NodeContext::~NodeContext() {}
} // namespace node

View File

@ -26,6 +26,7 @@ class Init;
class WalletLoader; class WalletLoader;
} // namespace interfaces } // namespace interfaces
namespace node {
//! NodeContext struct containing references to chain state and connection //! NodeContext struct containing references to chain state and connection
//! state. //! state.
//! //!
@ -62,5 +63,6 @@ struct NodeContext {
NodeContext(); NodeContext();
~NodeContext(); ~NodeContext();
}; };
} // namespace node
#endif // BITCOIN_NODE_CONTEXT_H #endif // BITCOIN_NODE_CONTEXT_H

View File

@ -249,8 +249,8 @@ public:
bool isInitialBlockDownload() override { bool isInitialBlockDownload() override {
return chainman().ActiveChainstate().IsInitialBlockDownload(); return chainman().ActiveChainstate().IsInitialBlockDownload();
} }
bool getReindex() override { return ::fReindex; } bool getReindex() override { return node::fReindex; }
bool getImporting() override { return ::fImporting; } bool getImporting() override { return node::fImporting; }
void setNetworkActive(bool active) override void setNetworkActive(bool active) override
{ {
if (m_context->connman) { if (m_context->connman) {
@ -649,9 +649,9 @@ public:
bool havePruned() override bool havePruned() override
{ {
LOCK(cs_main); LOCK(cs_main);
return ::fHavePruned; return node::fHavePruned;
} }
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); } bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); }
bool isInitialBlockDownload() override { bool isInitialBlockDownload() override {
return chainman().ActiveChainstate().IsInitialBlockDownload(); return chainman().ActiveChainstate().IsInitialBlockDownload();
} }
@ -729,6 +729,6 @@ public:
} // namespace node } // namespace node
namespace interfaces { namespace interfaces {
std::unique_ptr<Node> MakeNode(NodeContext& context) { return std::make_unique<node::NodeImpl>(context); } std::unique_ptr<Node> MakeNode(node::NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }
std::unique_ptr<Chain> MakeChain(NodeContext& context) { return std::make_unique<node::ChainImpl>(context); } std::unique_ptr<Chain> MakeChain(node::NodeContext& context) { return std::make_unique<node::ChainImpl>(context); }
} // namespace interfaces } // namespace interfaces

View File

@ -26,6 +26,7 @@
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
namespace node {
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
{ {
int64_t nOldTime = pblock->nTime; int64_t nOldTime = pblock->nTime;
@ -464,3 +465,4 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
} }
} // namespace node

View File

@ -23,6 +23,7 @@ class CScript;
namespace Consensus { struct Params; }; namespace Consensus { struct Params; };
namespace node {
static const bool DEFAULT_PRINTPRIORITY = false; static const bool DEFAULT_PRINTPRIORITY = false;
struct CBlockTemplate struct CBlockTemplate
@ -206,5 +207,6 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
/** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */ /** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
void RegenerateCommitments(CBlock& block, ChainstateManager& chainman); void RegenerateCommitments(CBlock& block, ChainstateManager& chainman);
} // namespace node
#endif // BITCOIN_NODE_MINER_H #endif // BITCOIN_NODE_MINER_H

View File

@ -16,6 +16,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
namespace node {
namespace { namespace {
static constexpr uint32_t BITS = 32; static constexpr uint32_t BITS = 32;
@ -75,3 +76,4 @@ Minisketch MakeMinisketch32FP(size_t max_elements, uint32_t fpbits)
{ {
return Minisketch::CreateFP(BITS, Minisketch32Implementation(), max_elements, fpbits); return Minisketch::CreateFP(BITS, Minisketch32Implementation(), max_elements, fpbits);
} }
} // namespace node

View File

@ -10,9 +10,11 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
namespace node {
/** Wrapper around Minisketch::Minisketch(32, implementation, capacity). */ /** Wrapper around Minisketch::Minisketch(32, implementation, capacity). */
Minisketch MakeMinisketch32(size_t capacity); Minisketch MakeMinisketch32(size_t capacity);
/** Wrapper around Minisketch::CreateFP. */ /** Wrapper around Minisketch::CreateFP. */
Minisketch MakeMinisketch32FP(size_t max_elements, uint32_t fpbits); Minisketch MakeMinisketch32FP(size_t max_elements, uint32_t fpbits);
} // namespace node
#endif // BITCOIN_NODE_MINISKETCHWRAPPER_H #endif // BITCOIN_NODE_MINISKETCHWRAPPER_H

View File

@ -12,6 +12,7 @@
#include <numeric> #include <numeric>
namespace node {
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
{ {
// Go through each input and build status // Go through each input and build status
@ -147,3 +148,4 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx)
return result; return result;
} }
} // namespace node

View File

@ -9,6 +9,7 @@
#include <optional> #include <optional>
namespace node {
/** /**
* Holds an analysis of one input from a PSBT * Holds an analysis of one input from a PSBT
*/ */
@ -52,5 +53,6 @@ struct PSBTAnalysis {
* @return A PSBTAnalysis with information about the provided PSBT. * @return A PSBTAnalysis with information about the provided PSBT.
*/ */
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx); PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx);
} // namespace node
#endif // BITCOIN_NODE_PSBT_H #endif // BITCOIN_NODE_PSBT_H

View File

@ -16,6 +16,7 @@
#include <future> #include <future>
namespace node {
static TransactionError HandleATMPError(const TxValidationState& state, std::string& err_string_out) static TransactionError HandleATMPError(const TxValidationState& state, std::string& err_string_out)
{ {
err_string_out = state.ToString(); err_string_out = state.ToString();
@ -153,3 +154,4 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
} }
return nullptr; return nullptr;
} }
} // namespace node

View File

@ -12,11 +12,13 @@
class CBlockIndex; class CBlockIndex;
class CTxMemPool; class CTxMemPool;
struct NodeContext;
namespace Consensus { namespace Consensus {
struct Params; struct Params;
} }
namespace node {
struct NodeContext;
/** Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls. /** Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
* Also used by the GUI when broadcasting a completed PSBT. * Also used by the GUI when broadcasting a completed PSBT.
* By default, a transaction with a fee rate higher than this will be rejected * By default, a transaction with a fee rate higher than this will be rejected
@ -57,5 +59,6 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
* @returns The tx if found, otherwise nullptr * @returns The tx if found, otherwise nullptr
*/ */
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock); CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
} // namespace node
#endif // BITCOIN_NODE_TRANSACTION_H #endif // BITCOIN_NODE_TRANSACTION_H

View File

@ -9,6 +9,7 @@
#include <uint256.h> #include <uint256.h>
#include <serialize.h> #include <serialize.h>
namespace node {
//! Metadata describing a serialized version of a UTXO set from which an //! Metadata describing a serialized version of a UTXO set from which an
//! assumeutxo CChainState can be constructed. //! assumeutxo CChainState can be constructed.
class SnapshotMetadata class SnapshotMetadata
@ -32,5 +33,6 @@ public:
SERIALIZE_METHODS(SnapshotMetadata, obj) { READWRITE(obj.m_base_blockhash, obj.m_coins_count); } SERIALIZE_METHODS(SnapshotMetadata, obj) { READWRITE(obj.m_base_blockhash, obj.m_coins_count); }
}; };
} // namespace node
#endif // BITCOIN_NODE_UTXO_SNAPSHOT_H #endif // BITCOIN_NODE_UTXO_SNAPSHOT_H

View File

@ -76,6 +76,8 @@ Q_DECLARE_METATYPE(CAmount)
Q_DECLARE_METATYPE(SynchronizationState) Q_DECLARE_METATYPE(SynchronizationState)
Q_DECLARE_METATYPE(uint256) Q_DECLARE_METATYPE(uint256)
using node::NodeContext;
static void RegisterMetaTypes() static void RegisterMetaTypes()
{ {
// Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection // Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection

View File

@ -31,6 +31,9 @@
#include <QSettings> #include <QSettings>
#include <QTreeWidget> #include <QTreeWidget>
using wallet::CCoinControl;
using wallet::MIN_CHANGE;
QList<CAmount> CoinControlDialog::payAmounts; QList<CAmount> CoinControlDialog::payAmounts;
bool CoinControlDialog::fSubtractFeeFromAmount = false; bool CoinControlDialog::fSubtractFeeFromAmount = false;

View File

@ -19,7 +19,9 @@
class PlatformStyle; class PlatformStyle;
class WalletModel; class WalletModel;
namespace wallet {
class CCoinControl; class CCoinControl;
} // namespace wallet
namespace Ui { namespace Ui {
class CoinControlDialog; class CoinControlDialog;
@ -42,11 +44,11 @@ class CoinControlDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit CoinControlDialog(CCoinControl& coin_control, WalletModel* model, const PlatformStyle *platformStyle, QWidget *parent = nullptr); explicit CoinControlDialog(wallet::CCoinControl& coin_control, WalletModel* model, const PlatformStyle *platformStyle, QWidget *parent = nullptr);
~CoinControlDialog(); ~CoinControlDialog();
// static because also called from sendcoinsdialog // static because also called from sendcoinsdialog
static void updateLabels(CCoinControl& m_coin_control, WalletModel*, QDialog*); static void updateLabels(wallet::CCoinControl& m_coin_control, WalletModel*, QDialog*);
static QList<CAmount> payAmounts; static QList<CAmount> payAmounts;
static bool fSubtractFeeFromAmount; static bool fSubtractFeeFromAmount;
@ -56,7 +58,7 @@ protected:
private: private:
Ui::CoinControlDialog *ui; Ui::CoinControlDialog *ui;
CCoinControl& m_coin_control; wallet::CCoinControl& m_coin_control;
WalletModel *model; WalletModel *model;
int sortColumn; int sortColumn;
Qt::SortOrder sortOrder; Qt::SortOrder sortOrder;

View File

@ -17,6 +17,9 @@
#include <iostream> #include <iostream>
using node::AnalyzePSBT;
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
using node::PSBTAnalysis;
PSBTOperationsDialog::PSBTOperationsDialog( PSBTOperationsDialog::PSBTOperationsDialog(
QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags), QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags),

View File

@ -35,6 +35,9 @@
#include <QSettings> #include <QSettings>
#include <QTextDocument> #include <QTextDocument>
using wallet::CCoinControl;
using wallet::DEFAULT_PAY_TX_FEE;
static constexpr std::array confTargets{2, 4, 6, 12, 24, 48, 144, 504, 1008}; static constexpr std::array confTargets{2, 4, 6, 12, 24, 48, 144, 504, 1008};
int getConfTargetForIndex(int index) { int getConfTargetForIndex(int index) {
if (index+1 > static_cast<int>(confTargets.size())) { if (index+1 > static_cast<int>(confTargets.size())) {

View File

@ -12,12 +12,14 @@
#include <QString> #include <QString>
#include <QTimer> #include <QTimer>
class CCoinControl;
class ClientModel; class ClientModel;
class PlatformStyle; class PlatformStyle;
class SendCoinsEntry; class SendCoinsEntry;
class SendCoinsRecipient; class SendCoinsRecipient;
enum class SynchronizationState; enum class SynchronizationState;
namespace wallet {
class CCoinControl;
} // namespace wallet
namespace Ui { namespace Ui {
class SendCoinsDialog; class SendCoinsDialog;
@ -62,7 +64,7 @@ private:
Ui::SendCoinsDialog *ui; Ui::SendCoinsDialog *ui;
ClientModel *clientModel; ClientModel *clientModel;
WalletModel *model; WalletModel *model;
std::unique_ptr<CCoinControl> m_coin_control; std::unique_ptr<wallet::CCoinControl> m_coin_control;
std::unique_ptr<WalletModelTransaction> m_current_transaction; std::unique_ptr<WalletModelTransaction> m_current_transaction;
bool fNewRecipientAllowed; bool fNewRecipientAllowed;
bool fFeeMinimized; bool fFeeMinimized;

View File

@ -24,6 +24,13 @@
#include <QTimer> #include <QTimer>
#include <QMessageBox> #include <QMessageBox>
using wallet::AddWallet;
using wallet::CWallet;
using wallet::CreateMockWalletDatabase;
using wallet::RemoveWallet;
using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WalletContext;
namespace namespace
{ {

View File

@ -39,6 +39,8 @@ Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
#endif #endif
#endif #endif
using node::NodeContext;
const std::function<void(const std::string&)> G_TEST_LOG_FUN{}; const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
// This is all you need to run all the tests // This is all you need to run all the tests

View File

@ -39,6 +39,15 @@
#include <QListView> #include <QListView>
#include <QDialogButtonBox> #include <QDialogButtonBox>
using wallet::AddWallet;
using wallet::CWallet;
using wallet::CreateMockWalletDatabase;
using wallet::RemoveWallet;
using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WalletContext;
using wallet::WalletDescriptor;
using wallet::WalletRescanReserver;
namespace namespace
{ {
//! Press "Yes" or "Cancel" buttons in modal send confirmation dialog. //! Press "Yes" or "Cancel" buttons in modal send confirmation dialog.

View File

@ -28,6 +28,11 @@
#include <QLatin1String> #include <QLatin1String>
using wallet::ISMINE_ALL;
using wallet::ISMINE_SPENDABLE;
using wallet::ISMINE_WATCH_ONLY;
using wallet::isminetype;
QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks) QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks)
{ {
if (!status.is_final) if (!status.is_final)

View File

@ -13,6 +13,10 @@
#include <QDateTime> #include <QDateTime>
using wallet::ISMINE_SPENDABLE;
using wallet::ISMINE_WATCH_ONLY;
using wallet::isminetype;
/* Return positive answer if transaction should be shown in list. /* Return positive answer if transaction should be shown in list.
*/ */
bool TransactionRecord::showTransaction() bool TransactionRecord::showTransaction()

View File

@ -28,6 +28,11 @@
#include <QTimer> #include <QTimer>
#include <QWindow> #include <QWindow>
using wallet::WALLET_FLAG_BLANK_WALLET;
using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS;
using wallet::WALLET_FLAG_EXTERNAL_SIGNER;
WalletController::WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent) WalletController::WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent)
: QObject(parent) : QObject(parent)
, m_activity_thread(new QThread(this)) , m_activity_thread(new QThread(this))

View File

@ -36,6 +36,9 @@
#include <QSet> #include <QSet>
#include <QTimer> #include <QTimer>
using wallet::CCoinControl;
using wallet::CRecipient;
using wallet::DEFAULT_DISABLE_WALLET;
WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, ClientModel& client_model, const PlatformStyle *platformStyle, QObject *parent) : WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, ClientModel& client_model, const PlatformStyle *platformStyle, QObject *parent) :
QObject(parent), QObject(parent),

View File

@ -32,16 +32,17 @@ class SendCoinsRecipient;
class TransactionTableModel; class TransactionTableModel;
class WalletModelTransaction; class WalletModelTransaction;
class CCoinControl;
class CKeyID; class CKeyID;
class COutPoint; class COutPoint;
class COutput;
class CPubKey; class CPubKey;
class uint256; class uint256;
namespace interfaces { namespace interfaces {
class Node; class Node;
} // namespace interfaces } // namespace interfaces
namespace wallet {
class CCoinControl;
} // namespace wallet
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTimer; class QTimer;
@ -99,7 +100,7 @@ public:
}; };
// prepare transaction for getting txfee before sending coins // prepare transaction for getting txfee before sending coins
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl); SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl& coinControl);
// Send coins to a list of recipients // Send coins to a list of recipients
SendCoinsReturn sendCoins(WalletModelTransaction &transaction); SendCoinsReturn sendCoins(WalletModelTransaction &transaction);

View File

@ -32,6 +32,11 @@
#include <univalue.h> #include <univalue.h>
using node::GetTransaction;
using node::IsBlockPruned;
using node::NodeContext;
using node::ReadBlockFromDisk;
static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once
static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000; static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000;

View File

@ -56,6 +56,16 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
using node::BlockManager;
using node::CCoinsStats;
using node::CoinStatsHashType;
using node::GetUTXOStats;
using node::IsBlockPruned;
using node::NodeContext;
using node::ReadBlockFromDisk;
using node::SnapshotMetadata;
using node::UndoReadFromDisk;
struct CUpdatedBlock struct CUpdatedBlock
{ {
uint256 hash; uint256 hash;
@ -1112,7 +1122,7 @@ static RPCHelpMan pruneblockchain()
}, },
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{ {
if (!fPruneMode) if (!node::fPruneMode)
throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode."); throw JSONRPCError(RPC_MISC_ERROR, "Cannot prune blocks because node is not in prune mode.");
ChainstateManager& chainman = EnsureAnyChainman(request.context); ChainstateManager& chainman = EnsureAnyChainman(request.context);
@ -1565,8 +1575,8 @@ RPCHelpMan getblockchaininfo()
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload()); obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());
obj.pushKV("chainwork", tip->nChainWork.GetHex()); obj.pushKV("chainwork", tip->nChainWork.GetHex());
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage()); obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
obj.pushKV("pruned", fPruneMode); obj.pushKV("pruned", node::fPruneMode);
if (fPruneMode) { if (node::fPruneMode) {
const CBlockIndex* block = tip; const CBlockIndex* block = tip;
CHECK_NONFATAL(block); CHECK_NONFATAL(block);
while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) { while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
@ -1579,7 +1589,7 @@ RPCHelpMan getblockchaininfo()
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1}; bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
obj.pushKV("automatic_pruning", automatic_pruning); obj.pushKV("automatic_pruning", automatic_pruning);
if (automatic_pruning) { if (automatic_pruning) {
obj.pushKV("prune_target_size", nPruneTarget); obj.pushKV("prune_target_size", node::nPruneTarget);
} }
} }

View File

@ -22,7 +22,9 @@ class CBlockIndex;
class CChainState; class CChainState;
class CTxMemPool; class CTxMemPool;
class UniValue; class UniValue;
namespace node {
struct NodeContext; struct NodeContext;
} // namespace node
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5; static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
@ -57,7 +59,7 @@ void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES],
* @return a UniValue map containing metadata about the snapshot. * @return a UniValue map containing metadata about the snapshot.
*/ */
UniValue CreateUTXOSnapshot( UniValue CreateUTXOSnapshot(
NodeContext& node, node::NodeContext& node,
CChainState& chainstate, CChainState& chainstate,
CAutoFile& afile, CAutoFile& afile,
const fs::path& path, const fs::path& path,

View File

@ -41,6 +41,13 @@
#include <memory> #include <memory>
#include <stdint.h> #include <stdint.h>
using node::BlockAssembler;
using node::CBlockTemplate;
using node::IncrementExtraNonce;
using node::NodeContext;
using node::RegenerateCommitments;
using node::UpdateTime;
/** /**
* Return average network hashes per second based on the last 'lookup' blocks, * Return average network hashes per second based on the last 'lookup' blocks,
* or from the last difficulty change if 'lookup' is nonpositive. * or from the last difficulty change if 'lookup' is nonpositive.

View File

@ -35,6 +35,8 @@
#include <univalue.h> #include <univalue.h>
using node::NodeContext;
static RPCHelpMan validateaddress() static RPCHelpMan validateaddress()
{ {
return RPCHelpMan{ return RPCHelpMan{

View File

@ -32,6 +32,8 @@
#include <univalue.h> #include <univalue.h>
using node::NodeContext;
const std::vector<std::string> CONNECTION_TYPE_DOC{ const std::vector<std::string> CONNECTION_TYPE_DOC{
"outbound-full-relay (default automatic connections)", "outbound-full-relay (default automatic connections)",
"block-relay-only (does not relay transactions or addresses)", "block-relay-only (does not relay transactions or addresses)",

View File

@ -45,6 +45,15 @@
#include <univalue.h> #include <univalue.h>
using node::AnalyzePSBT;
using node::BroadcastTransaction;
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
using node::FindCoins;
using node::GetTransaction;
using node::NodeContext;
using node::PSBTAnalysis;
using node::ReadBlockFromDisk;
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, CChainState& active_chainstate) static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, CChainState& active_chainstate)
{ {
// Call into TxToUniv() in bitcoin-common to decode the transaction hex. // Call into TxToUniv() in bitcoin-common to decode the transaction hex.

View File

@ -15,6 +15,8 @@
#include <any> #include <any>
using node::NodeContext;
NodeContext& EnsureAnyNodeContext(const std::any& context) NodeContext& EnsureAnyNodeContext(const std::any& context)
{ {
auto node_context = util::AnyPtr<NodeContext>(context); auto node_context = util::AnyPtr<NodeContext>(context);

View File

@ -13,18 +13,20 @@ class CConnman;
class CTxMemPool; class CTxMemPool;
class ChainstateManager; class ChainstateManager;
class PeerManager; class PeerManager;
namespace node {
struct NodeContext; struct NodeContext;
} // namespace node
NodeContext& EnsureAnyNodeContext(const std::any& context); node::NodeContext& EnsureAnyNodeContext(const std::any& context);
CTxMemPool& EnsureMemPool(const NodeContext& node); CTxMemPool& EnsureMemPool(const node::NodeContext& node);
CTxMemPool& EnsureAnyMemPool(const std::any& context); CTxMemPool& EnsureAnyMemPool(const std::any& context);
ArgsManager& EnsureArgsman(const NodeContext& node); ArgsManager& EnsureArgsman(const node::NodeContext& node);
ArgsManager& EnsureAnyArgsman(const std::any& context); ArgsManager& EnsureAnyArgsman(const std::any& context);
ChainstateManager& EnsureChainman(const NodeContext& node); ChainstateManager& EnsureChainman(const node::NodeContext& node);
ChainstateManager& EnsureAnyChainman(const std::any& context); ChainstateManager& EnsureAnyChainman(const std::any& context);
CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node); CBlockPolicyEstimator& EnsureFeeEstimator(const node::NodeContext& node);
CBlockPolicyEstimator& EnsureAnyFeeEstimator(const std::any& context); CBlockPolicyEstimator& EnsureAnyFeeEstimator(const std::any& context);
CConnman& EnsureConnman(const NodeContext& node); CConnman& EnsureConnman(const node::NodeContext& node);
PeerManager& EnsurePeerman(const NodeContext& node); PeerManager& EnsurePeerman(const node::NodeContext& node);
#endif // BITCOIN_RPC_SERVER_UTIL_H #endif // BITCOIN_RPC_SERVER_UTIL_H

View File

@ -16,6 +16,10 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using node::BlockAssembler;
using node::CBlockTemplate;
using node::IncrementExtraNonce;
BOOST_AUTO_TEST_SUITE(blockfilter_index_tests) BOOST_AUTO_TEST_SUITE(blockfilter_index_tests)
struct BuildChainTestingSetup : public TestChain100Setup { struct BuildChainTestingSetup : public TestChain100Setup {

View File

@ -11,6 +11,8 @@
#include <chrono> #include <chrono>
using node::CCoinsStats;
using node::CoinStatsHashType;
BOOST_AUTO_TEST_SUITE(coinstatsindex_tests) BOOST_AUTO_TEST_SUITE(coinstatsindex_tests)

View File

@ -26,6 +26,10 @@
#include <string> #include <string>
#include <vector> #include <vector>
using node::CCoinsStats;
using node::CoinStatsHashType;
using node::GetUTXOStats;
namespace { namespace {
const TestingSetup* g_setup; const TestingSetup* g_setup;
const Coin EMPTY_COIN{}; const Coin EMPTY_COIN{};

View File

@ -33,6 +33,8 @@
#include <test/fuzz/fuzz.h> #include <test/fuzz/fuzz.h>
using node::SnapshotMetadata;
void initialize_deserialize() void initialize_deserialize()
{ {
// Fuzzers using pubkey must hold an ECCVerifyHandle. // Fuzzers using pubkey must hold an ECCVerifyHandle.

View File

@ -12,6 +12,8 @@
#include <map> #include <map>
#include <numeric> #include <numeric>
using node::MakeMinisketch32;
FUZZ_TARGET(minisketch) FUZZ_TARGET(minisketch)
{ {
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};

View File

@ -18,6 +18,10 @@
#include <string> #include <string>
#include <vector> #include <vector>
using node::AnalyzePSBT;
using node::PSBTAnalysis;
using node::PSBTInputAnalysis;
void initialize_psbt() void initialize_psbt()
{ {
static const ECCVerifyHandle verify_handle; static const ECCVerifyHandle verify_handle;

View File

@ -14,6 +14,8 @@
#include <validation.h> #include <validation.h>
#include <validationinterface.h> #include <validationinterface.h>
using node::BlockAssembler;
namespace { namespace {
const TestingSetup* g_setup; const TestingSetup* g_setup;

View File

@ -13,6 +13,8 @@
#include <validation.h> #include <validation.h>
#include <validationinterface.h> #include <validationinterface.h>
using node::SnapshotMetadata;
namespace { namespace {
const std::vector<std::shared_ptr<CBlock>>* g_chain; const std::vector<std::shared_ptr<CBlock>>* g_chain;

View File

@ -24,6 +24,9 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using node::BlockAssembler;
using node::CBlockTemplate;
namespace miner_tests { namespace miner_tests {
struct MinerTestingSetup : public TestingSetup { struct MinerTestingSetup : public TestingSetup {
void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs); void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);

View File

@ -11,6 +11,8 @@
#include <utility> #include <utility>
using node::MakeMinisketch32;
BOOST_AUTO_TEST_SUITE(minisketch_tests) BOOST_AUTO_TEST_SUITE(minisketch_tests)
BOOST_AUTO_TEST_CASE(minisketch_test) BOOST_AUTO_TEST_CASE(minisketch_test)

View File

@ -8,6 +8,8 @@
#include <node/blockstorage.h> #include <node/blockstorage.h>
#include <validation.h> #include <validation.h>
using node::ReadBlockFromDisk;
using node::UndoReadFromDisk;
bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index, BlockFilter& filter) bool ComputeFilter(BlockFilterType filter_type, const CBlockIndex* block_index, BlockFilter& filter)
{ {

View File

@ -16,7 +16,7 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
const auto NoMalleation = [](CAutoFile& file, SnapshotMetadata& meta){}; const auto NoMalleation = [](CAutoFile& file, node::SnapshotMetadata& meta){};
/** /**
* Create and activate a UTXO snapshot, optionally providing a function to * Create and activate a UTXO snapshot, optionally providing a function to
@ -24,7 +24,7 @@ const auto NoMalleation = [](CAutoFile& file, SnapshotMetadata& meta){};
*/ */
template<typename F = decltype(NoMalleation)> template<typename F = decltype(NoMalleation)>
static bool static bool
CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root, F malleation = NoMalleation) CreateAndActivateUTXOSnapshot(node::NodeContext& node, const fs::path root, F malleation = NoMalleation)
{ {
// Write out a snapshot to the test's tempdir. // Write out a snapshot to the test's tempdir.
// //
@ -43,7 +43,7 @@ CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root, F malleati
// //
FILE* infile{fsbridge::fopen(snapshot_path, "rb")}; FILE* infile{fsbridge::fopen(snapshot_path, "rb")};
CAutoFile auto_infile{infile, SER_DISK, CLIENT_VERSION}; CAutoFile auto_infile{infile, SER_DISK, CLIENT_VERSION};
SnapshotMetadata metadata; node::SnapshotMetadata metadata;
auto_infile >> metadata; auto_infile >> metadata;
malleation(auto_infile, metadata); malleation(auto_infile, metadata);

View File

@ -16,6 +16,9 @@
#include <validation.h> #include <validation.h>
#include <versionbits.h> #include <versionbits.h>
using node::BlockAssembler;
using node::NodeContext;
CTxIn generatetoaddress(const NodeContext& node, const std::string& address) CTxIn generatetoaddress(const NodeContext& node, const std::string& address)
{ {
const auto dest = DecodeDestination(address); const auto dest = DecodeDestination(address);

View File

@ -13,18 +13,20 @@ class CBlock;
class CChainParams; class CChainParams;
class CScript; class CScript;
class CTxIn; class CTxIn;
namespace node {
struct NodeContext; struct NodeContext;
} // namespace node
/** Create a blockchain, starting from genesis */ /** Create a blockchain, starting from genesis */
std::vector<std::shared_ptr<CBlock>> CreateBlockChain(size_t total_height, const CChainParams& params); std::vector<std::shared_ptr<CBlock>> CreateBlockChain(size_t total_height, const CChainParams& params);
/** Returns the generated coin */ /** Returns the generated coin */
CTxIn MineBlock(const NodeContext&, const CScript& coinbase_scriptPubKey); CTxIn MineBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey);
/** Prepare a block to be mined */ /** Prepare a block to be mined */
std::shared_ptr<CBlock> PrepareBlock(const NodeContext&, const CScript& coinbase_scriptPubKey); std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey);
/** RPC-like helper function, returns the generated coin */ /** RPC-like helper function, returns the generated coin */
CTxIn generatetoaddress(const NodeContext&, const std::string& address); CTxIn generatetoaddress(const node::NodeContext&, const std::string& address);
#endif // BITCOIN_TEST_UTIL_MINING_H #endif // BITCOIN_TEST_UTIL_MINING_H

View File

@ -43,6 +43,14 @@
#include <functional> #include <functional>
using node::BlockAssembler;
using node::CalculateCacheSizes;
using node::LoadChainstate;
using node::RegenerateCommitments;
using node::VerifyLoadedChainstate;
using node::fPruneMode;
using node::fReindex;
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr; const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
UrlDecodeFn* const URL_DECODE = nullptr; UrlDecodeFn* const URL_DECODE = nullptr;

View File

@ -26,11 +26,13 @@
extern const std::function<void(const std::string&)> G_TEST_LOG_FUN; extern const std::function<void(const std::string&)> G_TEST_LOG_FUN;
// Enable BOOST_CHECK_EQUAL for enum class types // Enable BOOST_CHECK_EQUAL for enum class types
namespace std {
template <typename T> template <typename T>
std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, const T& e) std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, const T& e)
{ {
return stream << static_cast<typename std::underlying_type<T>::type>(e); return stream << static_cast<typename std::underlying_type<T>::type>(e);
} }
} // namespace std
/** /**
* This global and the helpers that use it are not thread-safe. * This global and the helpers that use it are not thread-safe.
@ -76,7 +78,7 @@ static constexpr CAmount CENT{1000000};
*/ */
struct BasicTestingSetup { struct BasicTestingSetup {
ECCVerifyHandle globalVerifyHandle; ECCVerifyHandle globalVerifyHandle;
NodeContext m_node; node::NodeContext m_node;
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {}); explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
~BasicTestingSetup(); ~BasicTestingSetup();
@ -90,7 +92,7 @@ struct BasicTestingSetup {
* initialization behaviour. * initialization behaviour.
*/ */
struct ChainTestingSetup : public BasicTestingSetup { struct ChainTestingSetup : public BasicTestingSetup {
CacheSizes m_cache_sizes{}; node::CacheSizes m_cache_sizes{};
explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {}); explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
~ChainTestingSetup(); ~ChainTestingSetup();

View File

@ -12,6 +12,8 @@
#include <wallet/wallet.h> #include <wallet/wallet.h>
#endif #endif
using wallet::CWallet;
const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj"; const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET

View File

@ -7,7 +7,9 @@
#include <string> #include <string>
namespace wallet {
class CWallet; class CWallet;
} // namespace wallet
// Constants // // Constants //
@ -16,9 +18,9 @@ extern const std::string ADDRESS_BCRT1_UNSPENDABLE;
// RPC-like // // RPC-like //
/** Import the address to the wallet */ /** Import the address to the wallet */
void importaddress(CWallet& wallet, const std::string& address); void importaddress(wallet::CWallet& wallet, const std::string& address);
/** Returns a new address from the wallet */ /** Returns a new address from the wallet */
std::string getnewaddress(CWallet& w); std::string getnewaddress(wallet::CWallet& w);
#endif // BITCOIN_TEST_UTIL_WALLET_H #endif // BITCOIN_TEST_UTIL_WALLET_H

View File

@ -19,6 +19,8 @@
#include <thread> #include <thread>
using node::BlockAssembler;
namespace validation_block_tests { namespace validation_block_tests {
struct MinerTestingSetup : public RegTestingSetup { struct MinerTestingSetup : public RegTestingSetup {
std::shared_ptr<CBlock> Block(const uint256& prev_hash); std::shared_ptr<CBlock> Block(const uint256& prev_hash);

View File

@ -20,6 +20,8 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using node::SnapshotMetadata;
BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, ChainTestingSetup) BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, ChainTestingSetup)
//! Basic tests for ChainstateManager. //! Basic tests for ChainstateManager.

View File

@ -9,6 +9,8 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
using node::BlockManager;
BOOST_FIXTURE_TEST_SUITE(validation_flush_tests, ChainTestingSetup) BOOST_FIXTURE_TEST_SUITE(validation_flush_tests, ChainTestingSetup)
//! Test utilities for detecting when we need to flush the coins cache based //! Test utilities for detecting when we need to flush the coins cache based

View File

@ -62,6 +62,25 @@
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
using node::BLOCKFILE_CHUNK_SIZE;
using node::BlockManager;
using node::BlockMap;
using node::CBlockIndexWorkComparator;
using node::CCoinsStats;
using node::CoinStatsHashType;
using node::GetUTXOStats;
using node::OpenBlockFile;
using node::ReadBlockFromDisk;
using node::SnapshotMetadata;
using node::UNDOFILE_CHUNK_SIZE;
using node::UndoReadFromDisk;
using node::UnlinkPrunedFiles;
using node::fHavePruned;
using node::fImporting;
using node::fPruneMode;
using node::fReindex;
using node::nPruneTarget;
#define MICRO 0.000001 #define MICRO 0.000001
#define MILLI 0.001 #define MILLI 0.001

View File

@ -43,12 +43,14 @@ class CBlockTreeDB;
class CChainParams; class CChainParams;
class CTxMemPool; class CTxMemPool;
class ChainstateManager; class ChainstateManager;
class SnapshotMetadata;
struct ChainTxData; struct ChainTxData;
struct DisconnectedBlockTransactions; struct DisconnectedBlockTransactions;
struct PrecomputedTransactionData; struct PrecomputedTransactionData;
struct LockPoints; struct LockPoints;
struct AssumeutxoData; struct AssumeutxoData;
namespace node {
class SnapshotMetadata;
} // namespace node
/** Default for -minrelaytxfee, minimum relay fee for transactions */ /** Default for -minrelaytxfee, minimum relay fee for transactions */
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000; static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
@ -476,7 +478,7 @@ protected:
public: public:
//! Reference to a BlockManager instance which itself is shared across all //! Reference to a BlockManager instance which itself is shared across all
//! CChainState instances. //! CChainState instances.
BlockManager& m_blockman; node::BlockManager& m_blockman;
/** Chain parameters for this chainstate */ /** Chain parameters for this chainstate */
const CChainParams& m_params; const CChainParams& m_params;
@ -488,7 +490,7 @@ public:
explicit CChainState( explicit CChainState(
CTxMemPool* mempool, CTxMemPool* mempool,
BlockManager& blockman, node::BlockManager& blockman,
ChainstateManager& chainman, ChainstateManager& chainman,
std::optional<uint256> from_snapshot_blockhash = std::nullopt); std::optional<uint256> from_snapshot_blockhash = std::nullopt);
@ -535,7 +537,7 @@ public:
* chainstates) and as good as our current tip or better. Entries may be failed, * chainstates) and as good as our current tip or better. Entries may be failed,
* though, and pruning nodes may be missing the data for the block. * though, and pruning nodes may be missing the data for the block.
*/ */
std::set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexCandidates; std::set<CBlockIndex*, node::CBlockIndexWorkComparator> setBlockIndexCandidates;
//! @returns A reference to the in-memory cache of the UTXO set. //! @returns A reference to the in-memory cache of the UTXO set.
CCoinsViewCache& CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main) CCoinsViewCache& CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@ -803,13 +805,13 @@ private:
bool m_snapshot_validated{false}; bool m_snapshot_validated{false};
CBlockIndex* m_best_invalid; CBlockIndex* m_best_invalid;
friend bool BlockManager::LoadBlockIndex(const Consensus::Params&, ChainstateManager&); friend bool node::BlockManager::LoadBlockIndex(const Consensus::Params&, ChainstateManager&);
//! Internal helper for ActivateSnapshot(). //! Internal helper for ActivateSnapshot().
[[nodiscard]] bool PopulateAndValidateSnapshot( [[nodiscard]] bool PopulateAndValidateSnapshot(
CChainState& snapshot_chainstate, CChainState& snapshot_chainstate,
CAutoFile& coins_file, CAutoFile& coins_file,
const SnapshotMetadata& metadata); const node::SnapshotMetadata& metadata);
/** /**
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure * If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
@ -826,7 +828,7 @@ public:
std::thread m_load_block; std::thread m_load_block;
//! A single BlockManager instance is shared across each constructed //! A single BlockManager instance is shared across each constructed
//! chainstate to avoid duplicating block metadata. //! chainstate to avoid duplicating block metadata.
BlockManager m_blockman GUARDED_BY(::cs_main); node::BlockManager m_blockman GUARDED_BY(::cs_main);
/** /**
* In order to efficiently track invalidity of headers, we keep the set of * In order to efficiently track invalidity of headers, we keep the set of
@ -886,7 +888,7 @@ public:
//! - Move the new chainstate to `m_snapshot_chainstate` and make it our //! - Move the new chainstate to `m_snapshot_chainstate` and make it our
//! ChainstateActive(). //! ChainstateActive().
[[nodiscard]] bool ActivateSnapshot( [[nodiscard]] bool ActivateSnapshot(
CAutoFile& coins_file, const SnapshotMetadata& metadata, bool in_memory); CAutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory);
//! The most-work chain. //! The most-work chain.
CChainState& ActiveChainstate() const; CChainState& ActiveChainstate() const;
@ -894,7 +896,7 @@ public:
int ActiveHeight() const { return ActiveChain().Height(); } int ActiveHeight() const { return ActiveChain().Height(); }
CBlockIndex* ActiveTip() const { return ActiveChain().Tip(); } CBlockIndex* ActiveTip() const { return ActiveChain().Tip(); }
BlockMap& BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) node::BlockMap& BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{ {
return m_blockman.m_block_index; return m_blockman.m_block_index;
} }

View File

@ -15,6 +15,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
namespace wallet {
namespace { namespace {
//! Make sure database has a unique fileid within the environment. If it //! Make sure database has a unique fileid within the environment. If it
@ -846,3 +847,4 @@ std::unique_ptr<BerkeleyDatabase> MakeBerkeleyDatabase(const fs::path& path, con
status = DatabaseStatus::SUCCESS; status = DatabaseStatus::SUCCESS;
return db; return db;
} }
} // namespace wallet

View File

@ -31,6 +31,7 @@
struct bilingual_str; struct bilingual_str;
namespace wallet {
static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100; static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100;
static const bool DEFAULT_WALLET_PRIVDB = true; static const bool DEFAULT_WALLET_PRIVDB = true;
@ -229,5 +230,6 @@ bool BerkeleyDatabaseSanityCheck();
//! Return object giving access to Berkeley database at specified path. //! Return object giving access to Berkeley database at specified path.
std::unique_ptr<BerkeleyDatabase> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error); std::unique_ptr<BerkeleyDatabase> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
} // namespace wallet
#endif // BITCOIN_WALLET_BDB_H #endif // BITCOIN_WALLET_BDB_H

View File

@ -6,7 +6,9 @@
#include <util/system.h> #include <util/system.h>
namespace wallet {
CCoinControl::CCoinControl() CCoinControl::CCoinControl()
{ {
m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS); m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
} }
} // namespace wallet

View File

@ -18,6 +18,7 @@
#include <map> #include <map>
#include <set> #include <set>
namespace wallet {
const int DEFAULT_MIN_DEPTH = 0; const int DEFAULT_MIN_DEPTH = 0;
const int DEFAULT_MAX_DEPTH = 9999999; const int DEFAULT_MAX_DEPTH = 9999999;
@ -118,5 +119,6 @@ private:
std::set<COutPoint> setSelected; std::set<COutPoint> setSelected;
std::map<COutPoint, CTxOut> m_external_txouts; std::map<COutPoint, CTxOut> m_external_txouts;
}; };
} // namespace wallet
#endif // BITCOIN_WALLET_COINCONTROL_H #endif // BITCOIN_WALLET_COINCONTROL_H

View File

@ -13,6 +13,7 @@
#include <numeric> #include <numeric>
#include <optional> #include <optional>
namespace wallet {
// Descending order comparator // Descending order comparator
struct { struct {
bool operator()(const OutputGroup& a, const OutputGroup& b) const bool operator()(const OutputGroup& a, const OutputGroup& b) const
@ -429,3 +430,4 @@ bool SelectionResult::operator<(SelectionResult other) const
// As this operator is only used in std::min_element, we want the result that has more inputs when waste are equal. // As this operator is only used in std::min_element, we want the result that has more inputs when waste are equal.
return *m_waste < *other.m_waste || (*m_waste == *other.m_waste && m_selected_inputs.size() > other.m_selected_inputs.size()); return *m_waste < *other.m_waste || (*m_waste == *other.m_waste && m_selected_inputs.size() > other.m_selected_inputs.size());
} }
} // namespace wallet

View File

@ -12,6 +12,7 @@
#include <optional> #include <optional>
namespace wallet {
//! target minimum change amount //! target minimum change amount
static constexpr CAmount MIN_CHANGE{COIN / 100}; static constexpr CAmount MIN_CHANGE{COIN / 100};
//! final minimum change amount after paying for fees //! final minimum change amount after paying for fees
@ -249,5 +250,6 @@ std::optional<SelectionResult> SelectCoinsSRD(const std::vector<OutputGroup>& ut
// Original coin selection algorithm as a fallback // Original coin selection algorithm as a fallback
std::optional<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, const CAmount& nTargetValue); std::optional<SelectionResult> KnapsackSolver(std::vector<OutputGroup>& groups, const CAmount& nTargetValue);
} // namespace wallet
#endif // BITCOIN_WALLET_COINSELECTION_H #endif // BITCOIN_WALLET_COINSELECTION_H

View File

@ -4,5 +4,7 @@
#include <wallet/context.h> #include <wallet/context.h>
namespace wallet {
WalletContext::WalletContext() {} WalletContext::WalletContext() {}
WalletContext::~WalletContext() {} WalletContext::~WalletContext() {}
} // namespace wallet

View File

@ -13,12 +13,13 @@
#include <vector> #include <vector>
class ArgsManager; class ArgsManager;
class CWallet;
namespace interfaces { namespace interfaces {
class Chain; class Chain;
class Wallet; class Wallet;
} // namespace interfaces } // namespace interfaces
namespace wallet {
class CWallet;
using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>; using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wallet)>;
//! WalletContext struct containing references to state shared between CWallet //! WalletContext struct containing references to state shared between CWallet
@ -46,5 +47,6 @@ struct WalletContext {
WalletContext(); WalletContext();
~WalletContext(); ~WalletContext();
}; };
} // namespace wallet
#endif // BITCOIN_WALLET_CONTEXT_H #endif // BITCOIN_WALLET_CONTEXT_H

View File

@ -10,6 +10,7 @@
#include <vector> #include <vector>
namespace wallet {
int CCrypter::BytesToKeySHA512AES(const std::vector<unsigned char>& chSalt, const SecureString& strKeyData, int count, unsigned char *key,unsigned char *iv) const int CCrypter::BytesToKeySHA512AES(const std::vector<unsigned char>& chSalt, const SecureString& strKeyData, int count, unsigned char *key,unsigned char *iv) const
{ {
// This mimics the behavior of openssl's EVP_BytesToKey with an aes256cbc // This mimics the behavior of openssl's EVP_BytesToKey with an aes256cbc
@ -136,3 +137,4 @@ bool DecryptKey(const CKeyingMaterial& vMasterKey, const std::vector<unsigned ch
key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed()); key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed());
return key.VerifyPubKey(vchPubKey); return key.VerifyPubKey(vchPubKey);
} }
} // namespace wallet

View File

@ -10,6 +10,7 @@
#include <script/signingprovider.h> #include <script/signingprovider.h>
namespace wallet {
const unsigned int WALLET_CRYPTO_KEY_SIZE = 32; const unsigned int WALLET_CRYPTO_KEY_SIZE = 32;
const unsigned int WALLET_CRYPTO_SALT_SIZE = 8; const unsigned int WALLET_CRYPTO_SALT_SIZE = 8;
const unsigned int WALLET_CRYPTO_IV_SIZE = 16; const unsigned int WALLET_CRYPTO_IV_SIZE = 16;
@ -105,5 +106,6 @@ public:
bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext); bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext);
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext); bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext);
bool DecryptKey(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCryptedSecret, const CPubKey& vchPubKey, CKey& key); bool DecryptKey(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCryptedSecret, const CPubKey& vchPubKey, CKey& key);
} // namespace wallet
#endif // BITCOIN_WALLET_CRYPTER_H #endif // BITCOIN_WALLET_CRYPTER_H

Some files were not shown because too many files have changed in this diff Show More