Skip to content

Commit

Permalink
[backport#15288] Remove use of uiInterface.LoadWallet in wallet code
Browse files Browse the repository at this point in the history
Summary:
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.

1106a6fde4bfde31a16de45e4cc84ed5da05c5a4 (Russell Yanofksi)

---

Depends on D5867

This is a partial backport of Core [[bitcoin/bitcoin#15288 | PR15288]]

Test Plan:
  cmake .. -GNinja -DENABLE_WERROR=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_BITCOIN_WALLET=OFF
  ninja check-all
  cmake .. -GNinja -DENABLE_WERROR=ON -DCMAKE_BUILD_TYPE=Debug
  ninja check-all

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D5868
  • Loading branch information
ryanofsky authored and majcosta committed Apr 28, 2020
1 parent ceaafd2 commit c734263
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,6 @@ bitcoin_wallet_LDADD = \
$(LIBBITCOIN_WALLET_TOOL) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_UTIL) \
Expand Down
2 changes: 0 additions & 2 deletions src/Makefile.bench.include
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
bench_bench_bitcoin_LDADD = \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_SERVER) \
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <chain.h>
#include <chainparams.h>
#include <interfaces/wallet.h>
#include <net.h>
#include <policy/mempool.h>
#include <primitives/block.h>
Expand Down Expand Up @@ -253,6 +254,9 @@ namespace {
void initError(const std::string &message) override {
InitError(message);
}
void loadWallet(std::unique_ptr<Wallet> wallet) override {
::uiInterface.LoadWallet(wallet);
}
};

} // namespace
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ struct Params;

namespace interfaces {

class Wallet;

//! Interface for giving wallet processes access to blockchain state.
class Chain {
public:
Expand Down Expand Up @@ -187,6 +189,9 @@ class Chain {

//! Send init error.
virtual void initError(const std::string &message) = 0;

//! Send wallet load notification to the GUI.
virtual void loadWallet(std::unique_ptr<Wallet> wallet) = 0;
};

//! Interface to let node manage chain clients (wallets, or maybe tools for
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ namespace {
}
std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override {
return MakeHandler(::uiInterface.LoadWallet_connect(
[fn](std::shared_ptr<CWallet> wallet) {
fn(MakeWallet(wallet));
[fn](std::unique_ptr<Wallet> &wallet) {
fn(std::move(wallet));
}));
}
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(
Expand Down
3 changes: 2 additions & 1 deletion src/ui_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) {
void CClientUIInterface::NotifyAlertChanged() {
return g_ui_signals.NotifyAlertChanged();
}
void CClientUIInterface::LoadWallet(std::shared_ptr<CWallet> wallet) {
void CClientUIInterface::LoadWallet(
std::unique_ptr<interfaces::Wallet> &wallet) {
return g_ui_signals.LoadWallet(wallet);
}
void CClientUIInterface::ShowProgress(const std::string &title, int nProgress,
Expand Down
8 changes: 6 additions & 2 deletions src/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
#include <memory>
#include <string>

class CWallet;
class CBlockIndex;
namespace boost {
namespace signals2 {
class connection;
}
} // namespace boost

namespace interfaces {
class Wallet;
} // namespace interfaces

/** General change type (added, updated, removed). */
enum ChangeType { CT_NEW, CT_UPDATED, CT_DELETED };

Expand Down Expand Up @@ -115,7 +118,8 @@ class CClientUIInterface {
ADD_SIGNALS_DECL_WRAPPER(NotifyAlertChanged, void, );

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

/**
* Show progress e.g. for verifychain.
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <consensus/validation.h>
#include <fs.h>
#include <interfaces/chain.h>
#include <interfaces/wallet.h>
#include <key.h>
#include <key_io.h>
#include <keystore.h>
Expand Down Expand Up @@ -4781,7 +4782,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(
}
}

uiInterface.LoadWallet(walletInstance);
chain.loadWallet(interfaces::MakeWallet(walletInstance));

// Register with the validation interface. It's ok to do this after rescan
// since we're still holding cs_main.
Expand Down

0 comments on commit c734263

Please sign in to comment.