Browse Source

Use PreciseTimer for main timer and rescanTimer

pull/112/head
Duke Leto 2 years ago
parent
commit
c8c26b12df
  1. 12
      src/mainwindow.cpp
  2. 54
      src/rpc.cpp

12
src/mainwindow.cpp

@ -2221,22 +2221,24 @@ void MainWindow::rescanButtonClicked(int number) {
// Check if OK clicked // Check if OK clicked
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
// Get submitted rescan height
int rescanHeight = rescanDialog.rescanBlockheight->text().toInt();
qDebug() << __func__ << ": rescan height = " << rescanHeight;
// Show message in status bar // Show message in status bar
ui->statusBar->showMessage(tr("Rescanning...")); ui->statusBar->showMessage(tr("Rescanning...") + tr(" from height ") + QString::number(rescanHeight), 5000);
// Close settings // Close settings
QWidget *modalWidget = QApplication::activeModalWidget(); QWidget *modalWidget = QApplication::activeModalWidget();
if (modalWidget) if (modalWidget)
modalWidget->close(); modalWidget->close();
// Get submitted rescan height
int rescanHeight = rescanDialog.rescanBlockheight->text().toInt();
qDebug() << __func__ << ": rescan height = " << rescanHeight;
// Call rescan RPC // Call rescan RPC
// TODO: This RPC might timeout, does the callback work correctly in that case?
rpc->rescan(rescanHeight, [=] (QJsonValue response){ rpc->rescan(rescanHeight, [=] (QJsonValue response){
qDebug() << __func__ << ":rescanning finished" << response; qDebug() << __func__ << ":rescanning finished" << response;
ui->statusBar->showMessage(tr("Rescanning finished"), 3000); ui->statusBar->showMessage(tr("Rescanning finished"), 5000);
}); });
qDebug() << __func__ << ": force refresh of rescan data"; qDebug() << __func__ << ": force refresh of rescan data";

54
src/rpc.cpp

@ -48,14 +48,16 @@ RPC::RPC(MainWindow* main) {
qDebug() << "setting up timer for rescan data"; qDebug() << "setting up timer for rescan data";
rescanTimer = new QTimer(main); rescanTimer = new QTimer(main);
// PreciseTimer is needed for timely GUI updates
rescanTimer->setTimerType(Qt::PreciseTimer);
QObject::connect(rescanTimer, &QTimer::timeout, [=]() { QObject::connect(rescanTimer, &QTimer::timeout, [=]() {
qDebug() << "Refreshing rescan data"; qDebug() << "Refreshing rescan data";
refreshRescan(); refreshRescan();
}); });
rescanTimer->start(1000);
qDebug() << __func__ << ": started rescanTimer"; qDebug() << __func__ << ": started rescanTimer";
rescanTimer->start(Settings::updateSpeed);
qDebug() << __func__ << ": Setting up a timer to refresh the UI every few seconds"; qDebug() << __func__ << ": Setting up a timer to refresh the UI every few seconds";
timer = new QTimer(main); timer = new QTimer(main);
@ -64,6 +66,8 @@ RPC::RPC(MainWindow* main) {
refresh(); refresh();
}); });
timer->start(Settings::updateSpeed); timer->start(Settings::updateSpeed);
// PreciseTimer is needed for timely GUI updates
timer->setTimerType(Qt::PreciseTimer);
qDebug() << __func__ << ": Set up the timer to watch for tx status"; qDebug() << __func__ << ": Set up the timer to watch for tx status";
txTimer = new QTimer(main); txTimer = new QTimer(main);
@ -198,7 +202,8 @@ void RPC::rescan(qint64 height, const std::function<void(QJsonValue)>& cb) {
// get rescan info // get rescan info
void RPC::getRescanInfo(const std::function<void(QJsonValue)>& cb){ void RPC::getRescanInfo(const std::function<void(QJsonValue)>& cb){
QString method = "getrescaninfo"; QString method = "getrescaninfo";
conn->doRPCWithDefaultErrorHandling(makePayload(method), cb); // do not show an error in case getrescaninfo doesn't exist in this hushd
conn->doRPCIgnoreError(makePayload(method), cb);
} }
// get help // get help
@ -1002,36 +1007,27 @@ void RPC::refreshBalances() {
void RPC::refreshRescan() { void RPC::refreshRescan() {
qDebug() << __func__; qDebug() << __func__;
if (conn == nullptr) { if (conn == nullptr) {
qDebug() << __func__ << ": no connection";
return noConnection(); return noConnection();
} }
conn->doRPC(makePayload("help", "getrescaninfo"), [=] (const QJsonValue& reply) { getRescanInfo([=] (QJsonValue response){
qDebug() << __func__ << ": found getrescaninfo: reply=" << reply; qDebug() << "got getrescaninfo json=" << response;
// Get rescan info auto rescanning = response.toObject().value("rescanning").toBool();
QObject::connect(rescanTimer, &QTimer::timeout, [=]() { auto rescan_progress = response.toObject().value("rescan_progress").toString();
qDebug() << "setting callback for getrescaninfo"; auto rescan_start_height = (qint64)response.toObject().value("rescan_start_height").toInt();
getRescanInfo([=] (QJsonValue response){ auto rescan_height = (qint64)response.toObject().value("rescan_height").toInt();
qDebug() << "got getrescaninfo json"; double percent = QString(rescan_progress).toDouble() * 100;
auto rescanning = response.toObject().value("rescanning").toBool(); qDebug() << __func__ << ": getrescaninfo" << rescanning << " " << percent << " " << rescan_start_height << " " << rescan_height;
auto rescan_progress = response.toObject().value("rescan_progress").toString();
auto rescan_start_height = (qint64)response.toObject().value("rescan_start_height").toInt(); if(rescanning){
auto rescan_height = (qint64)response.toObject().value("rescan_height").toInt(); // pauseTimer();
double percent = QString(rescan_progress).toDouble() * 100; qDebug() << __func__ << ": Rescanning at " << percent << "e";
qDebug() << __func__ << ": getrescaninfo" << rescanning << " " << percent << " " << rescan_start_height << " " << rescan_height; ui->statusBar->showMessage(QObject::tr("Rescanning... ") + QString::number(percent)+ "% " + QObject::tr("at height") + " " + QString::number(rescan_height));
} else{
if(rescanning){ qDebug() << __func__ << ": not rescanning";
pauseTimer(); }
qDebug() << __func__ << ": Rescanning at " << percent << " %";
ui->statusBar->showMessage(QObject::tr("Rescanning... ") + QString::number(percent)+ "% " + QObject::tr("at height") + " " + QString::number(rescan_height));
} else{
qDebug() << __func__ << ": not rescanning";
}
});
});
}, [=](QNetworkReply* reply, const QJsonValue&) {
qDebug() << __func__ << ": missing getrescaninfo, no rescan progress will be shown: reply=" << reply;
}); });
} }
void RPC::refreshPeers() { void RPC::refreshPeers() {

Loading…
Cancel
Save