Browse Source

WIP: Rescan changes

pull/112/head
fekt 2 years ago
parent
commit
f9b98b733f
  1. 55
      src/mainwindow.cpp
  2. 2
      src/mainwindow.h
  3. 13
      src/mainwindow.ui
  4. 91
      src/rescandialog.ui
  5. 12
      src/rpc.cpp
  6. 4
      src/rpc.h
  7. 55
      src/settings.ui

55
src/mainwindow.cpp

@ -13,6 +13,7 @@
#include "ui_settings.h" #include "ui_settings.h"
#include "ui_viewalladdresses.h" #include "ui_viewalladdresses.h"
#include "ui_validateaddress.h" #include "ui_validateaddress.h"
#include "ui_rescandialog.h"
#include "rpc.h" #include "rpc.h"
#include "balancestablemodel.h" #include "balancestablemodel.h"
#include "settings.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); int theme_index = settings.comboBoxTheme->findText(Settings::getInstance()->get_theme_name(), Qt::MatchExactly);
settings.comboBoxTheme->setCurrentIndex(theme_index); settings.comboBoxTheme->setCurrentIndex(theme_index);
@ -623,8 +629,8 @@ void MainWindow::setupSettingsModal() {
// Enable the troubleshooting options only if using embedded hushd // Enable the troubleshooting options only if using embedded hushd
if (!rpc->isEmbedded()) { if (!rpc->isEmbedded()) {
settings.chkRescan->setEnabled(false); //settings.chkRescan->setEnabled(false);
settings.chkRescan->setToolTip(tr("You're using an external hushd. Please restart hushd with -rescan")); //settings.chkRescan->setToolTip(tr("You're using an external hushd. Please restart hushd with -rescan"));
settings.chkReindex->setEnabled(false); settings.chkReindex->setEnabled(false);
settings.chkReindex->setToolTip(tr("You're using an external hushd. Please restart hushd with -reindex")); 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 // Check to see if rescan or reindex have been enabled
bool showRestartInfo = false; bool showRestartInfo = false;
bool showReindexInfo = false; bool showReindexInfo = false;
/*
if (settings.chkRescan->isChecked()) { if (settings.chkRescan->isChecked()) {
Settings::addToHushConf(hushConfLocation, "rescan=1"); Settings::addToHushConf(hushConfLocation, "rescan=1");
showRestartInfo = true; showRestartInfo = true;
} }*/
if (settings.chkReindex->isChecked()) { if (settings.chkReindex->isChecked()) {
Settings::addToHushConf(hushConfLocation, "reindex=1"); 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() MainWindow::~MainWindow()
{ {
delete ui; delete ui;

2
src/mainwindow.h

@ -127,6 +127,8 @@ private:
void memoButtonClicked(int number, bool includeReplyTo = false); void memoButtonClicked(int number, bool includeReplyTo = false);
void fileUploadButtonClicked(int number); void fileUploadButtonClicked(int number);
void setMemoEnabled(int number, bool enabled); void setMemoEnabled(int number, bool enabled);
void rescanButtonClicked(int number);
void donate(); void donate();
void website(); void website();

13
src/mainwindow.ui

@ -970,8 +970,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: #fff; <string notr="true"/>
image: url(:/img/res/logobig.gif);</string>
</property> </property>
<property name="text"> <property name="text">
<string/> <string/>
@ -1740,6 +1739,11 @@ image: url(:/img/res/logobig.gif);</string>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>
<customwidget>
<class>FilledIconLabel</class>
<extends>QLabel</extends>
<header>fillediconlabel.h</header>
</customwidget>
<customwidget> <customwidget>
<class>AddressCombo</class> <class>AddressCombo</class>
<extends>QComboBox</extends> <extends>QComboBox</extends>
@ -1750,11 +1754,6 @@ image: url(:/img/res/logobig.gif);</string>
<extends>QLabel</extends> <extends>QLabel</extends>
<header>qrcodelabel.h</header> <header>qrcodelabel.h</header>
</customwidget> </customwidget>
<customwidget>
<class>FilledIconLabel</class>
<extends>QLabel</extends>
<header>fillediconlabel.h</header>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>inputsCombo</tabstop> <tabstop>inputsCombo</tabstop>

91
src/rescandialog.ui

@ -0,0 +1,91 @@
<?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>542</width>
<height>108</height>
</rect>
</property>
<property name="windowTitle">
<string>Rescan</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="1" 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>
<item row="2" column="0" colspan="3">
<widget class="QLineEdit" name="rescanBlockheight"/>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Enter block height to rescan from:</string>
</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>

12
src/rpc.cpp

@ -135,6 +135,16 @@ QJsonValue RPC::makePayload(QString method, QString param) {
return payload; 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) { QJsonValue RPC::makePayload(QString method) {
QJsonObject payload = { QJsonObject payload = {
{"jsonrpc", "1.0"}, {"jsonrpc", "1.0"},
@ -154,7 +164,7 @@ void RPC::getTAddresses(const std::function<void(QJsonValue)>& cb) {
// full or partial rescan // full or partial rescan
void RPC::rescan(qint64 height, const std::function<void(QJsonValue)>& cb) { void RPC::rescan(qint64 height, const std::function<void(QJsonValue)>& cb) {
QString method = "rescan"; 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 // add/remove a banned node. ip can include an optional netmask

4
src/rpc.h

@ -117,6 +117,8 @@ public:
Connection* getConnection() { return conn; } Connection* getConnection() { return conn; }
void rescan(qint64 height, const std::function<void(QJsonValue)>& cb);
private: private:
void refreshBalances(); void refreshBalances();
@ -132,6 +134,7 @@ private:
void getBalance(const std::function<void(QJsonValue)>& cb); void getBalance(const std::function<void(QJsonValue)>& cb);
QJsonValue makePayload(QString method, QString param, QString param2); QJsonValue makePayload(QString method, QString param, QString param2);
QJsonValue makePayload(QString method, QString param); QJsonValue makePayload(QString method, QString param);
QJsonValue makePayload(QString method, int param);
QJsonValue makePayload(QString method); QJsonValue makePayload(QString method);
void getTransparentUnspent (const std::function<void(QJsonValue)>& cb); void getTransparentUnspent (const std::function<void(QJsonValue)>& cb);
@ -143,7 +146,6 @@ private:
void getTAddresses (const std::function<void(QJsonValue)>& cb); void getTAddresses (const std::function<void(QJsonValue)>& cb);
void z_sweepstatus (const std::function<void(QJsonValue)>& cb); void z_sweepstatus (const std::function<void(QJsonValue)>& cb);
void z_consolidationstatus (const std::function<void(QJsonValue)>& cb); void z_consolidationstatus (const std::function<void(QJsonValue)>& cb);
void rescan (qint64 height, const std::function<void(QJsonValue)>& cb);
Connection* conn = nullptr; Connection* conn = nullptr;
std::shared_ptr<QProcess> ehushd = nullptr; std::shared_ptr<QProcess> ehushd = nullptr;

55
src/settings.ui

@ -22,11 +22,11 @@
<property name="modal"> <property name="modal">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QGridLayout" name="gridLayout_2">
<item> <item row="0" column="0">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>3</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -724,6 +724,9 @@
</widget> </widget>
</widget> </widget>
<widget class="QWidget" name="tab_3"> <widget class="QWidget" name="tab_3">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<attribute name="title"> <attribute name="title">
<string>Troubleshooting</string> <string>Troubleshooting</string>
</attribute> </attribute>
@ -743,32 +746,19 @@
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>9</x> <x>10</x>
<y>38</y> <y>10</y>
<width>583</width> <width>583</width>
<height>51</height> <height>51</height>
</rect> </rect>
</property> </property>
<property name="text"> <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 SilentDragon for this to take effect</string> <string>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.</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
<widget class="QCheckBox" name="chkRescan">
<property name="geometry">
<rect>
<x>9</x>
<y>9</y>
<width>73</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Rescan</string>
</property>
</widget>
<widget class="Line" name="line_3"> <widget class="Line" name="line_3">
<property name="geometry"> <property name="geometry">
<rect> <rect>
@ -989,10 +979,35 @@
<string>MB</string> <string>MB</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="rescanButton">
<property name="geometry">
<rect>
<x>310</x>
<y>60</y>
<width>281</width>
<height>34</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="text">
<string>Rescan</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</widget> </widget>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>

Loading…
Cancel
Save