aboutsummaryrefslogtreecommitdiff
path: root/src/interface
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 /src/interface
parentc2f672fb1960399389dea9cdd8f76d7156c2c88b (diff)
Remove direct bitcoin calls from qt/splashscreen.cpp
Diffstat (limited to 'src/interface')
-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
4 files changed, 97 insertions, 0 deletions
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