From fad7c33342cb51b310a7dd372bfa675df8810367 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 17 Apr 2019 13:27:02 -0400 Subject: refactor: Add handleNotifications method to wallet Further stylistic cleanups in touched files: * Sort the includes * Wrap long single-line constructors into multiple lines --- src/bench/wallet_balance.cpp | 21 +++------------------ src/wallet/test/wallet_test_fixture.cpp | 7 ++++--- src/wallet/wallet.cpp | 13 +++++++++---- src/wallet/wallet.h | 18 +++++++++++------- 4 files changed, 27 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index 7fd2794164..46ca12826b 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -10,31 +10,16 @@ #include #include -struct WalletTestingSetup { - std::unique_ptr m_chain = interfaces::MakeChain(); - CWallet m_wallet; - - WalletTestingSetup() - : m_wallet{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_BCRT1_UNSPENDABLE; - WalletTestingSetup wallet_t{}; - auto& wallet = wallet_t.m_wallet; + std::unique_ptr chain = interfaces::MakeChain(); + CWallet wallet{chain.get(), WalletLocation(), WalletDatabase::CreateMock()}; { bool first_run; if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) assert(false); - wallet_t.handleNotifications(); + wallet.handleNotifications(); } diff --git a/src/wallet/test/wallet_test_fixture.cpp b/src/wallet/test/wallet_test_fixture.cpp index 7b82994539..6526e69eea 100644 --- a/src/wallet/test/wallet_test_fixture.cpp +++ b/src/wallet/test/wallet_test_fixture.cpp @@ -8,12 +8,13 @@ #include #include -WalletTestingSetup::WalletTestingSetup(const std::string& chainName): - TestingSetup(chainName), m_wallet(m_chain.get(), WalletLocation(), WalletDatabase::CreateMock()) +WalletTestingSetup::WalletTestingSetup(const std::string& chainName) + : TestingSetup(chainName), + m_wallet(m_chain.get(), WalletLocation(), 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.cpp b/src/wallet/wallet.cpp index 98ba489729..4737e2f6f4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5,9 +5,8 @@ #include -#include #include -#include +#include #include #include #include @@ -16,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -4303,7 +4303,7 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, chain.loadWallet(interfaces::MakeWallet(walletInstance)); // 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)); @@ -4316,6 +4316,11 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, return walletInstance; } +void CWallet::handleNotifications() +{ + m_chain_notifications_handler = m_chain->handleNotifications(*this); +} + void CWallet::postInitProcess() { auto locked_chain = chain().lock(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 53de1ea065..62ba0aa962 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -11,16 +11,16 @@ #include #include #include +#include