From 9c359b5e29c567acd84c4def7a4d60b12e918342 Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 16 Jul 2024 16:11:50 -0400 Subject: [PATCH] support deleting payment accounts #1136 --- core/src/main/java/haveno/core/api/CoreApi.java | 4 ++++ .../core/api/CorePaymentAccountsService.java | 10 ++++++++++ .../daemon/grpc/GrpcPaymentAccountsService.java | 15 +++++++++++++++ proto/src/main/proto/grpc.proto | 9 +++++++++ 4 files changed, 38 insertions(+) diff --git a/core/src/main/java/haveno/core/api/CoreApi.java b/core/src/main/java/haveno/core/api/CoreApi.java index b4a293a3b9..fac92b3124 100644 --- a/core/src/main/java/haveno/core/api/CoreApi.java +++ b/core/src/main/java/haveno/core/api/CoreApi.java @@ -496,6 +496,10 @@ public class CoreApi { tradeInstant); } + public void deletePaymentAccount(String paymentAccountId) { + paymentAccountsService.deletePaymentAccount(paymentAccountId); + } + public List getCryptoCurrencyPaymentMethods() { return paymentAccountsService.getCryptoCurrencyPaymentMethods(); } diff --git a/core/src/main/java/haveno/core/api/CorePaymentAccountsService.java b/core/src/main/java/haveno/core/api/CorePaymentAccountsService.java index df88d094a2..dcf1ef0e74 100644 --- a/core/src/main/java/haveno/core/api/CorePaymentAccountsService.java +++ b/core/src/main/java/haveno/core/api/CorePaymentAccountsService.java @@ -145,6 +145,16 @@ class CorePaymentAccountsService { return cryptoCurrencyAccount; } + synchronized void deletePaymentAccount(String paymentAccountId) { + accountService.checkAccountOpen(); + PaymentAccount paymentAccount = getPaymentAccount(paymentAccountId); + if (paymentAccount == null) throw new IllegalArgumentException(format("Payment account with id %s not found", paymentAccountId)); + user.removePaymentAccount(paymentAccount); + log.info("Deleted payment account with id {} and payment method {}.", + paymentAccount.getId(), + paymentAccount.getPaymentAccountPayload().getPaymentMethodId()); + } + // TODO Support all alt coin payment methods supported by UI. // The getCryptoCurrencyPaymentMethods method below will be // callable from the CLI when more are supported. diff --git a/daemon/src/main/java/haveno/daemon/grpc/GrpcPaymentAccountsService.java b/daemon/src/main/java/haveno/daemon/grpc/GrpcPaymentAccountsService.java index e29b448f83..ad1acce142 100644 --- a/daemon/src/main/java/haveno/daemon/grpc/GrpcPaymentAccountsService.java +++ b/daemon/src/main/java/haveno/daemon/grpc/GrpcPaymentAccountsService.java @@ -34,6 +34,8 @@ import haveno.proto.grpc.CreateCryptoCurrencyPaymentAccountReply; import haveno.proto.grpc.CreateCryptoCurrencyPaymentAccountRequest; import haveno.proto.grpc.CreatePaymentAccountReply; import haveno.proto.grpc.CreatePaymentAccountRequest; +import haveno.proto.grpc.DeletePaymentAccountReply; +import haveno.proto.grpc.DeletePaymentAccountRequest; import haveno.proto.grpc.GetCryptoCurrencyPaymentMethodsReply; import haveno.proto.grpc.GetCryptoCurrencyPaymentMethodsRequest; import haveno.proto.grpc.GetPaymentAccountFormReply; @@ -160,6 +162,19 @@ class GrpcPaymentAccountsService extends PaymentAccountsImplBase { } } + @Override + public void deletePaymentAccount(DeletePaymentAccountRequest req, + StreamObserver responseObserver) { + try { + coreApi.deletePaymentAccount(req.getPaymentAccountId()); + var reply = DeletePaymentAccountReply.newBuilder().build(); + responseObserver.onNext(reply); + responseObserver.onCompleted(); + } catch (Throwable cause) { + exceptionHandler.handleException(log, cause, responseObserver); + } + } + @Override public void getCryptoCurrencyPaymentMethods(GetCryptoCurrencyPaymentMethodsRequest req, StreamObserver responseObserver) { diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index c3dcf49833..1bb4c9f5ec 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -586,6 +586,8 @@ service PaymentAccounts { } rpc CreateCryptoCurrencyPaymentAccount (CreateCryptoCurrencyPaymentAccountRequest) returns (CreateCryptoCurrencyPaymentAccountReply) { } + rpc DeletePaymentAccount (DeletePaymentAccountRequest) returns (DeletePaymentAccountReply) { + } rpc GetCryptoCurrencyPaymentMethods (GetCryptoCurrencyPaymentMethodsRequest) returns (GetCryptoCurrencyPaymentMethodsReply) { } rpc ValidateFormField (ValidateFormFieldRequest) returns (ValidateFormFieldReply) { @@ -639,6 +641,13 @@ message CreateCryptoCurrencyPaymentAccountRequest { bool trade_instant = 4; } +message DeletePaymentAccountRequest { + string payment_account_id = 1; +} + +message DeletePaymentAccountReply { +} + message CreateCryptoCurrencyPaymentAccountReply { PaymentAccount payment_account = 1; }