Skip to content

Commit

Permalink
Fix wallet scanning for newly created wallet (#1508)
Browse files Browse the repository at this point in the history
* Fix wallet scanning for newly created wallet

* Accept coderabbitai advice

* Minor fix debug message
levoncrypto authored Jan 13, 2025
1 parent 6da96d8 commit df530ba
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
@@ -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"))
3 changes: 3 additions & 0 deletions src/qt/recover.cpp
Original file line number Diff line number Diff line change
@@ -156,6 +156,9 @@ bool Recover::askRecover(bool& newWallet)
}

SoftSetArg("-mnemonic", mnemonic);
} else {
newWallet = true;
SoftSetBoolArg("-newwallet", newWallet);
}

if(recover.ui->usePassphrase->isChecked()) {
8 changes: 6 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit df530ba

Please sign in to comment.