From 6310a38d83d75fc3cacefd0713e8598e1c1a9633 Mon Sep 17 00:00:00 2001 From: levoncrypto Date: Mon, 16 Dec 2024 11:54:12 +0400 Subject: [PATCH 1/3] Fix wallet scanning for newly created wallet --- src/init.cpp | 3 +++ src/qt/recover.cpp | 2 ++ src/wallet/wallet.cpp | 8 ++++++-- 3 files changed, 11 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..8c5aa01ae5 100644 --- a/src/qt/recover.cpp +++ b/src/qt/recover.cpp @@ -156,6 +156,8 @@ bool Recover::askRecover(bool& newWallet) } SoftSetArg("-mnemonic", mnemonic); + } else { + SoftSetBoolArg("-newwallet", true); } if(recover.ui->usePassphrase->isChecked()) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 787a739f0d..b7fb41d78b 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, not 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(); From 60f9ac1e0731dc7cc0b191dc0e975a36b32164c5 Mon Sep 17 00:00:00 2001 From: levoncrypto Date: Mon, 16 Dec 2024 12:01:23 +0400 Subject: [PATCH 2/3] Accept coderabbitai advice --- src/qt/recover.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/recover.cpp b/src/qt/recover.cpp index 8c5aa01ae5..ce2e65672d 100644 --- a/src/qt/recover.cpp +++ b/src/qt/recover.cpp @@ -157,7 +157,8 @@ bool Recover::askRecover(bool& newWallet) SoftSetArg("-mnemonic", mnemonic); } else { - SoftSetBoolArg("-newwallet", true); + newWallet = true; + SoftSetBoolArg("-newwallet", newWallet); } if(recover.ui->usePassphrase->isChecked()) { From 4dfdb1ab43863dc26043a6395649762eb6a6b03a Mon Sep 17 00:00:00 2001 From: levoncrypto Date: Tue, 24 Dec 2024 16:00:33 +0400 Subject: [PATCH 3/3] Minor fix debug message --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b7fb41d78b..ab14516dfe 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2406,7 +2406,7 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex *pindexStart, bool f { CBlockIndex* ret = nullptr; if (GetBoolArg("-newwallet", false)) { - LogPrintf("Created new wallet, not need to scan\n"); + LogPrintf("Created new wallet, no need to scan\n"); return ret; } int64_t nNow = GetTime();