fix: wallet should be unlocked before generating keys for Descriptor wallet

This commit is contained in:
Konstantin Akimov 2024-02-11 20:33:53 +07:00
parent f293c046f4
commit c1b94b6f52
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524

View File

@ -310,6 +310,14 @@ std::shared_ptr<CWallet> CreateWallet(interfaces::Chain& chain, interfaces::Coin
return nullptr;
}
if (!create_blank) {
// Unlock the wallet
if (!wallet->Unlock(passphrase)) {
error = Untranslated("Error: Wallet was encrypted but could not be unlocked");
status = DatabaseStatus::FAILED_ENCRYPT;
return nullptr;
}
// Set a seed for the wallet
if (wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
LOCK(wallet->cs_wallet);
wallet->SetupDescriptorScriptPubKeyMans();
@ -325,13 +333,6 @@ std::shared_ptr<CWallet> CreateWallet(interfaces::Chain& chain, interfaces::Coin
}
}
// Unlock the wallet
if (!wallet->Unlock(passphrase)) {
error = Untranslated("Error: Wallet was encrypted but could not be unlocked");
status = DatabaseStatus::FAILED_ENCRYPT;
return nullptr;
}
// backup the wallet we just encrypted
if (!wallet->AutoBackupWallet("", error, warnings) && !error.original.empty()) {
status = DatabaseStatus::FAILED_ENCRYPT;
@ -4885,6 +4886,7 @@ bool CWallet::UpgradeToHD(const SecureString& secureMnemonic, const SecureString
error = Untranslated("Failed to generate encrypted HD wallet");
return false;
}
Lock();
} else {
spk_man->GenerateNewHDChain(secureMnemonic, secureMnemonicPassphrase);
}
@ -5505,7 +5507,6 @@ bool CWallet::GenerateNewHDChainEncrypted(const SecureString& secureMnemonic, co
if (!spk_man->NewKeyPool()) {
throw std::runtime_error(std::string(__func__) + ": NewKeyPool failed");
}
Lock();
return true;
}