From d30ad4a9129da04e249e3938f643dc47bf060e7e Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Tue, 13 Jan 2026 13:10:53 -0800 Subject: [PATCH] wallet, rpc: Use HandleWalletError in createwallet Use the utility function HandleWalletError to deal with wallet creation errors in createwallet. --- src/wallet/rpc/util.cpp | 3 +++ src/wallet/rpc/wallet.cpp | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpc/util.cpp b/src/wallet/rpc/util.cpp index d68e6c65269..46e7d4371c5 100644 --- a/src/wallet/rpc/util.cpp +++ b/src/wallet/rpc/util.cpp @@ -145,6 +145,9 @@ void HandleWalletError(const std::shared_ptr wallet, DatabaseStatus& st case DatabaseStatus::FAILED_INVALID_BACKUP_FILE: code = RPC_INVALID_PARAMETER; break; + case DatabaseStatus::FAILED_ENCRYPT: + code = RPC_WALLET_ENCRYPTION_FAILED; + break; default: // RPC_WALLET_ERROR is returned for all other cases. break; } diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index c7c3f459fff..49808a8d696 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -422,10 +422,7 @@ static RPCHelpMan createwallet() bilingual_str error; std::optional load_on_start = request.params[6].isNull() ? std::nullopt : std::optional(request.params[6].get_bool()); const std::shared_ptr wallet = CreateWallet(context, request.params[0].get_str(), load_on_start, options, status, error, warnings); - if (!wallet) { - RPCErrorCode code = status == DatabaseStatus::FAILED_ENCRYPT ? RPC_WALLET_ENCRYPTION_FAILED : RPC_WALLET_ERROR; - throw JSONRPCError(code, error.original); - } + HandleWalletError(wallet, status, error); UniValue obj(UniValue::VOBJ); obj.pushKV("name", wallet->GetName());