From ca9bdf7c298d67fbb0c9e2d7f8beca93e0c6cbb7 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 23 May 2022 18:24:10 -0400 Subject: [PATCH] set offer trigger price and state from open offer --- .../main/java/bisq/core/api/model/OfferInfo.java | 13 ++++++++----- core/src/main/java/bisq/core/offer/Offer.java | 1 - .../java/bisq/core/offer/OpenOfferManager.java | 2 +- .../java/bisq/daemon/grpc/GrpcOffersService.java | 15 +++++++++------ proto/src/main/proto/pb.proto | 11 +++++------ 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/bisq/core/api/model/OfferInfo.java b/core/src/main/java/bisq/core/api/model/OfferInfo.java index 2e9c70a3a3..96ca5da45f 100644 --- a/core/src/main/java/bisq/core/api/model/OfferInfo.java +++ b/core/src/main/java/bisq/core/api/model/OfferInfo.java @@ -18,7 +18,7 @@ package bisq.core.api.model; import bisq.core.offer.Offer; - +import bisq.core.offer.OpenOffer; import bisq.common.Payload; import bisq.common.proto.ProtoUtil; import java.util.Objects; @@ -94,10 +94,13 @@ public class OfferInfo implements Payload { return getOfferInfoBuilder(offer).build(); } - public static OfferInfo toOfferInfo(Offer offer, long triggerPrice) { - // The Offer does not have a triggerPrice attribute, so we get - // the base OfferInfoBuilder, then add the OpenOffer's triggerPrice. - return getOfferInfoBuilder(offer).withTriggerPrice(triggerPrice).build(); + public static OfferInfo toOfferInfo(Offer offer, OpenOffer openOffer) { + OfferInfoBuilder builder = getOfferInfoBuilder(offer); + if (openOffer != null) { + builder.withState(openOffer.getState().name()); + builder.withTriggerPrice(openOffer.getTriggerPrice()); + } + return builder.build(); } private static OfferInfoBuilder getOfferInfoBuilder(Offer offer) { diff --git a/core/src/main/java/bisq/core/offer/Offer.java b/core/src/main/java/bisq/core/offer/Offer.java index 5e961c5204..79c899318a 100644 --- a/core/src/main/java/bisq/core/offer/Offer.java +++ b/core/src/main/java/bisq/core/offer/Offer.java @@ -82,7 +82,6 @@ public class Offer implements NetworkPayload, PersistablePayload { public enum State { UNKNOWN, - SCHEDULED, OFFER_FEE_RESERVED, AVAILABLE, NOT_AVAILABLE, diff --git a/core/src/main/java/bisq/core/offer/OpenOfferManager.java b/core/src/main/java/bisq/core/offer/OpenOfferManager.java index e175189745..ccc15bf025 100644 --- a/core/src/main/java/bisq/core/offer/OpenOfferManager.java +++ b/core/src/main/java/bisq/core/offer/OpenOfferManager.java @@ -696,7 +696,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // schedule txs openOffer.setScheduledTxHashes(scheduledTxHashes); openOffer.setScheduledAmount(scheduledAmount.toString()); - openOffer.getOffer().setState(Offer.State.SCHEDULED); + openOffer.setState(OpenOffer.State.SCHEDULED); } // handle result diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java index 16d5302d33..ce043825bc 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java @@ -39,7 +39,7 @@ import io.grpc.ServerInterceptor; import io.grpc.stub.StreamObserver; import javax.inject.Inject; - +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Optional; @@ -91,7 +91,7 @@ class GrpcOffersService extends OffersImplBase { Offer offer = coreApi.getMyOffer(req.getId()); OpenOffer openOffer = coreApi.getMyOpenOffer(req.getId()); var reply = GetMyOfferReply.newBuilder() - .setOffer(toOfferInfo(offer, openOffer.getTriggerPrice()).toProtoMessage()) + .setOffer(toOfferInfo(offer, openOffer).toProtoMessage()) .build(); responseObserver.onNext(reply); responseObserver.onCompleted(); @@ -123,9 +123,11 @@ class GrpcOffersService extends OffersImplBase { public void getMyOffers(GetMyOffersRequest req, StreamObserver responseObserver) { try { - List result = coreApi.getMyOffers(req.getDirection(), req.getCurrencyCode()) - .stream().map(OfferInfo::toOfferInfo) - .collect(Collectors.toList()); + List result = new ArrayList(); + for (Offer offer : coreApi.getMyOffers(req.getDirection(), req.getCurrencyCode())) { + OpenOffer openOffer = coreApi.getMyOpenOffer(offer.getId()); + result.add(toOfferInfo(offer, openOffer)); + } var reply = GetMyOffersReply.newBuilder() .addAllOffers(result.stream() .map(OfferInfo::toProtoMessage) @@ -161,7 +163,8 @@ class GrpcOffersService extends OffersImplBase { offer -> { // This result handling consumer's accept operation will return // the new offer to the gRPC client after async placement is done. - OfferInfo offerInfo = toOfferInfo(offer); + OpenOffer openOffer = coreApi.getMyOpenOffer(offer.getId()); + OfferInfo offerInfo = toOfferInfo(offer, openOffer); CreateOfferReply reply = CreateOfferReply.newBuilder() .setOffer(offerInfo.toProtoMessage()) .build(); diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index af2a92845c..f1d721ce3c 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1450,12 +1450,11 @@ message Offer { enum State { PB_ERROR = 0; UNKNOWN = 1; - SCHEDULED = 2; - OFFER_FEE_RESERVED = 3; - AVAILABLE = 4; - NOT_AVAILABLE = 5; - REMOVED = 6; - MAKER_OFFLINE = 7; + OFFER_FEE_RESERVED = 2; + AVAILABLE = 3; + NOT_AVAILABLE = 4; + REMOVED = 5; + MAKER_OFFLINE = 6; } OfferPayload offer_payload = 1;