Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wallet scanning for newly created wallet #1508

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 2 additions & 0 deletions src/qt/recover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ bool Recover::askRecover(bool& newWallet)
}

SoftSetArg("-mnemonic", mnemonic);
} else {
SoftSetBoolArg("-newwallet", true);
levoncrypto marked this conversation as resolved.
Show resolved Hide resolved
}

if(recover.ui->usePassphrase->isChecked()) {
Expand Down
8 changes: 6 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
levoncrypto marked this conversation as resolved.
Show resolved Hide resolved
return ret;
}
int64_t nNow = GetTime();
const CChainParams& chainParams = Params();

Expand Down Expand Up @@ -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);}
Comment on lines +7334 to +7337

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for making the messages conditional but not the actual operation itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition to prevent scanning if a new wallet has been created is placed inside the ScanForWalletTransactions function. This approach makes it easy to change the algorithm in the future without having to edit each function call. It also helps avoid code duplication and simplifies testing since all the logic is in one place.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

walletInstance->SetBestChain(chainActive.GetLocator());
CWalletDB::IncrementUpdateCounter();

Expand Down
Loading