Skip to content

Commit 1106a6f

Browse files
committed
Remove use of uiInterface.LoadWallet in wallet code
This also changes the uiInterface.LoadWallet signal argument type from shared_ptr<CWallet> to unique_ptr<interfaces::Wallet> because CWallet is an internal wallet class that shouldn't be used in non-wallet code (and also can't be passed across process boundaries). This commit does not change behavior.
1 parent 318f41f commit 1106a6f

File tree

8 files changed

+16
-9
lines changed

8 files changed

+16
-9
lines changed

src/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,6 @@ bitcoin_wallet_LDADD = \
562562
$(LIBBITCOIN_WALLET_TOOL) \
563563
$(LIBBITCOIN_WALLET) \
564564
$(LIBBITCOIN_SERVER) \
565-
$(LIBBITCOIN_WALLET) \
566-
$(LIBBITCOIN_SERVER) \
567565
$(LIBBITCOIN_COMMON) \
568566
$(LIBBITCOIN_CONSENSUS) \
569567
$(LIBBITCOIN_UTIL) \

src/Makefile.bench.include

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)
3737
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
3838
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
3939
bench_bench_bitcoin_LDADD = \
40-
$(LIBBITCOIN_WALLET) \
41-
$(LIBBITCOIN_SERVER) \
4240
$(LIBBITCOIN_WALLET) \
4341
$(LIBBITCOIN_SERVER) \
4442
$(LIBBITCOIN_COMMON) \

src/interfaces/chain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <chain.h>
88
#include <chainparams.h>
9+
#include <interfaces/wallet.h>
910
#include <net.h>
1011
#include <policy/fees.h>
1112
#include <policy/policy.h>
@@ -251,6 +252,7 @@ class ChainImpl : public Chain
251252
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
252253
void initWarning(const std::string& message) override { InitWarning(message); }
253254
void initError(const std::string& message) override { InitError(message); }
255+
void loadWallet(std::unique_ptr<Wallet> wallet) override { ::uiInterface.LoadWallet(wallet); }
254256
};
255257

256258
} // namespace

src/interfaces/chain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct FeeCalculation;
2424

2525
namespace interfaces {
2626

27+
class Wallet;
28+
2729
//! Interface for giving wallet processes access to blockchain state.
2830
class Chain
2931
{
@@ -187,6 +189,9 @@ class Chain
187189

188190
//! Send init error.
189191
virtual void initError(const std::string& message) = 0;
192+
193+
//! Send wallet load notification to the GUI.
194+
virtual void loadWallet(std::unique_ptr<Wallet> wallet) = 0;
190195
};
191196

192197
//! Interface to let node manage chain clients (wallets, or maybe tools for

src/interfaces/node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class NodeImpl : public Node
275275
}
276276
std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
277277
{
278-
return MakeHandler(::uiInterface.LoadWallet_connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); }));
278+
return MakeHandler(::uiInterface.LoadWallet_connect([fn](std::unique_ptr<Wallet>& wallet) { fn(std::move(wallet)); }));
279279
}
280280
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
281281
{

src/ui_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_s
5252
void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); }
5353
void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); }
5454
void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
55-
void CClientUIInterface::LoadWallet(std::shared_ptr<CWallet> wallet) { return g_ui_signals.LoadWallet(wallet); }
55+
void CClientUIInterface::LoadWallet(std::unique_ptr<interfaces::Wallet>& wallet) { return g_ui_signals.LoadWallet(wallet); }
5656
void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
5757
void CClientUIInterface::NotifyBlockTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(b, i); }
5858
void CClientUIInterface::NotifyHeaderTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(b, i); }

src/ui_interface.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
#include <stdint.h>
1212
#include <string>
1313

14-
class CWallet;
1514
class CBlockIndex;
1615
namespace boost {
1716
namespace signals2 {
1817
class connection;
1918
}
2019
} // namespace boost
2120

21+
namespace interfaces {
22+
class Wallet;
23+
} // namespace interfaces
24+
2225
/** General change type (added, updated, removed). */
2326
enum ChangeType
2427
{
@@ -102,7 +105,7 @@ class CClientUIInterface
102105
ADD_SIGNALS_DECL_WRAPPER(NotifyAlertChanged, void, );
103106

104107
/** A wallet has been loaded. */
105-
ADD_SIGNALS_DECL_WRAPPER(LoadWallet, void, std::shared_ptr<CWallet> wallet);
108+
ADD_SIGNALS_DECL_WRAPPER(LoadWallet, void, std::unique_ptr<interfaces::Wallet>& wallet);
106109

107110
/**
108111
* Show progress e.g. for verifychain.

src/wallet/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <consensus/validation.h>
1313
#include <fs.h>
1414
#include <interfaces/chain.h>
15+
#include <interfaces/wallet.h>
1516
#include <key.h>
1617
#include <key_io.h>
1718
#include <keystore.h>
@@ -4391,7 +4392,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
43914392
}
43924393
}
43934394

4394-
uiInterface.LoadWallet(walletInstance);
4395+
chain.loadWallet(interfaces::MakeWallet(walletInstance));
43954396

43964397
// Register with the validation interface. It's ok to do this after rescan since we're still holding cs_main.
43974398
RegisterValidationInterface(walletInstance.get());

0 commit comments

Comments
 (0)