Remove direct bitcoin calls from qt/optionsmodel.cpp
This commit is contained in:
parent
71e0d90876
commit
c0f2756be5
7 changed files with 57 additions and 27 deletions
|
@ -7,6 +7,9 @@
|
|||
#include <chainparams.h>
|
||||
#include <init.h>
|
||||
#include <interface/handler.h>
|
||||
#include <net.h>
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
#include <scheduler.h>
|
||||
#include <ui_interface.h>
|
||||
#include <util.h>
|
||||
|
@ -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<Handler> handleInitMessage(InitMessageFn fn) override
|
||||
{
|
||||
return MakeHandler(::uiInterface.InitMessage.connect(fn));
|
||||
|
|
|
@ -5,10 +5,14 @@
|
|||
#ifndef BITCOIN_INTERFACE_NODE_H
|
||||
#define BITCOIN_INTERFACE_NODE_H
|
||||
|
||||
#include <netaddress.h> // For Network
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class proxyType;
|
||||
|
||||
namespace interface {
|
||||
|
||||
class Handler;
|
||||
|
@ -22,6 +26,12 @@ public:
|
|||
//! 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 @@ public:
|
|||
//! 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<void(const std::string& message)>;
|
||||
virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
|
||||
|
|
|
@ -362,7 +362,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)
|
||||
|
|
|
@ -11,26 +11,21 @@
|
|||
#include <qt/bitcoinunits.h>
|
||||
#include <qt/guiutil.h>
|
||||
|
||||
#include <init.h>
|
||||
#include <interface/node.h>
|
||||
#include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
|
||||
#include <net.h>
|
||||
#include <netbase.h>
|
||||
#include <txdb.h> // for -dbcache defaults
|
||||
#include <qt/intro.h>
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
#include <wallet/wallet.h>
|
||||
#include <wallet/walletdb.h>
|
||||
#endif
|
||||
|
||||
#include <QNetworkProxy>
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
||||
const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
|
||||
|
||||
OptionsModel::OptionsModel(QObject *parent, bool resetSettings) :
|
||||
QAbstractListModel(parent)
|
||||
OptionsModel::OptionsModel(interface::Node& node, QObject *parent, bool resetSettings) :
|
||||
QAbstractListModel(parent), m_node(node)
|
||||
{
|
||||
Init(resetSettings);
|
||||
}
|
||||
|
@ -93,12 +88,12 @@ void OptionsModel::Init(bool resetSettings)
|
|||
// 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");
|
||||
|
||||
if (!settings.contains("strDataDir"))
|
||||
|
@ -108,19 +103,19 @@ void OptionsModel::Init(bool resetSettings)
|
|||
#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");
|
||||
#endif
|
||||
|
||||
// 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"))
|
||||
|
@ -128,7 +123,7 @@ void OptionsModel::Init(bool resetSettings)
|
|||
if (!settings.contains("addrProxy"))
|
||||
settings.setValue("addrProxy", QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST, DEFAULT_GUI_PROXY_PORT));
|
||||
// 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");
|
||||
|
@ -138,7 +133,7 @@ void OptionsModel::Init(bool resetSettings)
|
|||
if (!settings.contains("addrSeparateProxyTor"))
|
||||
settings.setValue("addrSeparateProxyTor", QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST, DEFAULT_GUI_PROXY_PORT));
|
||||
// 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");
|
||||
|
@ -146,7 +141,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();
|
||||
|
@ -315,12 +310,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();
|
||||
|
@ -453,7 +443,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());
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
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
|
||||
|
@ -76,6 +80,7 @@ public:
|
|||
bool isRestartRequired() const;
|
||||
|
||||
private:
|
||||
interface::Node& m_node;
|
||||
/* Qt-only settings */
|
||||
bool fHideTrayIcon;
|
||||
bool fMinimizeToTray;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <amount.h>
|
||||
#include <chainparams.h>
|
||||
#include <interface/node.h>
|
||||
#include <random.h>
|
||||
#include <script/script.h>
|
||||
#include <script/standard.h>
|
||||
|
@ -66,7 +67,8 @@ static SendCoinsRecipient handleRequest(PaymentServer* server, std::vector<unsig
|
|||
void PaymentServerTests::paymentServerTests()
|
||||
{
|
||||
SelectParams(CBaseChainParams::MAIN);
|
||||
OptionsModel optionsModel;
|
||||
auto node = interface::MakeNode();
|
||||
OptionsModel optionsModel(*node);
|
||||
PaymentServer* server = new PaymentServer(nullptr, false);
|
||||
X509_STORE* caStore = X509_STORE_new();
|
||||
X509_STORE_add_cert(caStore, parse_b64der_cert(caCert1_BASE64));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <qt/test/wallettests.h>
|
||||
|
||||
#include <interface/node.h>
|
||||
#include <qt/bitcoinamountfield.h>
|
||||
#include <qt/callback.h>
|
||||
#include <qt/optionsmodel.h>
|
||||
|
@ -175,7 +176,8 @@ void TestGUI()
|
|||
std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
|
||||
SendCoinsDialog sendCoinsDialog(platformStyle.get());
|
||||
TransactionView transactionView(platformStyle.get());
|
||||
OptionsModel optionsModel;
|
||||
auto node = interface::MakeNode();
|
||||
OptionsModel optionsModel(*node);
|
||||
WalletModel walletModel(platformStyle.get(), &wallet, &optionsModel);
|
||||
sendCoinsDialog.setModel(&walletModel);
|
||||
transactionView.setModel(&walletModel);
|
||||
|
|
Loading…
Reference in a new issue