Browse Source

#119 , #107

Add "troubleshooting" options to do rescan/reindex from UI
pull/45/head
Aditya Kulkarni 5 years ago
parent
commit
1671916e73
  1. 17
      src/connection.cpp
  2. 24
      src/mainwindow.cpp
  3. 7
      src/rpc.cpp
  4. 1
      src/rpc.h
  5. 4
      src/settings.cpp
  6. 70
      src/settings.ui

17
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);
}
/**

24
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(); });
}
}
});
}

7
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();

1
src/rpc.h

@ -78,6 +78,7 @@ public:
void shutdownZcashd();
void noConnection();
bool isEmbedded() { return ezcashd != nullptr; }
QString getDefaultSaplingAddress();
QString getDefaultTAddress();

4
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);
}
}

70
src/settings.ui

@ -26,7 +26,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -269,6 +269,74 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Troubleshooting</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<widget class="QCheckBox" name="chkReindex">
<property name="text">
<string>Reindex</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>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</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="chkRescan">
<property name="text">
<string>Rescan</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>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</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>

Loading…
Cancel
Save