diff --git a/src/qt/forms/recover.ui b/src/qt/forms/recover.ui index f10691d2ef..51c7cae951 100644 --- a/src/qt/forms/recover.ui +++ b/src/qt/forms/recover.ui @@ -165,13 +165,6 @@ Also you can choose wallet birth date for more faster and optimised wallet scan. - - - - Enable Date Selection - - - diff --git a/src/qt/recover.cpp b/src/qt/recover.cpp index 3ce259d269..6be76c8089 100644 --- a/src/qt/recover.cpp +++ b/src/qt/recover.cpp @@ -32,7 +32,6 @@ Recover::Recover(QWidget *parent) : connect(this, &Recover::stopThread, thread, &QThread::quit); thread->start(); - connect(ui->enableDateSelection, &QCheckBox::toggled, this, &Recover::updateDateInputState); ui->dateInput->setDisplayFormat("dd-MM-yyyy"); ui->dateInput->setMinimumDate(QDate(2019, 12, 11)); } @@ -53,7 +52,6 @@ void Recover::setCreateNew() ui->mnemonicWords->clear(); ui->dateInput->setEnabled(false); ui->dateInput->clear(); - ui->enableDateSelection->setEnabled(false); ui->use24->setChecked(true); ui->usePassphrase->setChecked(false); ui->textLabel3->setEnabled(false); @@ -62,11 +60,6 @@ void Recover::setCreateNew() ui->mnemonicPassPhrase2->setEnabled(false); } -void Recover::updateDateInputState(bool checked) { - ui->dateInput->setEnabled(checked); - ui->dateInput->setMinimumDate(QDate(2019, 12, 11)); -} - void Recover::on_createNew_clicked() { setCreateNew(); @@ -79,8 +72,7 @@ void Recover::on_recoverExisting_clicked() ui->textLabel2->setEnabled(true); ui->mnemonicWords->setEnabled(true); ui->dateInput->setEnabled(true); - ui->dateInput->setEnabled(ui->enableDateSelection->isChecked()); - ui->enableDateSelection->setEnabled(true); + ui->dateInput->setEnabled(true); ui->dateInput->setDisplayFormat("dd-MM-yyyy"); ui->dateInput->setDate(ui->dateInput->minimumDate()); } @@ -125,14 +117,10 @@ bool Recover::askRecover(bool& newWallet) if(recover.ui->recoverExisting->isChecked()) { newWallet = false; std::string mnemonic = recover.ui->mnemonicWords->text().toStdString(); - if (recover.ui->enableDateSelection->isChecked()) { - QDate date = recover.ui->dateInput->date(); - QDate newDate = date.addDays(-1); - recover.ui->dateInput->setDate(newDate); - SoftSetArg("-wcdate", recover.ui->dateInput->text().toStdString()); - } else { - SoftSetArg("-wcdate", ""); - } + QDate date = recover.ui->dateInput->date(); + QDate newDate = date.addDays(-1); + recover.ui->dateInput->setDate(newDate); + SoftSetArg("-wcdate", recover.ui->dateInput->text().toStdString()); const char* str = mnemonic.c_str(); bool space = true; int n = 0; diff --git a/src/qt/recover.h b/src/qt/recover.h index 2b918883d9..d91321e27b 100644 --- a/src/qt/recover.h +++ b/src/qt/recover.h @@ -22,7 +22,6 @@ class Recover : public QDialog void stopThread(); private Q_SLOTS: - void updateDateInputState(bool checked); void on_createNew_clicked(); void on_recoverExisting_clicked(); void on_usePassphrase_clicked(); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 94a63565b4..9b3e1505b9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2371,19 +2371,18 @@ static std::time_t parseDate(const std::string& dateStr) { return std::mktime(&tm); } -int CWallet::GetBlockHeightByDate(CBlockIndex* pindexStart, const std::string& dateStr) { +CBlockIndex* CWallet::GetBlockByDate(CBlockIndex* pindexStart, const std::string& dateStr) { std::time_t targetTimestamp = parseDate(dateStr); CBlockIndex* pindex = pindexStart; while (pindex) { if (pindex->GetBlockTime() > targetTimestamp) { - return pindex->nHeight - 200; + return chainActive[pindex->nHeight - 200]; } pindex = chainActive.Next(pindex); } - - return chainActive.Tip()->nHeight; + return chainActive[chainActive.Tip()->nHeight]; } /** @@ -2404,27 +2403,36 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex *pindexStart, bool f CBlockIndex* pindex = pindexStart; { LOCK2(cs_main, cs_wallet); - - // no need to read and scan block, if block was created before - // our wallet birthday (as adjusted for block time variability) - // if you are recovering wallet with mnemonics start rescan from block when mnemonics implemented in Firo - int targetHeight = 0; + // No need to read and scan block if block was created before our wallet birthday (as adjusted for block time variability). + // If you are recovering wallet with mnemonics, start rescan from the block when mnemonics were implemented in Firo. + // If the user provides a date, start scanning from the block that corresponds to that date. + // If no date is provided, start scanning from the mnemonic start block. + + std::string wcdate = GetArg("-wcdate", ""); + CBlockIndex* mnemonicStartBlock = chainActive[chainParams.GetConsensus().nMnemonicBlock]; + CBlockIndex* dateBlockPindex = pindexStart; + if (!wcdate.empty()) { + dateBlockPindex = GetBlockByDate(mnemonicStartBlock, wcdate); + if (dateBlockPindex->nHeight < chainParams.GetConsensus().nMnemonicBlock) { + dateBlockPindex = chainActive[chainParams.GetConsensus().nMnemonicBlock]; + } + } else { + dateBlockPindex = mnemonicStartBlock; + } + pindex = dateBlockPindex; if (fRecoverMnemonic) { - std::string wcdate = GetArg("-wcdate", ""); - CBlockIndex* mnemonicStartBlock = chainActive[chainParams.GetConsensus().nMnemonicBlock]; - targetHeight = GetBlockHeightByDate(mnemonicStartBlock, wcdate); + if (pindex == nullptr) + pindex = chainActive.Tip(); + } else { if (!wcdate.empty()) { - if (targetHeight < chainParams.GetConsensus().nMnemonicBlock) { - targetHeight = chainParams.GetConsensus().nMnemonicBlock; - } - pindex = chainActive[targetHeight]; + pindex = dateBlockPindex; } else { - pindex = mnemonicStartBlock; + while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200))) + pindex = chainActive.Next(pindex); } - } else - while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200))) - pindex = chainActive.Next(pindex); - LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height(), targetHeight); + } + + LogPrintf("Rescanning last %i blocks (from block %i)...\n", chainActive.Height(), pindex->nHeight); ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup double dProgressStart = GuessVerificationProgress(chainParams.TxData(), pindex); double dProgressTip = GuessVerificationProgress(chainParams.TxData(), chainActive.Tip()); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 1d53bf3a23..f9397f5150 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -929,7 +929,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, int posInBlock) override; bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate); CBlockIndex* ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false, bool fRecoverMnemonic = false); - int GetBlockHeightByDate(CBlockIndex* pindexStart, const std::string& dateStr); + CBlockIndex* GetBlockByDate(CBlockIndex* pindexStart, const std::string& dateStr); void ReacceptWalletTransactions(); void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override; std::vector ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman);