Skip to content

Commit e967cae

Browse files
Fabian Jahrfjahr
authored andcommitted
Use switch on status in RpcWallet
1 parent ba1f128 commit e967cae

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,12 +2686,14 @@ static UniValue createwallet(const JSONRPCRequest& request)
26862686
std::string warning;
26872687
std::shared_ptr<CWallet> wallet;
26882688
WalletCreationStatus status = CreateWallet(*g_rpc_interfaces->chain, passphrase, flags, request.params[0].get_str(), error, warning, wallet);
2689-
if (status == WalletCreationStatus::CREATION_FAILED) {
2690-
throw JSONRPCError(RPC_WALLET_ERROR, error);
2691-
} else if (status == WalletCreationStatus::ENCRYPTION_FAILED) {
2692-
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error);
2693-
} else if (status != WalletCreationStatus::SUCCESS) {
2694-
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed");
2689+
switch (status) {
2690+
case WalletCreationStatus::CREATION_FAILED:
2691+
throw JSONRPCError(RPC_WALLET_ERROR, error);
2692+
case WalletCreationStatus::ENCRYPTION_FAILED:
2693+
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error);
2694+
case WalletCreationStatus::SUCCESS:
2695+
break;
2696+
// no default case, so the compiler can warn about missing cases
26952697
}
26962698

26972699
UniValue obj(UniValue::VOBJ);

0 commit comments

Comments
 (0)