From a75f7cb40cb6a9b39d09ba6a71596d796dfbe7b7 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Sat, 26 Oct 2019 14:15:19 -0700 Subject: [PATCH] Remove unnecessary settings --- lib/Cargo.lock | 4 +- src/connection.cpp | 10 +-- src/controller.cpp | 5 -- src/main.cpp | 9 --- src/mainwindow.cpp | 83 ++------------------ src/settings.cpp | 87 +++------------------ src/settings.h | 18 +---- src/settings.ui | 188 +++++++++------------------------------------ 8 files changed, 62 insertions(+), 342 deletions(-) diff --git a/lib/Cargo.lock b/lib/Cargo.lock index 4326aef..2082d37 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -1051,7 +1051,7 @@ version = "0.1.0" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "zecwalletlitelib 0.1.0", + "zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=865a72442db4ee1862fa776514da4a4a1c935b94)", ] [[package]] @@ -2266,6 +2266,7 @@ dependencies = [ [[package]] name = "zecwalletlitelib" version = "0.1.0" +source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=865a72442db4ee1862fa776514da4a4a1c935b94#865a72442db4ee1862fa776514da4a4a1c935b94" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "bellman 0.1.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)", @@ -2561,3 +2562,4 @@ dependencies = [ "checksum zcash_client_backend 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "" "checksum zcash_primitives 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "" "checksum zcash_proofs 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "" +"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=865a72442db4ee1862fa776514da4a4a1c935b94)" = "" diff --git a/src/connection.cpp b/src/connection.cpp index de65e18..f1217d1 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -43,10 +43,10 @@ void ConnectionLoader::doAutoConnect() { auto config = std::shared_ptr(new ConnectionConfig()); config->dangerous = true; - config->server = QString("https://127.0.0.1:9067"); + config->server = Settings::getInstance()->getSettings().server; // Initialize the library - main->logger->write(QObject::tr("Attempting to initialize")); + main->logger->write(QObject::tr("Attempting to initialize library with ") + config->server); // Check to see if there's an existing wallet if (litelib_wallet_exists(Settings::getChainName().toStdString().c_str())) { @@ -172,15 +172,11 @@ void Executor::run() { QString reply = litelib_process_response(resp); - qDebug() << "Reply=" << reply; + qDebug() << "RPC Reply=" << reply; auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false); if (parsed.is_discarded() || parsed.is_null()) { emit handleError(reply); } else { - const bool isGuiThread = - QThread::currentThread() == QCoreApplication::instance()->thread(); - qDebug() << "executing RPC: isGUI=" << isGuiThread; - emit responseReady(parsed); } } diff --git a/src/controller.cpp b/src/controller.cpp index 0f8bc7c..5835edf 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -66,11 +66,6 @@ void Controller::setConnection(Connection* c) { ui->statusBar->showMessage("Ready!"); - // See if we need to remove the reindex/rescan flags from the zcash.conf file - auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation(); - Settings::removeFromZcashConf(zcashConfLocation, "rescan"); - Settings::removeFromZcashConf(zcashConfLocation, "reindex"); - // If we're allowed to get the Zec Price, get the prices if (Settings::getInstance()->getAllowFetchPrices()) refreshZECPrice(); diff --git a/src/main.cpp b/src/main.cpp index abe34d2..f4f6a0f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -150,11 +150,6 @@ public: parser.setApplicationDescription("Shielded desktop light wallet for Zcash"); parser.addHelpOption(); - // Add an option to specify the conf file - QCommandLineOption confOption(QStringList() << "conf", "Use the zcash.conf specified instead of looking for the default one.", - "confFile"); - parser.addOption(confOption); - // Positional argument will specify a zcash payment URI parser.addPositionalArgument("zcashURI", "An optional zcash URI to pay"); @@ -208,10 +203,6 @@ public: Settings::getInstance()->setUseEmbedded(false); - // Check to see if a conf location was specified - if (parser.isSet(confOption)) { - Settings::getInstance()->setUsingZcashConf(parser.value(confOption)); - } w = new MainWindow(); w->setWindowTitle("Zecwallet Lightclient v" + QString(APP_VERSION)); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f18c3ab..30c1424 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -272,41 +272,10 @@ void MainWindow::setupSettingsModal() { // Fetch prices settings.chkFetchPrices->setChecked(Settings::getInstance()->getAllowFetchPrices()); - - // Use Tor - bool isUsingTor = false; - if (rpc->getConnection() != nullptr) { - isUsingTor = !rpc->getConnection()->config->proxy.isEmpty(); - } - settings.chkTor->setChecked(isUsingTor); - // Connection Settings - QIntValidator validator(0, 65535); - settings.port->setValidator(&validator); - - // If values are coming from zcash.conf, then disable all the fields - auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation(); - if (!zcashConfLocation.isEmpty()) { - settings.confMsg->setText("Settings are being read from \n" + zcashConfLocation); - settings.hostname->setEnabled(false); - settings.port->setEnabled(false); - settings.rpcuser->setEnabled(false); - settings.rpcpassword->setEnabled(false); - } - else { - settings.confMsg->setText("No local zcash.conf found. Please configure connection manually."); - settings.hostname->setEnabled(true); - settings.port->setEnabled(true); - settings.rpcuser->setEnabled(true); - settings.rpcpassword->setEnabled(true); - } - // Load current values into the dialog auto conf = Settings::getInstance()->getSettings(); - settings.hostname->setText(conf.host); - settings.port->setText(conf.port); - settings.rpcuser->setText(conf.rpcuser); - settings.rpcpassword->setText(conf.rpcpassword); + settings.txtServer->setText(conf.server); // Connection tab by default settings.tabWidget->setCurrentIndex(0); @@ -315,9 +284,6 @@ void MainWindow::setupSettingsModal() { if (!rpc->isEmbedded()) { settings.chkRescan->setEnabled(false); settings.chkRescan->setToolTip(tr("You're using an external zcashd. Please restart zcashd with -rescan")); - - settings.chkReindex->setEnabled(false); - settings.chkReindex->setToolTip(tr("You're using an external zcashd. Please restart zcashd with -reindex")); } if (settingsDialog.exec() == QDialog::Accepted) { @@ -327,56 +293,17 @@ void MainWindow::setupSettingsModal() { // Allow fetching prices Settings::getInstance()->setAllowFetchPrices(settings.chkFetchPrices->isChecked()); - if (!isUsingTor && settings.chkTor->isChecked()) { - // If "use tor" was previously unchecked and now checked - Settings::addToZcashConf(zcashConfLocation, "proxy=127.0.0.1:9050"); - rpc->getConnection()->config->proxy = "proxy=127.0.0.1:9050"; - - QMessageBox::information(this, tr("Enable Tor"), - tr("Connection over Tor has been enabled. To use this feature, you need to restart ZecWallet."), - QMessageBox::Ok); - } - - if (isUsingTor && !settings.chkTor->isChecked()) { - // If "use tor" was previously checked and now is unchecked - Settings::removeFromZcashConf(zcashConfLocation, "proxy"); - rpc->getConnection()->config->proxy.clear(); - - QMessageBox::information(this, tr("Disable Tor"), - tr("Connection over Tor has been disabled. To fully disconnect from Tor, you need to restart ZecWallet."), - QMessageBox::Ok); - } + // Save the server + Settings::getInstance()->saveSettings(settings.txtServer->text().trimmed()); - if (zcashConfLocation.isEmpty()) { + if (false /* connection needs reloading?*/) { // Save settings - Settings::getInstance()->saveSettings( - settings.hostname->text(), - settings.port->text(), - settings.rpcuser->text(), - settings.rpcpassword->text()); + Settings::getInstance()->saveSettings(settings.txtServer->text()); auto cl = new ConnectionLoader(this, rpc); cl->loadConnection(); } - // Check to see if rescan or reindex have been enabled - bool showRestartInfo = false; - if (settings.chkRescan->isChecked()) { - Settings::addToZcashConf(zcashConfLocation, "rescan=1"); - showRestartInfo = true; - } - - if (settings.chkReindex->isChecked()) { - Settings::addToZcashConf(zcashConfLocation, "reindex=1"); - showRestartInfo = true; - } - - if (showRestartInfo) { - auto desc = tr("ZecWallet needs to restart to rescan/reindex. ZecWallet will now close, please restart ZecWallet to continue"); - - QMessageBox::information(this, tr("Restart ZecWallet"), desc, QMessageBox::Ok); - QTimer::singleShot(1, [=]() { this->close(); }); - } } }); } diff --git a/src/settings.cpp b/src/settings.cpp index a698c11..edc7b93 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -18,33 +18,24 @@ Config Settings::getSettings() { // Load from the QT Settings. QSettings s; - auto host = s.value("connection/host").toString(); - auto port = s.value("connection/port").toString(); - auto username = s.value("connection/rpcuser").toString(); - auto password = s.value("connection/rpcpassword").toString(); + auto server = s.value("connection/server").toString(); + if (server.trimmed().isEmpty()) { + server = Settings::getDefaultServer(); + } - return Config{host, port, username, password}; + return Config{server}; } -void Settings::saveSettings(const QString& host, const QString& port, const QString& username, const QString& password) { +void Settings::saveSettings(const QString& server) { QSettings s; - s.setValue("connection/host", host); - s.setValue("connection/port", port); - s.setValue("connection/rpcuser", username); - s.setValue("connection/rpcpassword", password); - + s.setValue("connection/server", server); s.sync(); // re-init to load correct settings init(); } -void Settings::setUsingZcashConf(QString confLocation) { - if (!confLocation.isEmpty()) - _confLocation = confLocation; -} - bool Settings::isTestnet() { return _isTestnet; } @@ -161,6 +152,10 @@ void Settings::saveRestoreTableHeader(QTableView* table, QDialog* d, QString tab }); } +QString Settings::getDefaultServer() { + return "https://lightd-main.zecwallet.co:443/"; +} + void Settings::openAddressInExplorer(QString address) { QString url; if (Settings::getInstance()->isTestnet()) { @@ -257,70 +252,10 @@ QString Settings::getDonationAddr() { } -bool Settings::addToZcashConf(QString confLocation, QString line) { - QFile file(confLocation); - if (!file.open(QIODevice::ReadWrite | QIODevice::Append)) - return false; - - - QTextStream out(&file); - out << line << "\n"; - file.close(); - - return true; -} - -bool Settings::removeFromZcashConf(QString confLocation, QString option) { - if (confLocation.isEmpty()) - return false; - - // To remove an option, we'll create a new file, and copy over everything but the option. - QFile file(confLocation); - if (!file.open(QIODevice::ReadOnly)) - return false; - - QList lines; - QTextStream in(&file); - while (!in.atEnd()) { - QString line = in.readLine(); - auto s = line.indexOf("="); - QString name = line.left(s).trimmed().toLower(); - if (name != option) { - lines.append(line); - } - } - file.close(); - - QFile newfile(confLocation); - if (!newfile.open(QIODevice::ReadWrite | QIODevice::Truncate)) - return false; - - QTextStream out(&newfile); - for (QString line : lines) { - out << line << endl; - } - newfile.close(); - - return true; -} - double Settings::getMinerFee() { return 10000; } -double Settings::getZboardAmount() { - return 0.0001; -} - -QString Settings::getZboardAddr() { - if (Settings::getInstance()->isTestnet()) { - return getDonationAddr(); - } - else { - return "zs10m00rvkhfm4f7n23e4sxsx275r7ptnggx39ygl0vy46j9mdll5c97gl6dxgpk0njuptg2mn9w5s"; - } -} - bool Settings::isValidSaplingPrivateKey(QString pk) { if (isTestnet()) { QRegExp zspkey("^secret-extended-key-test[0-9a-z]{278}$", Qt::CaseInsensitive); diff --git a/src/settings.h b/src/settings.h index 4363978..a3d1d8c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -4,10 +4,7 @@ #include "precompiled.h" struct Config { - QString host; - QString port; - QString rpcuser; - QString rpcpassword; + QString server; }; struct ToFields; @@ -29,7 +26,7 @@ public: static Settings* getInstance(); Config getSettings(); - void saveSettings(const QString& host, const QString& port, const QString& username, const QString& password); + void saveSettings(const QString& server); bool isTestnet(); void setTestnet(bool isTestnet); @@ -65,9 +62,6 @@ public: bool isSaplingActive(); - void setUsingZcashConf(QString confLocation); - const QString& getZcashdConfLocation() { return _confLocation; } - void setZECPrice(double p) { zecPrice = p; } double getZECPrice(); @@ -98,9 +92,8 @@ public: static QString getTokenName(); static QString getDonationAddr(); + static QString getDefaultServer(); static double getMinerFee(); - static double getZboardAmount(); - static QString getZboardAddr(); static int getMaxMobileAppTxns() { return 30; } @@ -108,9 +101,6 @@ public: static bool isValidAddress(QString addr); - static bool addToZcashConf(QString confLocation, QString line); - static bool removeFromZcashConf(QString confLocation, QString option); - static QString getChainName() { return QString("test"); } static const QString labelRegExp; @@ -126,7 +116,6 @@ private: static Settings* instance; - QString _confLocation; QString _executable; bool _isTestnet = false; bool _isSyncing = false; @@ -134,7 +123,6 @@ private: int _zcashdVersion = 0; bool _useEmbedded = false; bool _headless = false; - int _peerConnections = 0; double zecPrice = 0.0; }; diff --git a/src/settings.ui b/src/settings.ui index afdf1eb..b18879e 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -26,11 +26,11 @@ - 1 + 0 - zcashd connection + Connection @@ -43,13 +43,6 @@ - - - - Qt::Horizontal - - - @@ -59,69 +52,17 @@ - Host + Server - + - - - - - 60 - 0 - - - - Port - - - - - - - - - - - - - - - 60 - 0 - - - - RPC Username - - - - - - - - - - - 60 - 0 - - - - RPC Password - - - - - - @@ -145,7 +86,7 @@ Options - + @@ -175,41 +116,28 @@ - - + + - Connect to github on startup to check for updates + Fetch ZEC / USD prices - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + - Fetch ZEC / USD prices + Check github for updates at startup - - + + - Connect via Tor + Connect to github on startup to check for updates - + @@ -225,14 +153,20 @@ - - - - Check github for updates at startup + + + + Qt::Vertical - + + + 20 + 40 + + + - + @@ -245,23 +179,13 @@ - + Connect to the internet to fetch ZEC prices - - - - Connect to the Tor network via SOCKS proxy running on 127.0.0.1:9050. Please note that you'll have to install and run the Tor service externally. - - - true - - - @@ -270,37 +194,6 @@ - - - Reindex - - - - - - - Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This may take several hours. You need to restart ZecWallet for this to take effect - - - true - - - - - - - Rescan - - - - - - - Qt::Horizontal - - - - Qt::Vertical @@ -314,33 +207,26 @@ - - - + + + Qt::Horizontal - - + + - Rebuild the entire blockchain from the genesis block, by rescanning all the block files. This may take several hours to days, depending on your hardware. You need to restart ZecWallet for this to take effect + Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This may take several hours. You need to restart ZecWallet for this to take effect true - - - - Qt::Horizontal - - - - - + + - + Rescan