From a0704a8996bb950ae3c4d5b5a30e9dfe34cde1d3 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Mon, 17 Apr 2017 18:56:44 -0400 Subject: [PATCH] Remove most direct bitcoin calls from qt/walletmodel.cpp --- src/interface/node.cpp | 18 +- src/interface/node.h | 10 + src/interface/wallet.cpp | 212 ++++++++++++++++++++ src/interface/wallet.h | 206 ++++++++++++++++++- src/qt/bitcoin.cpp | 6 +- src/qt/bitcoingui.cpp | 4 +- src/qt/coincontroldialog.cpp | 12 +- src/qt/overviewpage.cpp | 8 +- src/qt/receivecoinsdialog.cpp | 6 +- src/qt/sendcoinsdialog.cpp | 16 +- src/qt/signverifymessagedialog.cpp | 2 +- src/qt/test/wallettests.cpp | 6 +- src/qt/transactionview.cpp | 10 +- src/qt/walletmodel.cpp | 306 +++++++---------------------- src/qt/walletmodel.h | 59 ++---- src/qt/walletmodeltransaction.cpp | 20 +- src/qt/walletmodeltransaction.h | 15 +- src/qt/walletview.cpp | 2 +- 18 files changed, 588 insertions(+), 330 deletions(-) diff --git a/src/interface/node.cpp b/src/interface/node.cpp index 2f0114f5e4..db03cc0627 100644 --- a/src/interface/node.cpp +++ b/src/interface/node.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include #endif #ifdef ENABLE_WALLET +#include #define CHECK_WALLET(x) x #else #define CHECK_WALLET(x) throw std::logic_error("Wallet function called in non-wallet build.") @@ -37,8 +39,6 @@ #include #include -class CWallet; - namespace interface { namespace { @@ -185,6 +185,8 @@ class NodeImpl : public Node } } bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); } + unsigned int getTxConfirmTarget() override { CHECK_WALLET(return ::nTxConfirmTarget); } + CAmount getMaxTxFee() override { return ::maxTxFee; } UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override { JSONRPCRequest req; @@ -196,6 +198,18 @@ class NodeImpl : public Node std::vector listRpcCommands() override { return ::tableRPC.listCommands(); } void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) override { RPCSetTimerInterfaceIfUnset(iface); } void rpcUnsetTimerInterface(RPCTimerInterface* iface) override { RPCUnsetTimerInterface(iface); } + std::vector> getWallets() override + { +#ifdef ENABLE_WALLET + std::vector> wallets; + for (CWalletRef wallet : ::vpwallets) { + wallets.emplace_back(MakeWallet(*wallet)); + } + return wallets; +#else + throw std::logic_error("Node::getWallets() called in non-wallet build."); +#endif + } std::unique_ptr handleInitMessage(InitMessageFn fn) override { return MakeHandler(::uiInterface.InitMessage.connect(fn)); diff --git a/src/interface/node.h b/src/interface/node.h index aeac1d6215..b0d435695e 100644 --- a/src/interface/node.h +++ b/src/interface/node.h @@ -6,6 +6,7 @@ #define BITCOIN_INTERFACE_NODE_H #include // For banmap_t +#include // For CAmount #include // For HelpMessageMode #include // For CConnman::NumConnections #include // For Network @@ -141,6 +142,12 @@ public: //! Get network active. virtual bool getNetworkActive() = 0; + //! Get tx confirm target. + virtual unsigned int getTxConfirmTarget() = 0; + + //! Get max tx fee. + virtual CAmount getMaxTxFee() = 0; + //! Execute rpc command. virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0; @@ -153,6 +160,9 @@ public: //! Unset RPC timer interface. virtual void rpcUnsetTimerInterface(RPCTimerInterface* iface) = 0; + //! Return interfaces for accessing wallets (if any). + virtual std::vector> getWallets() = 0; + //! Register handler for init messages. using InitMessageFn = std::function; virtual std::unique_ptr handleInitMessage(InitMessageFn fn) = 0; diff --git a/src/interface/wallet.cpp b/src/interface/wallet.cpp index 01639aa37f..8dae7ac547 100644 --- a/src/interface/wallet.cpp +++ b/src/interface/wallet.cpp @@ -4,7 +4,21 @@ #include +#include +#include +#include #include +#include +#include +#include +#include