From 75b8eb1dc937e24968445e7ff783851981c40c2b Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 8 Jul 2025 07:08:30 -0400 Subject: [PATCH] provide trade start time, duration, and deadline in grpc api --- .../java/haveno/core/api/model/TradeInfo.java | 18 ++++++++++++++++++ .../api/model/builder/TradeInfoV1Builder.java | 18 ++++++++++++++++++ .../src/main/java/haveno/core/trade/Trade.java | 8 ++++++-- proto/src/main/proto/grpc.proto | 3 +++ 4 files changed, 45 insertions(+), 2 deletions(-) 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 8df26368ba..a423bfa470 100644 --- a/core/src/main/java/haveno/core/api/model/TradeInfo.java +++ b/core/src/main/java/haveno/core/api/model/TradeInfo.java @@ -99,6 +99,9 @@ public class TradeInfo implements Payload { private final boolean isCompleted; private final String contractAsJson; private final ContractInfo contract; + private final long startTime; + private final long maxDurationMs; + private final long deadlineTime; public TradeInfo(TradeInfoV1Builder builder) { this.offer = builder.getOffer(); @@ -140,6 +143,9 @@ public class TradeInfo implements Payload { this.isCompleted = builder.isCompleted(); this.contractAsJson = builder.getContractAsJson(); this.contract = builder.getContract(); + this.startTime = builder.getStartTime(); + this.maxDurationMs = builder.getMaxDurationMs(); + this.deadlineTime = builder.getDeadlineTime(); } public static TradeInfo toTradeInfo(Trade trade) { @@ -202,6 +208,9 @@ public class TradeInfo implements Payload { .withContractAsJson(trade.getContractAsJson()) .withContract(contractInfo) .withOffer(toOfferInfo(trade.getOffer())) + .withStartTime(trade.getStartDate().getTime()) + .withMaxDurationMs(trade.getMaxTradePeriod()) + .withDeadlineTime(trade.getMaxTradePeriodDate().getTime()) .build(); } @@ -251,6 +260,9 @@ public class TradeInfo implements Payload { .setIsPayoutUnlocked(isPayoutUnlocked) .setContractAsJson(contractAsJson == null ? "" : contractAsJson) .setContract(contract.toProtoMessage()) + .setStartTime(startTime) + .setMaxDurationMs(maxDurationMs) + .setDeadlineTime(deadlineTime) .build(); } @@ -295,6 +307,9 @@ public class TradeInfo implements Payload { .withIsPayoutUnlocked(proto.getIsPayoutUnlocked()) .withContractAsJson(proto.getContractAsJson()) .withContract((ContractInfo.fromProto(proto.getContract()))) + .withStartTime(proto.getStartTime()) + .withMaxDurationMs(proto.getMaxDurationMs()) + .withDeadlineTime(proto.getDeadlineTime()) .build(); } @@ -339,6 +354,9 @@ public class TradeInfo implements Payload { ", offer=" + offer + "\n" + ", contractAsJson=" + contractAsJson + "\n" + ", contract=" + contract + "\n" + + ", startTime=" + startTime + "\n" + + ", maxDurationMs=" + maxDurationMs + "\n" + + ", deadlineTime=" + deadlineTime + "\n" + '}'; } } diff --git a/core/src/main/java/haveno/core/api/model/builder/TradeInfoV1Builder.java b/core/src/main/java/haveno/core/api/model/builder/TradeInfoV1Builder.java index dcf40b8a69..dfb99f820b 100644 --- a/core/src/main/java/haveno/core/api/model/builder/TradeInfoV1Builder.java +++ b/core/src/main/java/haveno/core/api/model/builder/TradeInfoV1Builder.java @@ -73,6 +73,9 @@ public final class TradeInfoV1Builder { private String contractAsJson; private ContractInfo contract; private String closingStatus; + private long startTime; + private long maxDurationMs; + private long deadlineTime; public TradeInfoV1Builder withOffer(OfferInfo offer) { this.offer = offer; @@ -284,6 +287,21 @@ public final class TradeInfoV1Builder { return this; } + public TradeInfoV1Builder withStartTime(long startTime) { + this.startTime = startTime; + return this; + } + + public TradeInfoV1Builder withMaxDurationMs(long maxDurationMs) { + this.maxDurationMs = maxDurationMs; + return this; + } + + public TradeInfoV1Builder withDeadlineTime(long deadlineTime) { + this.deadlineTime = deadlineTime; + return this; + } + public TradeInfo build() { return new TradeInfo(this); } diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index 29df35e45f..83002928bb 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -2153,6 +2153,10 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { } } + public long getMaxTradePeriod() { + return getOffer().getPaymentMethod().getMaxTradePeriod(); + } + public Date getHalfTradePeriodDate() { return new Date(getStartTime() + getMaxTradePeriod() / 2); } @@ -2161,8 +2165,8 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { return new Date(getStartTime() + getMaxTradePeriod()); } - private long getMaxTradePeriod() { - return getOffer().getPaymentMethod().getMaxTradePeriod(); + public Date getStartDate() { + return new Date(getStartTime()); } private long getStartTime() { diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index b2af139042..882e0a0623 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -908,6 +908,9 @@ message TradeInfo { string maker_deposit_tx_id = 37; string taker_deposit_tx_id = 38; string payout_tx_id = 39; + uint64 start_time = 40; + uint64 max_duration_ms = 41; + uint64 deadline_time = 42; } message ContractInfo {