From 7308206a10c574f8aa76fb031ca362f18708a028 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 17 Jul 2024 17:27:07 -0400 Subject: [PATCH] set trade role from utility class in api #1146 --- core/src/main/java/haveno/core/api/CoreApi.java | 4 ---- core/src/main/java/haveno/core/api/model/TradeInfo.java | 6 ++---- core/src/main/java/haveno/core/trade/TradeUtil.java | 4 ++-- .../src/main/java/haveno/daemon/grpc/GrpcTradesService.java | 3 +-- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/haveno/core/api/CoreApi.java b/core/src/main/java/haveno/core/api/CoreApi.java index fac92b31..25f98c34 100644 --- a/core/src/main/java/haveno/core/api/CoreApi.java +++ b/core/src/main/java/haveno/core/api/CoreApi.java @@ -561,10 +561,6 @@ public class CoreApi { return coreTradesService.getTrades(); } - public String getTradeRole(String tradeId) { - return coreTradesService.getTradeRole(tradeId); - } - public List getChatMessages(String tradeId) { return coreTradesService.getChatMessages(tradeId); } diff --git a/core/src/main/java/haveno/core/api/model/TradeInfo.java b/core/src/main/java/haveno/core/api/model/TradeInfo.java index f53d3ee9..fa94fd27 100644 --- a/core/src/main/java/haveno/core/api/model/TradeInfo.java +++ b/core/src/main/java/haveno/core/api/model/TradeInfo.java @@ -21,6 +21,7 @@ import haveno.common.Payload; import haveno.core.api.model.builder.TradeInfoV1Builder; import haveno.core.trade.Contract; import haveno.core.trade.Trade; +import haveno.core.trade.TradeUtil; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -142,10 +143,7 @@ public class TradeInfo implements Payload { } public static TradeInfo toTradeInfo(Trade trade) { - return toTradeInfo(trade, null); - } - - public static TradeInfo toTradeInfo(Trade trade, String role) { + String role = TradeUtil.getRole(trade); ContractInfo contractInfo; if (trade.getContract() != null) { Contract contract = trade.getContract(); diff --git a/core/src/main/java/haveno/core/trade/TradeUtil.java b/core/src/main/java/haveno/core/trade/TradeUtil.java index 1b55a6b2..bfebca48 100644 --- a/core/src/main/java/haveno/core/trade/TradeUtil.java +++ b/core/src/main/java/haveno/core/trade/TradeUtil.java @@ -172,7 +172,7 @@ public class TradeUtil { * @param trade Trade * @return String describing a trader's role for a given trade */ - public String getRole(Trade trade) { + public static String getRole(Trade trade) { Offer offer = trade.getOffer(); if (offer == null) throw new IllegalStateException(format("could not get role because no offer was found for trade '%s'", @@ -191,7 +191,7 @@ public class TradeUtil { * @param currencyCode String * @return String describing a trader's role */ - public String getRole(boolean isBuyerMakerAndSellerTaker, boolean isMaker, String currencyCode) { + private static String getRole(boolean isBuyerMakerAndSellerTaker, boolean isMaker, String currencyCode) { if (isTraditionalCurrency(currencyCode)) { String baseCurrencyCode = Res.getBaseCurrencyCode(); if (isBuyerMakerAndSellerTaker) diff --git a/daemon/src/main/java/haveno/daemon/grpc/GrpcTradesService.java b/daemon/src/main/java/haveno/daemon/grpc/GrpcTradesService.java index e521a7ee..123078b2 100644 --- a/daemon/src/main/java/haveno/daemon/grpc/GrpcTradesService.java +++ b/daemon/src/main/java/haveno/daemon/grpc/GrpcTradesService.java @@ -96,9 +96,8 @@ class GrpcTradesService extends TradesImplBase { StreamObserver responseObserver) { try { Trade trade = coreApi.getTrade(req.getTradeId()); - String role = coreApi.getTradeRole(req.getTradeId()); var reply = GetTradeReply.newBuilder() - .setTrade(toTradeInfo(trade, role).toProtoMessage()) + .setTrade(toTradeInfo(trade).toProtoMessage()) .build(); responseObserver.onNext(reply); responseObserver.onCompleted();