Skip to content

Commit fad7c33

Browse files
author
MarcoFalke
committed
refactor: Add handleNotifications method to wallet
Further stylistic cleanups in touched files: * Sort the includes * Wrap long single-line constructors into multiple lines
1 parent fa46ac3 commit fad7c33

File tree

4 files changed

+27
-32
lines changed

4 files changed

+27
-32
lines changed

src/bench/wallet_balance.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,16 @@
1010
#include <validationinterface.h>
1111
#include <wallet/wallet.h>
1212

13-
struct WalletTestingSetup {
14-
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain();
15-
CWallet m_wallet;
16-
17-
WalletTestingSetup()
18-
: m_wallet{m_chain.get(), WalletLocation(), WalletDatabase::CreateMock()}
19-
{
20-
}
21-
22-
void handleNotifications()
23-
{
24-
m_wallet.m_chain_notifications_handler = m_chain->handleNotifications(m_wallet);
25-
}
26-
};
27-
2813
static void WalletBalance(benchmark::State& state, const bool set_dirty, const bool add_watchonly, const bool add_mine)
2914
{
3015
const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;
3116

32-
WalletTestingSetup wallet_t{};
33-
auto& wallet = wallet_t.m_wallet;
17+
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain();
18+
CWallet wallet{chain.get(), WalletLocation(), WalletDatabase::CreateMock()};
3419
{
3520
bool first_run;
3621
if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) assert(false);
37-
wallet_t.handleNotifications();
22+
wallet.handleNotifications();
3823
}
3924

4025

src/wallet/test/wallet_test_fixture.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
#include <wallet/db.h>
99
#include <wallet/rpcwallet.h>
1010

11-
WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
12-
TestingSetup(chainName), m_wallet(m_chain.get(), WalletLocation(), WalletDatabase::CreateMock())
11+
WalletTestingSetup::WalletTestingSetup(const std::string& chainName)
12+
: TestingSetup(chainName),
13+
m_wallet(m_chain.get(), WalletLocation(), WalletDatabase::CreateMock())
1314
{
1415
bool fFirstRun;
1516
m_wallet.LoadWallet(fFirstRun);
16-
m_wallet.m_chain_notifications_handler = m_chain->handleNotifications(m_wallet);
17+
m_wallet.handleNotifications();
1718

1819
m_chain_client->registerRpcs();
1920
}

src/wallet/wallet.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
#include <wallet/wallet.h>
77

8-
#include <checkpoints.h>
98
#include <chain.h>
10-
#include <wallet/coincontrol.h>
9+
#include <checkpoints.h>
1110
#include <consensus/consensus.h>
1211
#include <consensus/validation.h>
1312
#include <fs.h>
@@ -16,7 +15,6 @@
1615
#include <key.h>
1716
#include <key_io.h>
1817
#include <keystore.h>
19-
#include <validation.h>
2018
#include <net.h>
2119
#include <policy/fees.h>
2220
#include <policy/policy.h>
@@ -34,6 +32,8 @@
3432
#include <util/moneystr.h>
3533
#include <util/rbf.h>
3634
#include <util/validation.h>
35+
#include <validation.h>
36+
#include <wallet/coincontrol.h>
3737
#include <wallet/fees.h>
3838

3939
#include <algorithm>
@@ -4303,7 +4303,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
43034303
chain.loadWallet(interfaces::MakeWallet(walletInstance));
43044304

43054305
// Register with the validation interface. It's ok to do this after rescan since we're still holding locked_chain.
4306-
walletInstance->m_chain_notifications_handler = chain.handleNotifications(*walletInstance);
4306+
walletInstance->handleNotifications();
43074307

43084308
walletInstance->SetBroadcastTransactions(gArgs.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST));
43094309

@@ -4316,6 +4316,11 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
43164316
return walletInstance;
43174317
}
43184318

4319+
void CWallet::handleNotifications()
4320+
{
4321+
m_chain_notifications_handler = m_chain->handleNotifications(*this);
4322+
}
4323+
43194324
void CWallet::postInitProcess()
43204325
{
43214326
auto locked_chain = chain().lock();

src/wallet/wallet.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
#include <interfaces/handler.h>
1212
#include <outputtype.h>
1313
#include <policy/feerate.h>
14+
#include <script/ismine.h>
15+
#include <script/sign.h>
1416
#include <streams.h>
1517
#include <tinyformat.h>
1618
#include <ui_interface.h>
1719
#include <util/strencodings.h>
18-
#include <validationinterface.h>
19-
#include <script/ismine.h>
20-
#include <script/sign.h>
2120
#include <util/system.h>
22-
#include <wallet/crypter.h>
21+
#include <validationinterface.h>
2322
#include <wallet/coinselection.h>
23+
#include <wallet/crypter.h>
2424
#include <wallet/walletdb.h>
2525
#include <wallet/walletutil.h>
2626

@@ -767,7 +767,10 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
767767
unsigned int nMasterKeyMaxID = 0;
768768

769769
/** Construct wallet with specified name and database implementation. */
770-
CWallet(interfaces::Chain* chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database) : m_chain(chain), m_location(location), database(std::move(database))
770+
CWallet(interfaces::Chain* chain, const WalletLocation& location, std::unique_ptr<WalletDatabase> database)
771+
: m_chain(chain),
772+
m_location(location),
773+
database(std::move(database))
771774
{
772775
}
773776

@@ -794,6 +797,9 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
794797
/** Registered interfaces::Chain::Notifications handler. */
795798
std::unique_ptr<interfaces::Handler> m_chain_notifications_handler;
796799

800+
/** Register the wallet for chain notifications */
801+
void handleNotifications();
802+
797803
/** Interface for accessing chain state. */
798804
interfaces::Chain& chain() const { assert(m_chain); return *m_chain; }
799805

@@ -1208,8 +1214,6 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
12081214

12091215
/** Add a KeyOriginInfo to the wallet */
12101216
bool AddKeyOrigin(const CPubKey& pubkey, const KeyOriginInfo& info);
1211-
1212-
friend struct WalletTestingSetup;
12131217
};
12141218

12151219
/**

0 commit comments

Comments
 (0)