From 1671916e731b674b3df123a6f7b10b03c780e492 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 19 Mar 2019 16:02:47 -0700 Subject: [PATCH] #119 , #107 Add "troubleshooting" options to do rescan/reindex from UI --- src/connection.cpp | 17 +++++++++-- src/mainwindow.cpp | 24 ++++++++++++++++ src/rpc.cpp | 7 +++++ src/rpc.h | 1 + src/settings.cpp | 4 ++- src/settings.ui | 70 +++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 118 insertions(+), 5 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index fc900b0..b987e02 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -463,7 +463,7 @@ void ConnectionLoader::refreshZcashdState(Connection* connection, std::function< } else if (err == QNetworkReply::NetworkError::InternalServerError && !res.is_discarded()) { // The server is loading, so just poll until it succeeds - QString status = QString::fromStdString(res["error"]["message"]); + QString status = QString::fromStdString(res["error"]["message"]); { static int dots = 0; status = status.left(status.length() - 3) + QString(".").repeated(dots); @@ -480,11 +480,22 @@ void ConnectionLoader::refreshZcashdState(Connection* connection, std::function< ); } +// Update the UI with the status void ConnectionLoader::showInformation(QString info, QString detail) { + static int rescanCount = 0; + if (detail.toLower().startsWith("rescan")) { + rescanCount++; + } + + if (rescanCount > 10) { + detail = detail + "\n" + QObject::tr("This may take several hours"); + } + connD->status->setText(info); connD->statusDetail->setText(detail); - - main->logger->write(info + ":" + detail); + + if (rescanCount < 10) + main->logger->write(info + ":" + detail); } /** diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c3abfc7..6ef6251 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -526,6 +526,7 @@ void MainWindow::setupSettingsModal() { 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"); @@ -547,6 +548,29 @@ void MainWindow::setupSettingsModal() { 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"); + + if (!rpc->isEmbedded()) { + desc = desc + "\n\n" + tr("You also need to restart your zcashd."); + } + + QMessageBox::information(this, tr("Restart ZecWallet"), desc, QMessageBox::Ok); + QTimer::singleShot(1, [=]() { this->close(); }); + } } }); } diff --git a/src/rpc.cpp b/src/rpc.cpp index a37c065..7bd7253 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -79,6 +79,7 @@ void RPC::setEZcashd(QProcess* p) { } } +// Called when a connection to zcashd is available. void RPC::setConnection(Connection* c) { if (c == nullptr) return; @@ -87,6 +88,12 @@ void RPC::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"); + + // Refresh the UI refreshZECPrice(); checkForUpdate(); diff --git a/src/rpc.h b/src/rpc.h index ec41e70..7cc6610 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -78,6 +78,7 @@ public: void shutdownZcashd(); void noConnection(); + bool isEmbedded() { return ezcashd != nullptr; } QString getDefaultSaplingAddress(); QString getDefaultTAddress(); diff --git a/src/settings.cpp b/src/settings.cpp index 5e9e057..b8ae3a3 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -221,6 +221,9 @@ bool Settings::addToZcashConf(QString confLocation, QString line) { } 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)) @@ -233,7 +236,6 @@ bool Settings::removeFromZcashConf(QString confLocation, QString option) { auto s = line.indexOf("="); QString name = line.left(s).trimmed().toLower(); if (name != option) { - qDebug() << "Copied " << line; lines.append(line); } } diff --git a/src/settings.ui b/src/settings.ui index 47e3961..597ce1a 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -26,7 +26,7 @@ - 1 + 2 @@ -269,6 +269,74 @@ + + + Troubleshooting + + + + + + Reindex + + + + + + + Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This will take several hours. You need to restart ZecWallet for this to take effect + + + true + + + + + + + Rescan + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 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 + + + true + + + + + + + Qt::Horizontal + + + + +