aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-04-17 15:10:47 -0400
committerJohn Newbery <john@johnnewbery.com>2018-04-04 16:52:40 -0400
commit5fba3af21e44ab7552c57782de430c1f4cfd6697 (patch)
treedd34ef0bbf69f24f9bd4cc2a615a0398e6cf79a9
parentc2f672fb1960399389dea9cdd8f76d7156c2c88b (diff)
Remove direct bitcoin calls from qt/splashscreen.cpp
-rw-r--r--src/Makefile.am3
-rw-r--r--src/Makefile.qt.include4
-rw-r--r--src/Makefile.qttest.include2
-rw-r--r--src/interface/node.cpp21
-rw-r--r--src/interface/node.h9
-rw-r--r--src/interface/wallet.cpp32
-rw-r--r--src/interface/wallet.h35
-rw-r--r--src/qt/bitcoin.cpp2
-rw-r--r--src/qt/splashscreen.cpp40
-rw-r--r--src/qt/splashscreen.h20
10 files changed, 139 insertions, 29 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index affafaa5f9..605c932120 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,7 @@ DIST_SUBDIRS = secp256k1 univalue
AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS)
AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS)
AM_CPPFLAGS = $(HARDENED_CPPFLAGS)
+AM_LIBTOOLFLAGS = --preserve-dup-deps
EXTRA_LIBRARIES =
if EMBEDDED_UNIVALUE
@@ -106,6 +107,7 @@ BITCOIN_CORE_H = \
init.h \
interface/handler.h \
interface/node.h \
+ interface/wallet.h \
key.h \
key_io.h \
keystore.h \
@@ -247,6 +249,7 @@ endif
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_wallet_a_SOURCES = \
+ interface/wallet.cpp \
wallet/crypter.cpp \
wallet/db.cpp \
wallet/feebumper.cpp \
diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include
index 0bdde06772..38eb12ce0d 100644
--- a/src/Makefile.qt.include
+++ b/src/Makefile.qt.include
@@ -402,7 +402,7 @@ if TARGET_WINDOWS
endif
qt_bitcoin_qt_LDADD = qt/libbitcoinqt.a $(LIBBITCOIN_SERVER)
if ENABLE_WALLET
-qt_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET)
+qt_bitcoin_qt_LDADD += $(LIBBITCOIN_UTIL) $(LIBBITCOIN_WALLET)
endif
if ENABLE_ZMQ
qt_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
@@ -411,7 +411,7 @@ qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL)
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
qt_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
-qt_bitcoin_qt_LIBTOOLFLAGS = --tag CXX
+qt_bitcoin_qt_LIBTOOLFLAGS = $(AM_LIBTOOLFLAGS) --tag CXX
#locale/foo.ts -> locale/foo.qm
QT_QM=$(QT_TS:.ts=.qm)
diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include
index ea2ed17472..1279152198 100644
--- a/src/Makefile.qttest.include
+++ b/src/Makefile.qttest.include
@@ -52,7 +52,7 @@ nodist_qt_test_test_bitcoin_qt_SOURCES = $(TEST_QT_MOC_CPP)
qt_test_test_bitcoin_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER)
if ENABLE_WALLET
-qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET)
+qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_UTIL) $(LIBBITCOIN_WALLET)
endif
if ENABLE_ZMQ
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
diff --git a/src/interface/node.cpp b/src/interface/node.cpp
index 43bdfbaebc..5f4f0f2fa7 100644
--- a/src/interface/node.cpp
+++ b/src/interface/node.cpp
@@ -7,6 +7,7 @@
#include <chainparams.h>
#include <init.h>
#include <interface/handler.h>
+#include <interface/wallet.h>
#include <net.h>
#include <netaddress.h>
#include <netbase.h>
@@ -15,8 +16,19 @@
#include <util.h>
#include <warnings.h>
+#if defined(HAVE_CONFIG_H)
+#include <config/bitcoin-config.h>
+#endif
+#ifdef ENABLE_WALLET
+#define CHECK_WALLET(x) x
+#else
+#define CHECK_WALLET(x) throw std::logic_error("Wallet function called in non-wallet build.")
+#endif
+
#include <boost/thread/thread.hpp>
+class CWallet;
+
namespace interface {
namespace {
@@ -69,6 +81,15 @@ class NodeImpl : public Node
{
return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn));
}
+ std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
+ {
+ return MakeHandler(::uiInterface.ShowProgress.connect(fn));
+ }
+ std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
+ {
+ CHECK_WALLET(
+ return MakeHandler(::uiInterface.LoadWallet.connect([fn](CWallet* wallet) { fn(MakeWallet(*wallet)); })));
+ }
};
} // namespace
diff --git a/src/interface/node.h b/src/interface/node.h
index 60ef9cce1b..d1749871bf 100644
--- a/src/interface/node.h
+++ b/src/interface/node.h
@@ -17,6 +17,7 @@ class proxyType;
namespace interface {
class Handler;
+class Wallet;
//! Top-level interface for a bitcoin node (bitcoind process).
class Node
@@ -87,6 +88,14 @@ public:
const std::string& caption,
unsigned int style)>;
virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
+
+ //! Register handler for progress messages.
+ using ShowProgressFn = std::function<void(const std::string& title, int progress, bool resume_possible)>;
+ virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
+
+ //! Register handler for load wallet messages.
+ using LoadWalletFn = std::function<void(std::unique_ptr<Wallet> wallet)>;
+ virtual std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) = 0;
};
//! Return implementation of Node interface.
diff --git a/src/interface/wallet.cpp b/src/interface/wallet.cpp
new file mode 100644
index 0000000000..01639aa37f
--- /dev/null
+++ b/src/interface/wallet.cpp
@@ -0,0 +1,32 @@
+// Copyright (c) 2018 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <interface/wallet.h>
+
+#include <interface/handler.h>
+#include <wallet/wallet.h>
+
+#include <memory>
+
+namespace interface {
+namespace {
+
+class WalletImpl : public Wallet
+{
+public:
+ WalletImpl(CWallet& wallet) : m_wallet(wallet) {}
+
+ std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
+ {
+ return MakeHandler(m_wallet.ShowProgress.connect(fn));
+ }
+
+ CWallet& m_wallet;
+};
+
+} // namespace
+
+std::unique_ptr<Wallet> MakeWallet(CWallet& wallet) { return MakeUnique<WalletImpl>(wallet); }
+
+} // namespace interface
diff --git a/src/interface/wallet.h b/src/interface/wallet.h
new file mode 100644
index 0000000000..bf68df4e7d
--- /dev/null
+++ b/src/interface/wallet.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2018 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_INTERFACE_WALLET_H
+#define BITCOIN_INTERFACE_WALLET_H
+
+#include <functional>
+#include <memory>
+#include <string>
+
+class CWallet;
+
+namespace interface {
+
+class Handler;
+
+//! Interface for accessing a wallet.
+class Wallet
+{
+public:
+ virtual ~Wallet() {}
+
+ //! Register handler for show progress messages.
+ using ShowProgressFn = std::function<void(const std::string& title, int progress)>;
+ virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
+};
+
+//! Return implementation of Wallet interface. This function will be undefined
+//! in builds where ENABLE_WALLET is false.
+std::unique_ptr<Wallet> MakeWallet(CWallet& wallet);
+
+} // namespace interface
+
+#endif // BITCOIN_INTERFACE_WALLET_H
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 8ccdaff651..07fac934fb 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -375,7 +375,7 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
{
- SplashScreen *splash = new SplashScreen(0, networkStyle);
+ SplashScreen *splash = new SplashScreen(m_node, 0, networkStyle);
// We don't hold a direct pointer to the splash screen after creation, but the splash
// screen will take care of deleting itself when slotFinish happens.
splash->show();
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index 66e9dd0465..2475a82ef9 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -12,22 +12,21 @@
#include <clientversion.h>
#include <init.h>
+#include <interface/handler.h>
+#include <interface/node.h>
+#include <interface/wallet.h>
#include <util.h>
#include <ui_interface.h>
#include <version.h>
-#ifdef ENABLE_WALLET
-#include <wallet/wallet.h>
-#endif
-
#include <QApplication>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QPainter>
#include <QRadialGradient>
-SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) :
- QWidget(0, f), curAlignment(0)
+SplashScreen::SplashScreen(interface::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) :
+ QWidget(0, f), curAlignment(0), m_node(node)
{
// set reference point, paddings
int paddingRight = 50;
@@ -143,7 +142,7 @@ bool SplashScreen::eventFilter(QObject * obj, QEvent * ev) {
if (ev->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
if(keyEvent->text()[0] == 'q') {
- StartShutdown();
+ m_node.startShutdown();
}
}
return QObject::eventFilter(obj, ev);
@@ -177,35 +176,34 @@ static void ShowProgress(SplashScreen *splash, const std::string &title, int nPr
: _("press q to shutdown")) +
strprintf("\n%d", nProgress) + "%");
}
-
#ifdef ENABLE_WALLET
-void SplashScreen::ConnectWallet(CWallet* wallet)
+void SplashScreen::ConnectWallet(std::unique_ptr<interface::Wallet> wallet)
{
- wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2, false));
- connectedWallets.push_back(wallet);
+ m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(boost::bind(ShowProgress, this, _1, _2, false)));
+ m_connected_wallets.emplace_back(std::move(wallet));
}
#endif
void SplashScreen::subscribeToCoreSignals()
{
// Connect signals to client
- uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
- uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2, _3));
+ m_handler_init_message = m_node.handleInitMessage(boost::bind(InitMessage, this, _1));
+ m_handler_show_progress = m_node.handleShowProgress(boost::bind(ShowProgress, this, _1, _2, _3));
#ifdef ENABLE_WALLET
- uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this, _1));
+ m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interface::Wallet> wallet) { ConnectWallet(std::move(wallet)); });
#endif
}
void SplashScreen::unsubscribeFromCoreSignals()
{
// Disconnect signals from client
- uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
- uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2, _3));
-#ifdef ENABLE_WALLET
- for (CWallet* const & pwallet : connectedWallets) {
- pwallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2, false));
+ m_handler_init_message->disconnect();
+ m_handler_show_progress->disconnect();
+ for (auto& handler : m_connected_wallet_handlers) {
+ handler->disconnect();
}
-#endif
+ m_connected_wallet_handlers.clear();
+ m_connected_wallets.clear();
}
void SplashScreen::showMessage(const QString &message, int alignment, const QColor &color)
@@ -227,6 +225,6 @@ void SplashScreen::paintEvent(QPaintEvent *event)
void SplashScreen::closeEvent(QCloseEvent *event)
{
- StartShutdown(); // allows an "emergency" shutdown during startup
+ m_node.startShutdown(); // allows an "emergency" shutdown during startup
event->ignore();
}
diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h
index e1568e406b..419f36f641 100644
--- a/src/qt/splashscreen.h
+++ b/src/qt/splashscreen.h
@@ -8,9 +8,16 @@
#include <functional>
#include <QSplashScreen>
-class CWallet;
+#include <memory>
+
class NetworkStyle;
+namespace interface {
+class Handler;
+class Node;
+class Wallet;
+};
+
/** Class for the splashscreen with information of the running client.
*
* @note this is intentionally not a QSplashScreen. Bitcoin Core initialization
@@ -22,7 +29,7 @@ class SplashScreen : public QWidget
Q_OBJECT
public:
- explicit SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle);
+ explicit SplashScreen(interface::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle);
~SplashScreen();
protected:
@@ -45,14 +52,19 @@ private:
/** Disconnect core signals to splash screen */
void unsubscribeFromCoreSignals();
/** Connect wallet signals to splash screen */
- void ConnectWallet(CWallet*);
+ void ConnectWallet(std::unique_ptr<interface::Wallet> wallet);
QPixmap pixmap;
QString curMessage;
QColor curColor;
int curAlignment;
- QList<CWallet*> connectedWallets;
+ interface::Node& m_node;
+ std::unique_ptr<interface::Handler> m_handler_init_message;
+ std::unique_ptr<interface::Handler> m_handler_show_progress;
+ std::unique_ptr<interface::Handler> m_handler_load_wallet;
+ std::list<std::unique_ptr<interface::Wallet>> m_connected_wallets;
+ std::list<std::unique_ptr<interface::Handler>> m_connected_wallet_handlers;
};
#endif // BITCOIN_QT_SPLASHSCREEN_H