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
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
ui->statusBar->showMessage(tr("Rescanning..."));
ui->statusBar->showMessage(tr("Rescanning...") + tr(" from height ") + QString::number(rescanHeight), 5000);
// Close settings
QWidget *modalWidget = QApplication::activeModalWidget();
if (modalWidget)
modalWidget->close();
// Get submitted rescan height
int rescanHeight = rescanDialog.rescanBlockheight->text().toInt();
qDebug() << __func__ << ": rescan height = " << rescanHeight;
// Call rescan RPC
// TODO: This RPC might timeout, does the callback work correctly in that case?
rpc->rescan(rescanHeight, [=] (QJsonValue 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";

54
src/rpc.cpp

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

Loading…
Cancel
Save