From 31893f1d45c17eb98871132d11fa3781d87029e9 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Sat, 22 May 2021 21:32:48 +0200 Subject: [PATCH] Add wallet creation date to debug info --- src/dialog/debuginfodialog.cpp | 3 ++- src/utils/FeatherSeed.h | 4 ++-- src/utils/RestoreHeightLookup.h | 8 ++++++-- src/widgets/restoreheightwidget.cpp | 4 ++-- src/wizard/PageSetRestoreHeight.cpp | 5 ++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/dialog/debuginfodialog.cpp b/src/dialog/debuginfodialog.cpp index 7fcab2e..768fa07 100644 --- a/src/dialog/debuginfodialog.cpp +++ b/src/dialog/debuginfodialog.cpp @@ -50,7 +50,8 @@ void DebugInfoDialog::updateInfo() { ui->label_walletHeight->setText(QString::number(m_ctx->wallet->blockChainHeight())); ui->label_daemonHeight->setText(QString::number(m_ctx->wallet->daemonBlockChainHeight())); ui->label_targetHeight->setText(QString::number(m_ctx->wallet->daemonBlockChainTargetHeight())); - ui->label_restoreHeight->setText(QString::number(m_ctx->wallet->getWalletCreationHeight())); + QDateTime restoreDate = appData()->restoreHeights[constants::networkType]->heightToDate(m_ctx->wallet->getWalletCreationHeight()); + ui->label_restoreHeight->setText(QString("%1 (%2)").arg(QString::number(m_ctx->wallet->getWalletCreationHeight()), restoreDate.toString("yyyy-MM-dd"))); ui->label_synchronized->setText(m_ctx->wallet->isSynchronized() ? "True" : "False"); auto node = m_ctx->nodes->connection(); diff --git a/src/utils/FeatherSeed.h b/src/utils/FeatherSeed.h index 47d6780..3232e67 100644 --- a/src/utils/FeatherSeed.h +++ b/src/utils/FeatherSeed.h @@ -93,13 +93,13 @@ struct FeatherSeed { if (this->time == 0) this->restoreHeight = 1; - this->restoreHeight = appData()->restoreHeights[netType]->dateToRestoreHeight(this->time); + this->restoreHeight = appData()->restoreHeights[netType]->dateToHeight(this->time); } int setRestoreHeight(int height) { auto now = std::time(nullptr); auto nowClearance = 3600 * 24; - auto currentBlockHeight = appData()->restoreHeights[netType]->dateToRestoreHeight(now - nowClearance); + auto currentBlockHeight = appData()->restoreHeights[netType]->dateToHeight(now - nowClearance); if (height >= currentBlockHeight + nowClearance) { qCritical() << "unrealistic restore height detected, setting to current blockheight instead: " << currentBlockHeight; this->restoreHeight = currentBlockHeight; diff --git a/src/utils/RestoreHeightLookup.h b/src/utils/RestoreHeightLookup.h index 4b23d76..b0499f0 100644 --- a/src/utils/RestoreHeightLookup.h +++ b/src/utils/RestoreHeightLookup.h @@ -17,7 +17,7 @@ struct RestoreHeightLookup { QMap data; explicit RestoreHeightLookup(NetworkType::Type type) : type(type) {} - int dateToRestoreHeight(int date) { + int dateToHeight(int date) { // restore height based on a given timestamp using a lookup // table. If it cannot find the date in the lookup table, it // will calculate the blockheight based off the last known @@ -49,7 +49,7 @@ struct RestoreHeightLookup { return blockHeight; } - int restoreHeightToDate(int height) { + int heightToTimestamp(int height) { // @TODO: most likely inefficient, refactor QMap::iterator i; int timestamp = 0; @@ -70,6 +70,10 @@ struct RestoreHeightLookup { return timestamp; } + QDateTime heightToDate(int height) { + return QDateTime::fromSecsSinceEpoch(this->heightToTimestamp(height)); + } + static RestoreHeightLookup *fromFile(const QString &fn, NetworkType::Type type) { // initialize this class using a lookup table, e.g `:/assets/restore_heights_monero_mainnet.txt`/ auto rtn = new RestoreHeightLookup(type); diff --git a/src/widgets/restoreheightwidget.cpp b/src/widgets/restoreheightwidget.cpp index 6ec42e8..f8b6a1d 100644 --- a/src/widgets/restoreheightwidget.cpp +++ b/src/widgets/restoreheightwidget.cpp @@ -33,7 +33,7 @@ void RestoreHeightWidget::setHeight(int height) { ui->lineEdit_restoreHeight->setText(QString::number(height)); // Update slider - int date = m_restoreHeightLookup->restoreHeightToDate(height); + int date = m_restoreHeightLookup->heightToTimestamp(height); ui->restoreSlider->setValue(date); this->updateTimestamp(date); @@ -49,7 +49,7 @@ void RestoreHeightWidget::initRestoreHeights(RestoreHeightLookup *lookup) { connect(ui->restoreSlider, &QSlider::sliderMoved, [this](int date){ // Update lineEdit - int blockHeight = m_restoreHeightLookup->dateToRestoreHeight(date); + int blockHeight = m_restoreHeightLookup->dateToHeight(date); ui->lineEdit_restoreHeight->setText(QString::number(blockHeight)); this->updateTimestamp(date); diff --git a/src/wizard/PageSetRestoreHeight.cpp b/src/wizard/PageSetRestoreHeight.cpp index 8fdc07d..7bd13fa 100644 --- a/src/wizard/PageSetRestoreHeight.cpp +++ b/src/wizard/PageSetRestoreHeight.cpp @@ -61,7 +61,7 @@ void PageSetRestoreHeight::onCreationDateEdited() { QDateTime restoreDate = date > curDate ? curDate : date; int timestamp = restoreDate.toSecsSinceEpoch(); - QString restoreHeight = QString::number(appData()->restoreHeights[constants::networkType]->dateToRestoreHeight(timestamp)); + QString restoreHeight = QString::number(appData()->restoreHeights[constants::networkType]->dateToHeight(timestamp)); ui->line_restoreHeight->setText(restoreHeight); this->showScanWarning(restoreDate); @@ -77,8 +77,7 @@ void PageSetRestoreHeight::onRestoreHeightEdited() { return; } - int timestamp = appData()->restoreHeights[constants::networkType]->restoreHeightToDate(restoreHeight); - auto date = QDateTime::fromSecsSinceEpoch(timestamp); + QDateTime date = appData()->restoreHeights[constants::networkType]->heightToDate(restoreHeight); ui->line_creationDate->setText(date.toString("yyyy-MM-dd")); this->showScanWarning(date);