Skip to content

Commit

Permalink
fix: wallet should be unlocked before generating keys for Descriptor …
Browse files Browse the repository at this point in the history
…wallet
  • Loading branch information
knst committed Mar 6, 2024
1 parent f293c04 commit c1b94b6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit c1b94b6

Please sign in to comment.