Add wallet creation date to debug info

This commit is contained in:
tobtoht 2021-05-22 21:32:48 +02:00
parent 6a5e662f85
commit 31893f1d45
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
5 changed files with 14 additions and 10 deletions

View file

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

View file

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

View file

@ -17,7 +17,7 @@ struct RestoreHeightLookup {
QMap<int, int> 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<int, int>::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);

View file

@ -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);

View file

@ -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);