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_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;

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

13
src/mainwindow.ui

@ -970,8 +970,7 @@
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: #fff;
image: url(:/img/res/logobig.gif);</string>
<string notr="true"/>
</property>
<property name="text">
<string/>
@ -1740,6 +1739,11 @@ image: url(:/img/res/logobig.gif);</string>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>FilledIconLabel</class>
<extends>QLabel</extends>
<header>fillediconlabel.h</header>
</customwidget>
<customwidget>
<class>AddressCombo</class>
<extends>QComboBox</extends>
@ -1750,11 +1754,6 @@ image: url(:/img/res/logobig.gif);</string>
<extends>QLabel</extends>
<header>qrcodelabel.h</header>
</customwidget>
<customwidget>
<class>FilledIconLabel</class>
<extends>QLabel</extends>
<header>fillediconlabel.h</header>
</customwidget>
</customwidgets>
<tabstops>
<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;
}
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<void(QJsonValue)>& cb) {
// full or partial rescan
void RPC::rescan(qint64 height, const std::function<void(QJsonValue)>& 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

4
src/rpc.h

@ -117,6 +117,8 @@ public:
Connection* getConnection() { return conn; }
void rescan(qint64 height, const std::function<void(QJsonValue)>& cb);
private:
void refreshBalances();
@ -132,6 +134,7 @@ private:
void getBalance(const std::function<void(QJsonValue)>& 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<void(QJsonValue)>& cb);
@ -143,7 +146,6 @@ private:
void getTAddresses (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 rescan (qint64 height, const std::function<void(QJsonValue)>& cb);
Connection* conn = nullptr;
std::shared_ptr<QProcess> ehushd = nullptr;

55
src/settings.ui

@ -22,11 +22,11 @@
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>3</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -724,6 +724,9 @@
</widget>
</widget>
<widget class="QWidget" name="tab_3">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<attribute name="title">
<string>Troubleshooting</string>
</attribute>
@ -743,32 +746,19 @@
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>9</x>
<y>38</y>
<x>10</x>
<y>10</y>
<width>583</width>
<height>51</height>
</rect>
</property>
<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 name="wordWrap">
<bool>true</bool>
</property>
</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">
<property name="geometry">
<rect>
@ -989,10 +979,35 @@
<string>MB</string>
</property>
</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>
</item>
<item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>

Loading…
Cancel
Save