diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 96de7e8c0b..a95bc530ab 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -310,6 +310,14 @@ std::shared_ptr 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 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; }