Skip to content

Commit

Permalink
Rescan Blockchain Menuitem (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
denverbdr committed Aug 23, 2019
1 parent cb8fbc9 commit ea663d5
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 49 deletions.
39 changes: 35 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ui_mobileappconnector.h"
#include "ui_addressbook.h"
#include "ui_nullifiermigration.h"
#include "ui_rescandialog.h"
#include "ui_zboard.h"
#include "ui_privkey.h"
#include "ui_about.h"
Expand Down Expand Up @@ -79,6 +80,9 @@ MainWindow::MainWindow(QWidget *parent) :
// Nullifier Migration
QObject::connect(ui->actionNullifier_Migration, &QAction::triggered, this, &MainWindow::nullifierMigration);

// Rescan Blockchain
QObject::connect(ui->actionRescanBlockchain, &QAction::triggered, this, &MainWindow::rescanBlockchain);

// Connect mobile app
QObject::connect(ui->actionConnect_Mobile_App, &QAction::triggered, this, [=] () {
if (rpc->getConnection() == nullptr)
Expand Down Expand Up @@ -584,10 +588,6 @@ void MainWindow::setupSettingsModal() {

// 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");
Expand Down Expand Up @@ -634,6 +634,37 @@ void MainWindow::donate() {
ui->tabWidget->setCurrentIndex(1);
}


/**
* Rescan the blockchain
*/
void MainWindow::rescanBlockchain() {
if (!getRPC() || !getRPC()->getConnection())
return;

QDialog d(this);
Ui_rescanDialog r;
r.setupUi(&d);
Settings::saveRestore(&d);

// Set the default start height to 0
r.txtStartHeight->setText("0");
r.txtStartHeight->setValidator(new QIntValidator(0, 10000000, &d));

if (d.exec() == QDialog::Accepted) {
int startHeight = r.txtStartHeight->text().toInt();

// Call the RPC. We ignore the return callback, since we'll monitor the progress via the rescaninfo RPC
getRPC()->rescanBlockchain(startHeight, [=](auto) {});

// Trigger monitoring the rescan with a slight delay, allowing the previous RPC to complete
QTimer::singleShot(1000, [=]() {
this->getRPC()->refreshRescanStatus();
});
}
}


/** Migrate sapling nullifiers */
void MainWindow::nullifierMigration() {
// Make sure everything is up and running
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MainWindow : public QMainWindow

void validateAddress();
void nullifierMigration();
void rescanBlockchain();

void updateLabels();
void updateTAddrCombo(bool checked);
Expand Down
11 changes: 11 additions & 0 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@
<addaction name="actionExport_All_Private_Keys"/>
<addaction name="actionBackup_wallet_dat"/>
<addaction name="separator"/>
<addaction name="actionRescanBlockchain"/>
<addaction name="actionExport_transactions"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
Expand Down Expand Up @@ -1201,6 +1202,16 @@
<string>Nullifier Migration</string>
</property>
</action>
<action name="actionRescan_Blockchain">
<property name="text">
<string>Rescan Blockchain</string>
</property>
</action>
<action name="actionRescanBlockchain">
<property name="text">
<string>Rescan Blockchain</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
101 changes: 101 additions & 0 deletions src/rescandialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>rescanDialog</class>
<widget class="QDialog" name="rescanDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Rescan Blockchain</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>You can optionally specify a start height to start re-scanning the blockchain at</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtStartHeight"/>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Rescanning the blockchain examines the transactions in each block and re-imports transactions belonging to you into your wallet. Rescanning can fix issues like missing balances or corrupted wallets. Note that rescanning can take a long time, upto several hours.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Start Height</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>rescanDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>rescanDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
11 changes: 11 additions & 0 deletions src/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ void RPC::getTransactions(const std::function<void(json)>& cb) {
conn->doRPCWithDefaultErrorHandling(payload, cb);
}

void RPC::rescanBlockchain(int startHeight, const std::function<void(json)>& cb) {
json payload = {
{"jsonrpc", "1.0"},
{"id", "someid"},
{"method", "rescanblockchain"},
{"params", {startHeight}}
};

conn->doRPCWithDefaultErrorHandling(payload, cb);
}

void RPC::sendZTransaction(json params, const std::function<void(json)>& cb,
const std::function<void(QString)>& err) {
json payload = {
Expand Down
2 changes: 2 additions & 0 deletions src/rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class RPC
void importTPrivKey(QString addr, bool rescan, int rescanHeight, const std::function<void(json)>& cb);
void validateAddress(QString address, const std::function<void(json)>& cb);

void rescanBlockchain(int startHeight, const std::function<void(json)>& cb);

void shutdownZcashd();
void noConnection();
bool isEmbedded() { return ezcashd != nullptr; }
Expand Down
59 changes: 14 additions & 45 deletions src/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -288,38 +288,38 @@
<string>Troubleshooting</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="5" column="0">
<item row="2" 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">
<item row="3" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This may take several hours. You need to restart YecWallet for this to take effect</string>
<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 YecWallet 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>
<item row="5" column="0">
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="0">
<item row="6" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -332,37 +332,6 @@
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" 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 YecWallet for this to take effect</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down
1 change: 1 addition & 0 deletions yecwallet.pro
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ HEADERS += \
FORMS += \
src/mainwindow.ui \
src/nullifiermigration.ui \
src/rescandialog.ui \
src/settings.ui \
src/about.ui \
src/confirm.ui \
Expand Down

0 comments on commit ea663d5

Please sign in to comment.