From 98473af332a6679615e1cfa09ce91562fe68530d Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Mon, 27 Mar 2017 16:55:24 -0400 Subject: [PATCH 01/36] Add src/interface/README.md --- src/interface/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/interface/README.md diff --git a/src/interface/README.md b/src/interface/README.md new file mode 100644 index 000000000000..e93b91d23cea --- /dev/null +++ b/src/interface/README.md @@ -0,0 +1,17 @@ +# Internal c++ interfaces + +The following interfaces are defined here: + +* [`Chain`](chain.h) — used by wallet to access blockchain and mempool state. Added in [#10973](https://github.com/bitcoin/bitcoin/pull/10973). + +* [`Chain::Client`](chain.h) — used by node to start & stop `Chain` clients. Added in [#10973](https://github.com/bitcoin/bitcoin/pull/10973). + +* [`Node`](node.h) — used by GUI to start & stop bitcoin node. Added in [#10244](https://github.com/bitcoin/bitcoin/pull/10244). + +* [`Wallet`](wallet.h) — used by GUI to access wallets. Added in [#10244](https://github.com/bitcoin/bitcoin/pull/10244). + +* [`Handler`](handler.h) — returned by `handleEvent` methods on interfaces above and used to manage lifetimes of event handlers. + +* [`Init`](init.h) — used by multiprocess code to access interfaces above on startup. Added in [#10102](https://github.com/bitcoin/bitcoin/pull/10102). + +The interfaces above define boundaries between major components of bitcoin code (node, wallet, and gui), making it possible for them to run in different processes, and be tested, developed, and understood independently. These interfaces are not currently designed to be stable or to be used externally. From e709f5a45e8edc620880dc55dfe559429e2e75bb Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Mon, 17 Apr 2017 13:55:43 -0400 Subject: [PATCH 02/36] Remove direct bitcoin calls from qt/bitcoin.cpp --- src/Makefile.am | 4 +++ src/interface/handler.cpp | 33 ++++++++++++++++++ src/interface/handler.h | 35 +++++++++++++++++++ src/interface/node.cpp | 53 ++++++++++++++++++++++++++++ src/interface/node.h | 62 +++++++++++++++++++++++++++++++++ src/qt/dash.cpp | 73 +++++++++++++++------------------------ 6 files changed, 214 insertions(+), 46 deletions(-) create mode 100644 src/interface/handler.cpp create mode 100644 src/interface/handler.h create mode 100644 src/interface/node.cpp create mode 100644 src/interface/node.h diff --git a/src/Makefile.am b/src/Makefile.am index 5997d0ffa7c5..4c4416de5de0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -169,6 +169,8 @@ BITCOIN_CORE_H = \ httpserver.h \ indirectmap.h \ init.h \ + interface/handler.h \ + interface/node.h \ key.h \ keepass.h \ keystore.h \ @@ -548,6 +550,8 @@ libdash_util_a_SOURCES = \ compat/glibcxx_sanity.cpp \ compat/strnlen.cpp \ fs.cpp \ + interface/handler.cpp \ + interface/node.cpp \ logging.cpp \ random.cpp \ rpc/protocol.cpp \ diff --git a/src/interface/handler.cpp b/src/interface/handler.cpp new file mode 100644 index 000000000000..4b27f374f44d --- /dev/null +++ b/src/interface/handler.cpp @@ -0,0 +1,33 @@ +// 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 + +#include + +#include +#include +#include + +namespace interface { +namespace { + +class HandlerImpl : public Handler +{ +public: + HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {} + + void disconnect() override { m_connection.disconnect(); } + + boost::signals2::scoped_connection m_connection; +}; + +} // namespace + +std::unique_ptr MakeHandler(boost::signals2::connection connection) +{ + return MakeUnique(std::move(connection)); +} + +} // namespace interface diff --git a/src/interface/handler.h b/src/interface/handler.h new file mode 100644 index 000000000000..a76334bfbf0f --- /dev/null +++ b/src/interface/handler.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_HANDLER_H +#define BITCOIN_INTERFACE_HANDLER_H + +#include + +namespace boost { +namespace signals2 { +class connection; +} // namespace signals2 +} // namespace boost + +namespace interface { + +//! Generic interface for managing an event handler or callback function +//! registered with another interface. Has a single disconnect method to cancel +//! the registration and prevent any future notifications. +class Handler +{ +public: + virtual ~Handler() {} + + //! Disconnect the handler. + virtual void disconnect() = 0; +}; + +//! Return handler wrapping a boost signal connection. +std::unique_ptr MakeHandler(boost::signals2::connection connection); + +} // namespace interface + +#endif // BITCOIN_INTERFACE_HANDLER_H diff --git a/src/interface/node.cpp b/src/interface/node.cpp new file mode 100644 index 000000000000..4e3fa6ceb944 --- /dev/null +++ b/src/interface/node.cpp @@ -0,0 +1,53 @@ +// 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 + +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace interface { +namespace { + +class NodeImpl : public Node +{ + void parseParameters(int argc, const char* const argv[]) override + { + gArgs.ParseParameters(argc, argv); + } + void readConfigFile(const std::string& conf_path) override { gArgs.ReadConfigFile(conf_path); } + void selectParams(const std::string& network) override { SelectParams(network); } + void initLogging() override { InitLogging(); } + void initParameterInteraction() override { InitParameterInteraction(); } + std::string getWarnings(const std::string& type) override { return GetWarnings(type); } + bool baseInitialize() override + { + return AppInitBasicSetup() && AppInitParameterInteraction() && AppInitSanityChecks() && + AppInitLockDataDirectory(); + } + bool appInitMain() override { return AppInitMain(); } + void appShutdown() override + { + Interrupt(); + Shutdown(); + } + void startShutdown() override { StartShutdown(); } + std::unique_ptr handleInitMessage(InitMessageFn fn) override + { + return MakeHandler(::uiInterface.InitMessage.connect(fn)); + } +}; + +} // namespace + +std::unique_ptr MakeNode() { return MakeUnique(); } + +} // namespace interface diff --git a/src/interface/node.h b/src/interface/node.h new file mode 100644 index 000000000000..b69ef160a39f --- /dev/null +++ b/src/interface/node.h @@ -0,0 +1,62 @@ +// 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_NODE_H +#define BITCOIN_INTERFACE_NODE_H + +#include +#include +#include + +namespace interface { + +class Handler; + +//! Top-level interface for a bitcoin node (bitcoind process). +class Node +{ +public: + virtual ~Node() {} + + //! Set command line arguments. + virtual void parseParameters(int argc, const char* const argv[]) = 0; + + //! Load settings from configuration file. + virtual void readConfigFile(const std::string& conf_path) = 0; + + //! Choose network parameters. + virtual void selectParams(const std::string& network) = 0; + + //! Init logging. + virtual void initLogging() = 0; + + //! Init parameter interaction. + virtual void initParameterInteraction() = 0; + + //! Get warnings. + virtual std::string getWarnings(const std::string& type) = 0; + + //! Initialize app dependencies. + virtual bool baseInitialize() = 0; + + //! Start node. + virtual bool appInitMain() = 0; + + //! Stop node. + virtual void appShutdown() = 0; + + //! Start shutdown. + virtual void startShutdown() = 0; + + //! Register handler for init messages. + using InitMessageFn = std::function; + virtual std::unique_ptr handleInitMessage(InitMessageFn fn) = 0; +}; + +//! Return implementation of Node interface. +std::unique_ptr MakeNode(); + +} // namespace interface + +#endif // BITCOIN_INTERFACE_NODE_H diff --git a/src/qt/dash.cpp b/src/qt/dash.cpp index c80d34ee79c7..b7f61b918652 100644 --- a/src/qt/dash.cpp +++ b/src/qt/dash.cpp @@ -28,6 +28,8 @@ #endif #include +#include +#include #include #include #include @@ -156,11 +158,7 @@ class BitcoinCore: public QObject { Q_OBJECT public: - explicit BitcoinCore(); - /** Basic initialization, before starting initialization/shutdown thread. - * Return true on success. - */ - static bool baseInitialize(); + explicit BitcoinCore(interface::Node& node); public Q_SLOTS: void initialize(); @@ -173,9 +171,10 @@ public Q_SLOTS: void runawayException(const QString &message); private: - /// Pass fatal exception message to UI thread void handleRunawayException(const std::exception_ptr e); + + interface::Node& m_node; }; /** Main Dash application object */ @@ -183,7 +182,7 @@ class BitcoinApplication: public QApplication { Q_OBJECT public: - explicit BitcoinApplication(int &argc, char **argv); + explicit BitcoinApplication(interface::Node& node, int &argc, char **argv); ~BitcoinApplication(); #ifdef ENABLE_WALLET @@ -225,6 +224,7 @@ public Q_SLOTS: private: QThread *coreThread; + interface::Node& m_node; OptionsModel *optionsModel; ClientModel *clientModel; BitcoinGUI *window; @@ -241,36 +241,15 @@ public Q_SLOTS: #include -BitcoinCore::BitcoinCore(): - QObject() +BitcoinCore::BitcoinCore(interface::Node& node) : + QObject(), m_node(node) { } void BitcoinCore::handleRunawayException(const std::exception_ptr e) { PrintExceptionContinue(e, "Runaway exception"); - Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui"))); -} - -bool BitcoinCore::baseInitialize() -{ - if (!AppInitBasicSetup()) - { - return false; - } - if (!AppInitParameterInteraction()) - { - return false; - } - if (!AppInitSanityChecks()) - { - return false; - } - if (!AppInitLockDataDirectory()) - { - return false; - } - return true; + Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings("gui"))); } void BitcoinCore::initialize() @@ -278,7 +257,7 @@ void BitcoinCore::initialize() try { qDebug() << __func__ << ": Running initialization in thread"; - bool rv = AppInitMain(); + bool rv = m_node.appInitMain(); Q_EMIT initializeResult(rv); } catch (...) { handleRunawayException(std::current_exception()); @@ -314,8 +293,7 @@ void BitcoinCore::shutdown() try { qDebug() << __func__ << ": Running Shutdown in thread"; - Interrupt(); - Shutdown(); + m_node.appShutdown(); qDebug() << __func__ << ": Shutdown finished"; Q_EMIT shutdownResult(); } catch (...) { @@ -323,9 +301,10 @@ void BitcoinCore::shutdown() } } -BitcoinApplication::BitcoinApplication(int &argc, char **argv): +BitcoinApplication::BitcoinApplication(interface::Node& node, int &argc, char **argv): QApplication(argc, argv), coreThread(0), + m_node(node), optionsModel(0), clientModel(0), window(0), @@ -402,7 +381,7 @@ void BitcoinApplication::startThread() if(coreThread) return; coreThread = new QThread(this); - BitcoinCore *executor = new BitcoinCore(); + BitcoinCore *executor = new BitcoinCore(m_node); executor->moveToThread(coreThread); /* communication to and from thread */ @@ -421,8 +400,8 @@ void BitcoinApplication::startThread() void BitcoinApplication::parameterSetup() { - InitLogging(); - InitParameterInteraction(); + m_node.initLogging(); + m_node.initParameterInteraction(); } void BitcoinApplication::requestInitialize() @@ -455,7 +434,7 @@ void BitcoinApplication::requestShutdown() delete clientModel; clientModel = 0; - StartShutdown(); + m_node.startShutdown(); // Request shutdown from core thread Q_EMIT requestedShutdown(); @@ -555,9 +534,11 @@ int main(int argc, char *argv[]) SetupEnvironment(); + std::unique_ptr node = interface::MakeNode(); + /// 1. Parse command-line options. These take precedence over anything else. // Command-line options take precedence: - gArgs.ParseParameters(argc, argv); + node->parseParameters(argc, argv); // Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory @@ -574,7 +555,7 @@ int main(int argc, char *argv[]) QApplication::setAttribute(Qt::AA_DontShowIconsInMenus); #endif - BitcoinApplication app(argc, argv); + BitcoinApplication app(*node, argc, argv); // Register meta types used for QMetaObject::invokeMethod qRegisterMetaType< bool* >(); @@ -627,7 +608,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } try { - gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)); + node->readConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)); } catch (const std::exception& e) { QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what())); @@ -642,7 +623,7 @@ int main(int argc, char *argv[]) // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) try { - SelectParams(gArgs.GetChainName()); + node->selectParams(gArgs.GetChainName()); } catch(std::exception &e) { QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what())); return EXIT_FAILURE; @@ -779,7 +760,7 @@ int main(int argc, char *argv[]) } // Subscribe to global signals from core - uiInterface.InitMessage.connect(InitMessage); + std::unique_ptr handler = node->handleInitMessage(InitMessage); if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false)) app.createSplashScreen(networkStyle.data()); @@ -791,7 +772,7 @@ int main(int argc, char *argv[]) // Perform base initialization before spinning up initialization/shutdown thread // This is acceptable because this function only contains steps that are quick to execute, // so the GUI thread won't be held up. - if (BitcoinCore::baseInitialize()) { + if (node->baseInitialize()) { app.requestInitialize(); #if defined(Q_OS_WIN) WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely...").arg(QObject::tr(PACKAGE_NAME)), (HWND)app.getMainWinId()); @@ -806,7 +787,7 @@ int main(int argc, char *argv[]) } } catch (...) { PrintExceptionContinue(std::current_exception(), "Runaway exception"); - app.handleRunawayException(QString::fromStdString(GetWarnings("gui"))); + app.handleRunawayException(QString::fromStdString(node->getWarnings("gui"))); } return rv; } From f45e09556669072d7ec51c49030c50f724695850 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Mon, 17 Apr 2017 14:23:14 -0400 Subject: [PATCH 03/36] Remove direct bitcoin calls from qt/optionsmodel.cpp --- src/interface/node.cpp | 15 ++++++++++ src/interface/node.h | 16 ++++++++++ src/qt/addressbookpage.cpp | 2 -- src/qt/dash.cpp | 2 +- src/qt/optionsmodel.cpp | 48 +++++++++++++----------------- src/qt/optionsmodel.h | 7 ++++- src/qt/qrdialog.cpp | 20 ++----------- src/qt/qrdialog.h | 4 --- src/qt/test/paymentservertests.cpp | 4 ++- src/qt/test/wallettests.cpp | 4 ++- src/qt/transactionview.cpp | 2 -- 11 files changed, 66 insertions(+), 58 deletions(-) diff --git a/src/interface/node.cpp b/src/interface/node.cpp index 4e3fa6ceb944..877c5f57a8f0 100644 --- a/src/interface/node.cpp +++ b/src/interface/node.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -24,6 +27,8 @@ class NodeImpl : public Node gArgs.ParseParameters(argc, argv); } void readConfigFile(const std::string& conf_path) override { gArgs.ReadConfigFile(conf_path); } + bool softSetArg(const std::string& arg, const std::string& value) override { return gArgs.SoftSetArg(arg, value); } + bool softSetBoolArg(const std::string& arg, bool value) override { return gArgs.SoftSetBoolArg(arg, value); } void selectParams(const std::string& network) override { SelectParams(network); } void initLogging() override { InitLogging(); } void initParameterInteraction() override { InitParameterInteraction(); } @@ -40,6 +45,16 @@ class NodeImpl : public Node Shutdown(); } void startShutdown() override { StartShutdown(); } + void mapPort(bool use_upnp) override + { + if (use_upnp) { + StartMapPort(); + } else { + InterruptMapPort(); + StopMapPort(); + } + } + bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); } 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 b69ef160a39f..368bade28b74 100644 --- a/src/interface/node.h +++ b/src/interface/node.h @@ -5,10 +5,14 @@ #ifndef BITCOIN_INTERFACE_NODE_H #define BITCOIN_INTERFACE_NODE_H +#include // For Network + #include #include #include +class proxyType; + namespace interface { class Handler; @@ -22,6 +26,12 @@ class Node //! Set command line arguments. virtual void parseParameters(int argc, const char* const argv[]) = 0; + //! Set a command line argument if it doesn't already have a value + virtual bool softSetArg(const std::string& arg, const std::string& value) = 0; + + //! Set a command line boolean argument if it doesn't already have a value + virtual bool softSetBoolArg(const std::string& arg, bool value) = 0; + //! Load settings from configuration file. virtual void readConfigFile(const std::string& conf_path) = 0; @@ -49,6 +59,12 @@ class Node //! Start shutdown. virtual void startShutdown() = 0; + //! Map port. + virtual void mapPort(bool use_upnp) = 0; + + //! Get proxy. + virtual bool getProxy(Network net, proxyType& proxy_info) = 0; + //! Register handler for init messages. using InitMessageFn = std::function; virtual std::unique_ptr handleInitMessage(InitMessageFn fn) = 0; diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index b5764ed263e9..f96de330337d 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -241,9 +241,7 @@ void AddressBookPage::on_showAddressQRCode_clicked() QString strAddress = entries.at(0).data(Qt::EditRole).toString(); QRDialog* dialog = new QRDialog(this); - OptionsModel *model = new OptionsModel(nullptr, false); - dialog->setModel(model); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setInfo(tr("QR code"), "dash:"+strAddress, "", strAddress); dialog->show(); diff --git a/src/qt/dash.cpp b/src/qt/dash.cpp index b7f61b918652..1fc259a0ee10 100644 --- a/src/qt/dash.cpp +++ b/src/qt/dash.cpp @@ -353,7 +353,7 @@ void BitcoinApplication::createPaymentServer() void BitcoinApplication::createOptionsModel(bool resetSettings) { - optionsModel = new OptionsModel(nullptr, resetSettings); + optionsModel = new OptionsModel(m_node, nullptr, resetSettings); } void BitcoinApplication::createWindow(const NetworkStyle *networkStyle) diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index b28a64053592..e1954e9b594b 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -12,16 +12,13 @@ #include #include -#include +#include #include // For DEFAULT_SCRIPTCHECK_THREADS #include #include #include // for -dbcache defaults #ifdef ENABLE_WALLET -#include -#include - #include #endif @@ -33,8 +30,8 @@ const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1"; static const QString GetDefaultProxyAddress(); -OptionsModel::OptionsModel(QObject *parent, bool resetSettings) : - QAbstractListModel(parent) +OptionsModel::OptionsModel(interface::Node& node, QObject *parent, bool resetSettings) : + QAbstractListModel(parent), m_node(node) { Init(resetSettings); } @@ -91,17 +88,17 @@ void OptionsModel::Init(bool resetSettings) if (!settings.contains("fontScale")) settings.setValue("fontScale", GUIUtil::getFontScaleDefault()); - if (!gArgs.SoftSetArg("-font-scale", settings.value("fontScale").toString().toStdString())) + if (!m_node.softSetArg("-font-scale", settings.value("fontScale").toString().toStdString())) addOverriddenOption("-font-scale"); if (!settings.contains("fontWeightNormal")) settings.setValue("fontWeightNormal", GUIUtil::weightToArg(GUIUtil::getFontWeightNormalDefault())); - if (!gArgs.SoftSetArg("-font-weight-normal", settings.value("fontWeightNormal").toString().toStdString())) + if (!m_node.softSetArg("-font-weight-normal", settings.value("fontWeightNormal").toString().toStdString())) addOverriddenOption("-font-weight-normal"); if (!settings.contains("fontWeightBold")) settings.setValue("fontWeightBold", GUIUtil::weightToArg(GUIUtil::getFontWeightBoldDefault())); - if (!gArgs.SoftSetArg("-font-weight-bold", settings.value("fontWeightBold").toString().toStdString())) + if (!m_node.softSetArg("-font-weight-bold", settings.value("fontWeightBold").toString().toStdString())) addOverriddenOption("-font-weight-bold"); #ifdef ENABLE_WALLET @@ -136,31 +133,31 @@ void OptionsModel::Init(bool resetSettings) // // If setting doesn't exist create it with defaults. // - // If gArgs.SoftSetArg() or gArgs.SoftSetBoolArg() return false we were overridden + // If m_node.softSetArg() or m_node.softSetBoolArg() return false we were overridden // by command-line and show this in the UI. // Main if (!settings.contains("nDatabaseCache")) settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache); - if (!gArgs.SoftSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString())) + if (!m_node.softSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString())) addOverriddenOption("-dbcache"); if (!settings.contains("nThreadsScriptVerif")) settings.setValue("nThreadsScriptVerif", DEFAULT_SCRIPTCHECK_THREADS); - if (!gArgs.SoftSetArg("-par", settings.value("nThreadsScriptVerif").toString().toStdString())) + if (!m_node.softSetArg("-par", settings.value("nThreadsScriptVerif").toString().toStdString())) addOverriddenOption("-par"); // Wallet #ifdef ENABLE_WALLET if (!settings.contains("bSpendZeroConfChange")) settings.setValue("bSpendZeroConfChange", true); - if (!gArgs.SoftSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool())) + if (!m_node.softSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool())) addOverriddenOption("-spendzeroconfchange"); // PrivateSend if (!settings.contains("nPrivateSendRounds")) settings.setValue("nPrivateSendRounds", DEFAULT_PRIVATESEND_ROUNDS); - if (!gArgs.SoftSetArg("-privatesendrounds", settings.value("nPrivateSendRounds").toString().toStdString())) + if (!m_node.softSetArg("-privatesendrounds", settings.value("nPrivateSendRounds").toString().toStdString())) addOverriddenOption("-privatesendrounds"); CPrivateSendClientOptions::SetRounds(settings.value("nPrivateSendRounds").toInt()); @@ -171,13 +168,13 @@ void OptionsModel::Init(bool resetSettings) else settings.setValue("nPrivateSendAmount", settings.value("nAnonymizeDashAmount").toInt()); } - if (!gArgs.SoftSetArg("-privatesendamount", settings.value("nPrivateSendAmount").toString().toStdString())) + if (!m_node.softSetArg("-privatesendamount", settings.value("nPrivateSendAmount").toString().toStdString())) addOverriddenOption("-privatesendamount"); CPrivateSendClientOptions::SetAmount(settings.value("nPrivateSendAmount").toInt()); if (!settings.contains("fPrivateSendMultiSession")) settings.setValue("fPrivateSendMultiSession", DEFAULT_PRIVATESEND_MULTISESSION); - if (!gArgs.SoftSetBoolArg("-privatesendmultisession", settings.value("fPrivateSendMultiSession").toBool())) + if (!m_node.softSetBoolArg("-privatesendmultisession", settings.value("fPrivateSendMultiSession").toBool())) addOverriddenOption("-privatesendmultisession"); CPrivateSendClientOptions::SetMultiSessionEnabled(settings.value("fPrivateSendMultiSession").toBool()); #endif @@ -185,12 +182,12 @@ void OptionsModel::Init(bool resetSettings) // Network if (!settings.contains("fUseUPnP")) settings.setValue("fUseUPnP", DEFAULT_UPNP); - if (!gArgs.SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool())) + if (!m_node.softSetBoolArg("-upnp", settings.value("fUseUPnP").toBool())) addOverriddenOption("-upnp"); if (!settings.contains("fListen")) settings.setValue("fListen", DEFAULT_LISTEN); - if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool())) + if (!m_node.softSetBoolArg("-listen", settings.value("fListen").toBool())) addOverriddenOption("-listen"); if (!settings.contains("fUseProxy")) @@ -198,7 +195,7 @@ void OptionsModel::Init(bool resetSettings) if (!settings.contains("addrProxy")) settings.setValue("addrProxy", GetDefaultProxyAddress()); // Only try to set -proxy, if user has enabled fUseProxy - if (settings.value("fUseProxy").toBool() && !gArgs.SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString())) + if (settings.value("fUseProxy").toBool() && !m_node.softSetArg("-proxy", settings.value("addrProxy").toString().toStdString())) addOverriddenOption("-proxy"); else if(!settings.value("fUseProxy").toBool() && !gArgs.GetArg("-proxy", "").empty()) addOverriddenOption("-proxy"); @@ -208,7 +205,7 @@ void OptionsModel::Init(bool resetSettings) if (!settings.contains("addrSeparateProxyTor")) settings.setValue("addrSeparateProxyTor", GetDefaultProxyAddress()); // Only try to set -onion, if user has enabled fUseSeparateProxyTor - if (settings.value("fUseSeparateProxyTor").toBool() && !gArgs.SoftSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString())) + if (settings.value("fUseSeparateProxyTor").toBool() && !m_node.softSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString())) addOverriddenOption("-onion"); else if(!settings.value("fUseSeparateProxyTor").toBool() && !gArgs.GetArg("-onion", "").empty()) addOverriddenOption("-onion"); @@ -216,7 +213,7 @@ void OptionsModel::Init(bool resetSettings) // Display if (!settings.contains("language")) settings.setValue("language", ""); - if (!gArgs.SoftSetArg("-lang", settings.value("language").toString().toStdString())) + if (!m_node.softSetArg("-lang", settings.value("language").toString().toStdString())) addOverriddenOption("-lang"); language = settings.value("language").toString(); @@ -418,12 +415,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in break; case MapPortUPnP: // core option - can be changed on-the-fly settings.setValue("fUseUPnP", value.toBool()); - if (value.toBool()) { - StartMapPort(); - } else { - InterruptMapPort(); - StopMapPort(); - } + m_node.mapPort(value.toBool()); break; case MinimizeOnClose: fMinimizeOnClose = value.toBool(); @@ -642,7 +634,7 @@ bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const // Directly query current base proxy, because // GUI settings can be overridden with -proxy. proxyType curProxy; - if (GetProxy(NET_IPV4, curProxy)) { + if (m_node.getProxy(NET_IPV4, curProxy)) { proxy.setType(QNetworkProxy::Socks5Proxy); proxy.setHostName(QString::fromStdString(curProxy.proxy.ToStringIP())); proxy.setPort(curProxy.proxy.GetPort()); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 27bd7fc32cae..30629611af87 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -9,6 +9,10 @@ #include +namespace interface { +class Node; +} + QT_BEGIN_NAMESPACE class QNetworkProxy; QT_END_NAMESPACE @@ -27,7 +31,7 @@ class OptionsModel : public QAbstractListModel Q_OBJECT public: - explicit OptionsModel(QObject *parent = 0, bool resetSettings = false); + explicit OptionsModel(interface::Node& node, QObject *parent = 0, bool resetSettings = false); enum OptionID { StartAtStartup, // bool @@ -93,6 +97,7 @@ class OptionsModel : public QAbstractListModel bool resetSettingsOnShutdown{false}; private: + interface::Node& m_node; /* Qt-only settings */ bool fHideTrayIcon; bool fMinimizeToTray; diff --git a/src/qt/qrdialog.cpp b/src/qt/qrdialog.cpp index badfc9ed7944..ab913db7820a 100644 --- a/src/qt/qrdialog.cpp +++ b/src/qt/qrdialog.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -91,8 +90,7 @@ void QRGeneralImageWidget::contextMenuEvent(QContextMenuEvent *event) QRDialog::QRDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::QRDialog), - model(0) + ui(new Ui::QRDialog) { ui->setupUi(this); @@ -113,17 +111,6 @@ QRDialog::~QRDialog() delete ui; } -void QRDialog::setModel(OptionsModel *model) -{ - this->model = model; - - if (model) - connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(update())); - - // update the display unit if necessary - update(); -} - void QRDialog::setInfo(QString strWindowtitle, QString strQRCode, QString strTextInfo, QString strQRCodeTitle) { this->strWindowtitle = strWindowtitle; @@ -135,9 +122,6 @@ void QRDialog::setInfo(QString strWindowtitle, QString strQRCode, QString strTex void QRDialog::update() { - if(!model) - return; - setWindowTitle(strWindowtitle); ui->button_saveImage->setEnabled(false); if (strTextInfo.isEmpty()) { @@ -183,4 +167,4 @@ void QRDialog::update() ui->button_saveImage->setEnabled(true); } #endif -} \ No newline at end of file +} diff --git a/src/qt/qrdialog.h b/src/qt/qrdialog.h index 7174f2a5517a..46d9cbcb1a36 100644 --- a/src/qt/qrdialog.h +++ b/src/qt/qrdialog.h @@ -11,8 +11,6 @@ #include #include -class OptionsModel; - namespace Ui { class QRDialog; } @@ -52,7 +50,6 @@ class QRDialog : public QDialog explicit QRDialog(QWidget *parent = 0); ~QRDialog(); - void setModel(OptionsModel *model); void setInfo(QString strWindowtitle, QString strQRCode, QString strTextInfo, QString strQRCodeTitle); private Q_SLOTS: @@ -60,7 +57,6 @@ private Q_SLOTS: private: Ui::QRDialog *ui; - OptionsModel *model; QString strWindowtitle; QString strQRCode; QString strTextInfo; diff --git a/src/qt/test/paymentservertests.cpp b/src/qt/test/paymentservertests.cpp index 1864604372a4..286c368fed42 100644 --- a/src/qt/test/paymentservertests.cpp +++ b/src/qt/test/paymentservertests.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include