Skip to content

Commit 0359d9b

Browse files
committed
Change wallet validation order
In the current code, the database is created before the last validation, which checks that passphrase is set and private keys are disabled. Therefore, if this validation fails, it will result in an empty database and the user will not be able to recreate a wallet with the same name and with the correct parameters.
1 parent e14f0fa commit 0359d9b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
299299
return nullptr;
300300
}
301301

302+
// Do not allow a passphrase when private keys are disabled
303+
if (!passphrase.empty() && (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
304+
error = Untranslated("Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled.");
305+
status = DatabaseStatus::FAILED_CREATE;
306+
return nullptr;
307+
}
308+
302309
// Wallet::Verify will check if we're trying to create a wallet with a duplicate name.
303310
std::unique_ptr<WalletDatabase> database = MakeWalletDatabase(name, options, status, error);
304311
if (!database) {
@@ -307,13 +314,6 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
307314
return nullptr;
308315
}
309316

310-
// Do not allow a passphrase when private keys are disabled
311-
if (!passphrase.empty() && (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
312-
error = Untranslated("Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled.");
313-
status = DatabaseStatus::FAILED_CREATE;
314-
return nullptr;
315-
}
316-
317317
// Make the wallet
318318
context.chain->initMessage(_("Loading wallet…").translated);
319319
const std::shared_ptr<CWallet> wallet = CWallet::Create(context, name, std::move(database), wallet_creation_flags, error, warnings);

0 commit comments

Comments
 (0)