wallet, rpc: Use HandleWalletError in createwallet

Use the utility function HandleWalletError to deal with wallet creation
errors in createwallet.
This commit is contained in:
Ava Chow 2026-01-13 13:10:53 -08:00
parent 796f18e559
commit d30ad4a912
2 changed files with 4 additions and 4 deletions

View File

@ -145,6 +145,9 @@ void HandleWalletError(const std::shared_ptr<CWallet> 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;
}

View File

@ -422,10 +422,7 @@ static RPCHelpMan createwallet()
bilingual_str error;
std::optional<bool> load_on_start = request.params[6].isNull() ? std::nullopt : std::optional<bool>(request.params[6].get_bool());
const std::shared_ptr<CWallet> 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());