diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index cecaadf0d5..8639c95602 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -17,6 +17,7 @@ package bisq.cli; +import bisq.proto.grpc.CancelOfferRequest; import bisq.proto.grpc.ConfirmPaymentReceivedRequest; import bisq.proto.grpc.ConfirmPaymentStartedRequest; import bisq.proto.grpc.CreateOfferRequest; @@ -74,6 +75,7 @@ public class CliMain { private enum Method { createoffer, + canceloffer, getoffer, getoffers, takeoffer, @@ -238,6 +240,18 @@ public class CliMain { out.println(formatOfferTable(singletonList(reply.getOffer()), currencyCode)); return; } + case canceloffer: { + if (nonOptionArgs.size() < 2) + throw new IllegalArgumentException("incorrect parameter count, expecting offer id"); + + var offerId = nonOptionArgs.get(1); + var request = CancelOfferRequest.newBuilder() + .setId(offerId) + .build(); + offersService.cancelOffer(request); + out.println("offer canceled and removed from offer book"); + return; + } case getoffer: { if (nonOptionArgs.size() < 2) throw new IllegalArgumentException("incorrect parameter count, expecting offer id"); @@ -246,7 +260,7 @@ public class CliMain { var request = GetOfferRequest.newBuilder() .setId(offerId) .build(); - var reply = offersService.getOffer(request); + var reply =offersService.getOffer(request); out.println(formatOfferTable(singletonList(reply.getOffer()), reply.getOffer().getCounterCurrencyCode())); return; @@ -475,6 +489,7 @@ public class CliMain { stream.format(rowFormat, "", "amount (btc), min amount, use mkt based price, \\", ""); stream.format(rowFormat, "", "fixed price (btc) | mkt price margin (%), \\", ""); stream.format(rowFormat, "", "security deposit (%)", ""); + stream.format(rowFormat, "canceloffer", "offer id", "Cancel offer with id"); stream.format(rowFormat, "getoffer", "offer id", "Get current offer with id"); stream.format(rowFormat, "getoffers", "buy | sell, currency code", "Get current offers"); stream.format(rowFormat, "takeoffer", "offer id", "Take offer with id"); diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index 001bf4773b..7cfcc5ce15 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -142,6 +142,10 @@ public class CoreApi { paymentAccount); } + public void cancelOffer(String id) { + coreOffersService.cancelOffer(id); + } + /////////////////////////////////////////////////////////////////////////////////////////// // PaymentAccounts /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/api/CoreOffersService.java b/core/src/main/java/bisq/core/api/CoreOffersService.java index da07677f1b..1a35af4ea2 100644 --- a/core/src/main/java/bisq/core/api/CoreOffersService.java +++ b/core/src/main/java/bisq/core/api/CoreOffersService.java @@ -160,6 +160,10 @@ class CoreOffersService { paymentAccount); } + void cancelOffer(String id) { + log.info("TODO"); + } + private void placeOffer(Offer offer, double buyerSecurityDeposit, boolean useSavingsWallet, diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java index d778593556..f03155d2f8 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java @@ -21,6 +21,8 @@ import bisq.core.api.CoreApi; import bisq.core.api.model.OfferInfo; import bisq.core.offer.Offer; +import bisq.proto.grpc.CancelOfferReply; +import bisq.proto.grpc.CancelOfferRequest; import bisq.proto.grpc.CreateOfferReply; import bisq.proto.grpc.CreateOfferRequest; import bisq.proto.grpc.GetOfferReply; @@ -114,4 +116,19 @@ class GrpcOffersService extends OffersGrpc.OffersImplBase { throw ex; } } + + @Override + public void cancelOffer(CancelOfferRequest req, + StreamObserver responseObserver) { + try { + coreApi.cancelOffer(req.getId()); + var reply = CancelOfferReply.newBuilder().build(); + responseObserver.onNext(reply); + responseObserver.onCompleted(); + } catch (IllegalStateException | IllegalArgumentException cause) { + var ex = new StatusRuntimeException(Status.UNKNOWN.withDescription(cause.getMessage())); + responseObserver.onError(ex); + throw ex; + } + } } diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 006c6a6f11..d9e0a3973d 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -51,6 +51,8 @@ service Offers { } rpc CreateOffer (CreateOfferRequest) returns (CreateOfferReply) { } + rpc CancelOffer (CancelOfferRequest) returns (CancelOfferReply) { + } } message GetOfferRequest { @@ -85,6 +87,13 @@ message CreateOfferReply { OfferInfo offer = 1; } +message CancelOfferRequest { + string id = 1; +} + +message CancelOfferReply { +} + message OfferInfo { string id = 1; string direction = 2;