diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -3,7 +3,6 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include // For Params() #include #include #include @@ -12,36 +11,23 @@ #include #include -struct WalletTestingSetup { - std::unique_ptr m_chain = interfaces::MakeChain(); - CWallet m_wallet; - - WalletTestingSetup() - : m_wallet{Params(), m_chain.get(), WalletLocation(), - WalletDatabase::CreateMock()} {} - - void handleNotifications() { - m_wallet.m_chain_notifications_handler = - m_chain->handleNotifications(m_wallet); - } -}; - static void WalletBalance(benchmark::State &state, const bool set_dirty, const bool add_watchonly, const bool add_mine) { const auto &ADDRESS_WATCHONLY = ADDRESS_BCHREG_UNSPENDABLE; - WalletTestingSetup wallet_t{}; - auto &wallet = wallet_t.m_wallet; + const Config &config = GetConfig(); + + std::unique_ptr chain = interfaces::MakeChain(); + CWallet wallet{config.GetChainParams(), chain.get(), WalletLocation(), + WalletDatabase::CreateMock()}; { bool first_run; if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) { assert(false); } - wallet_t.handleNotifications(); + wallet.handleNotifications(); } - const Config &config = GetConfig(); - const Optional address_mine{ add_mine ? Optional{getnewaddress(config, wallet)} : nullopt}; diff --git a/src/wallet/test/wallet_test_fixture.cpp b/src/wallet/test/wallet_test_fixture.cpp --- a/src/wallet/test/wallet_test_fixture.cpp +++ b/src/wallet/test/wallet_test_fixture.cpp @@ -17,8 +17,7 @@ WalletDatabase::CreateMock()) { bool fFirstRun; m_wallet.LoadWallet(fFirstRun); - m_wallet.m_chain_notifications_handler = - m_chain->handleNotifications(m_wallet); + m_wallet.handleNotifications(); m_chain_client->registerRpcs(); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -872,6 +872,9 @@ /** Registered interfaces::Chain::Notifications handler. */ std::unique_ptr m_chain_notifications_handler; + /** Register the wallet for chain notifications */ + void handleNotifications(); + /** Interface for accessing chain state. */ interfaces::Chain &chain() const { assert(m_chain); @@ -1446,8 +1449,6 @@ * Add a KeyOriginInfo to the wallet */ bool AddKeyOrigin(const CPubKey &pubkey, const KeyOriginInfo &info); - - friend struct WalletTestingSetup; }; /** diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4818,8 +4818,7 @@ // Register with the validation interface. It's ok to do this after rescan // since we're still holding locked_chain. - walletInstance->m_chain_notifications_handler = - chain.handleNotifications(*walletInstance); + walletInstance->handleNotifications(); walletInstance->SetBroadcastTransactions( gArgs.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST)); @@ -4834,6 +4833,10 @@ return walletInstance; } +void CWallet::handleNotifications() { + m_chain_notifications_handler = m_chain->handleNotifications(*this); +} + void CWallet::postInitProcess() { // Add wallet transactions that aren't already in a block to mempool. // Do this here as mempool requires genesis block to be loaded.