mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-31 18:51:12 +00:00
wallet, rpc: Use HandleWalletError in createwallet
Use the utility function HandleWalletError to deal with wallet creation errors in createwallet.
This commit is contained in:
parent
796f18e559
commit
d30ad4a912
@ -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;
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user