From df530baf071b77232ce1ac360dd9543d68393e59 Mon Sep 17 00:00:00 2001 From: levoncrypto <95240473+levoncrypto@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:34:53 +0400 Subject: [PATCH] Fix wallet scanning for newly created wallet (#1508) * Fix wallet scanning for newly created wallet * Accept coderabbitai advice * Minor fix debug message --- src/init.cpp | 3 +++ src/qt/recover.cpp | 3 +++ src/wallet/wallet.cpp | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 1b2c071448..4af82f4fc5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -945,6 +945,9 @@ void InitParameterInteraction() } #ifdef ENABLE_WALLET + // Set arg "-newwallet" false by default for wallet scaning. + SoftSetBoolArg("-newwallet", false); + // Forcing all mnemonic settings off if -usehd is off. if (!GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET)) { if (SoftSetBoolArg("-usemnemonic", false) && SoftSetArg("-mnemonic", "") && SoftSetArg("-mnemonicpassphrase", "") && SoftSetArg("-hdseed", "not hex")) diff --git a/src/qt/recover.cpp b/src/qt/recover.cpp index 6be76c8089..ce2e65672d 100644 --- a/src/qt/recover.cpp +++ b/src/qt/recover.cpp @@ -156,6 +156,9 @@ bool Recover::askRecover(bool& newWallet) } SoftSetArg("-mnemonic", mnemonic); + } else { + newWallet = true; + SoftSetBoolArg("-newwallet", newWallet); } if(recover.ui->usePassphrase->isChecked()) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 787a739f0d..ab14516dfe 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2405,6 +2405,10 @@ CBlockIndex* CWallet::GetBlockByDate(CBlockIndex* pindexStart, const std::string CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex *pindexStart, bool fUpdate, bool fRecoverMnemonic) { CBlockIndex* ret = nullptr; + if (GetBoolArg("-newwallet", false)) { + LogPrintf("Created new wallet, no need to scan\n"); + return ret; + } int64_t nNow = GetTime(); const CChainParams& chainParams = Params(); @@ -7327,10 +7331,10 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) } } - uiInterface.InitMessage(_("Rescanning...")); + if (!(GetBoolArg("-newwallet", false))) {uiInterface.InitMessage(_("Rescanning..."));} nStart = GetTimeMillis(); walletInstance->ScanForWalletTransactions(pindexRescan, true, fRecoverMnemonic); - LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart); + if (!(GetBoolArg("-newwallet", false))) {LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart);} walletInstance->SetBestChain(chainActive.GetLocator()); CWalletDB::IncrementUpdateCounter();