From f9b98b733fdd0df19b02fc9c79584a08e4a3f5bf Mon Sep 17 00:00:00 2001 From: fekt Date: Sun, 9 Oct 2022 10:19:20 -0400 Subject: [PATCH] WIP: Rescan changes --- src/mainwindow.cpp | 55 +++++++++++++++++++++++++-- src/mainwindow.h | 2 + src/mainwindow.ui | 13 +++---- src/rescandialog.ui | 91 +++++++++++++++++++++++++++++++++++++++++++++ src/rpc.cpp | 12 +++++- src/rpc.h | 4 +- src/settings.ui | 55 +++++++++++++++++---------- 7 files changed, 200 insertions(+), 32 deletions(-) create mode 100644 src/rescandialog.ui diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 77351dd..5585125 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -13,6 +13,7 @@ #include "ui_settings.h" #include "ui_viewalladdresses.h" #include "ui_validateaddress.h" +#include "ui_rescandialog.h" #include "rpc.h" #include "balancestablemodel.h" #include "settings.h" @@ -409,6 +410,11 @@ void MainWindow::setupSettingsModal() { } }); + // Setup rescan button + QObject::connect(settings.rescanButton, &QPushButton::clicked, [=] () { + this->rescanButtonClicked(1); + }); + int theme_index = settings.comboBoxTheme->findText(Settings::getInstance()->get_theme_name(), Qt::MatchExactly); settings.comboBoxTheme->setCurrentIndex(theme_index); @@ -623,8 +629,8 @@ void MainWindow::setupSettingsModal() { // Enable the troubleshooting options only if using embedded hushd if (!rpc->isEmbedded()) { - settings.chkRescan->setEnabled(false); - settings.chkRescan->setToolTip(tr("You're using an external hushd. Please restart hushd with -rescan")); + //settings.chkRescan->setEnabled(false); + //settings.chkRescan->setToolTip(tr("You're using an external hushd. Please restart hushd with -rescan")); settings.chkReindex->setEnabled(false); settings.chkReindex->setToolTip(tr("You're using an external hushd. Please restart hushd with -reindex")); @@ -690,10 +696,12 @@ void MainWindow::setupSettingsModal() { // Check to see if rescan or reindex have been enabled bool showRestartInfo = false; bool showReindexInfo = false; + + /* if (settings.chkRescan->isChecked()) { Settings::addToHushConf(hushConfLocation, "rescan=1"); showRestartInfo = true; - } + }*/ if (settings.chkReindex->isChecked()) { Settings::addToHushConf(hushConfLocation, "reindex=1"); @@ -2030,6 +2038,47 @@ void MainWindow::slot_change_theme(QString& theme_name) } +void MainWindow::rescanButtonClicked(int number) { + + qDebug() << "rescanButtonClicked" << number; + + // Setup rescan dialog + Ui_RescanDialog rescanDialog; + QDialog dialog(this); + rescanDialog.setupUi(&dialog); + + // TODO: Maybe set to current blockheight by default + rescanDialog.rescanBlockheight->setFocus(); + + // Add validator for block height + QRegExpValidator* heightValidator = new QRegExpValidator(QRegExp("\\d*"), this); + rescanDialog.rescanBlockheight->setValidator(heightValidator); + + // Check if OK clicked + if (dialog.exec() == QDialog::Accepted) { + + // Show message in status bar + ui->statusBar->showMessage(tr("Rescanning"), 3 * 1000); + + // Close settings + QWidget *modalWidget = QApplication::activeModalWidget(); + if (modalWidget) + modalWidget->close(); + + // Get submitted rescan height + int rescanHeight = rescanDialog.rescanBlockheight->text().toInt(); + qDebug() << "rescan height = " << rescanHeight; + + // Call rescan RPC + rpc->rescan(rescanHeight, [=] (QJsonValue response){ + qDebug() << "rescanning " << response; + }); + + /* TODO: Display progress somewhere by reading debug.log with QFileSystemWatcher + * or something similar / or use an available RPC and update rescan progress somewhere */ + } +} + MainWindow::~MainWindow() { delete ui; diff --git a/src/mainwindow.h b/src/mainwindow.h index 135233f..78442e7 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -127,6 +127,8 @@ private: void memoButtonClicked(int number, bool includeReplyTo = false); void fileUploadButtonClicked(int number); void setMemoEnabled(int number, bool enabled); + + void rescanButtonClicked(int number); void donate(); void website(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 8385ec7..f3b73ac 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -970,8 +970,7 @@ false - background-color: #fff; -image: url(:/img/res/logobig.gif); + @@ -1740,6 +1739,11 @@ image: url(:/img/res/logobig.gif); + + FilledIconLabel + QLabel +
fillediconlabel.h
+
AddressCombo QComboBox @@ -1750,11 +1754,6 @@ image: url(:/img/res/logobig.gif); QLabel
qrcodelabel.h
- - FilledIconLabel - QLabel -
fillediconlabel.h
-
inputsCombo diff --git a/src/rescandialog.ui b/src/rescandialog.ui new file mode 100644 index 0000000..65e1ea1 --- /dev/null +++ b/src/rescandialog.ui @@ -0,0 +1,91 @@ + + + RescanDialog + + + + 0 + 0 + 542 + 108 + + + + Rescan + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + Enter block height to rescan from: + + + + + + + + + buttonBox + accepted() + RescanDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RescanDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/rpc.cpp b/src/rpc.cpp index 3f9e33e..b75c29c 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -135,6 +135,16 @@ QJsonValue RPC::makePayload(QString method, QString param) { return payload; } +QJsonValue RPC::makePayload(QString method, int param) { + QJsonObject payload = { + {"jsonrpc", "1.0"}, + {"id", "42" }, + {"method", method }, + {"params", QJsonArray{param}} + }; + return payload; +} + QJsonValue RPC::makePayload(QString method) { QJsonObject payload = { {"jsonrpc", "1.0"}, @@ -154,7 +164,7 @@ void RPC::getTAddresses(const std::function& cb) { // full or partial rescan void RPC::rescan(qint64 height, const std::function& cb) { QString method = "rescan"; - conn->doRPCWithDefaultErrorHandling(makePayload(method, QString::number(height)), cb); + conn->doRPCWithDefaultErrorHandling(makePayload(method, height), cb); } // add/remove a banned node. ip can include an optional netmask diff --git a/src/rpc.h b/src/rpc.h index 8e78824..1349b36 100755 --- a/src/rpc.h +++ b/src/rpc.h @@ -117,6 +117,8 @@ public: Connection* getConnection() { return conn; } + void rescan(qint64 height, const std::function& cb); + private: void refreshBalances(); @@ -132,6 +134,7 @@ private: void getBalance(const std::function& cb); QJsonValue makePayload(QString method, QString param, QString param2); QJsonValue makePayload(QString method, QString param); + QJsonValue makePayload(QString method, int param); QJsonValue makePayload(QString method); void getTransparentUnspent (const std::function& cb); @@ -143,7 +146,6 @@ private: void getTAddresses (const std::function& cb); void z_sweepstatus (const std::function& cb); void z_consolidationstatus (const std::function& cb); - void rescan (qint64 height, const std::function& cb); Connection* conn = nullptr; std::shared_ptr ehushd = nullptr; diff --git a/src/settings.ui b/src/settings.ui index 270fdff..1a6830f 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -22,11 +22,11 @@ true - - + + - 1 + 3 @@ -724,6 +724,9 @@ + + Qt::NoFocus + Troubleshooting @@ -743,32 +746,19 @@ - 9 - 38 + 10 + 10 583 51 - Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This may take several hours. You need to restart SilentDragon for this to take effect + Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. Click rescan to enter block height to rescan from. This may take several hours depending on submitted block height. true - - - - 9 - 9 - 73 - 23 - - - - Rescan - - @@ -989,10 +979,35 @@ MB + + + + 310 + 60 + 281 + 34 + + + + Qt::StrongFocus + + + Rescan + + + false + + + true + + + false + + - + Qt::Horizontal