From ead70751dcea9800ca33c01a8fd3f90d8a0123e8 Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 11 Mar 2023 16:10:57 -0500 Subject: [PATCH] add trader id to SignedOffer --- .../haveno/core/api/CoreDisputesService.java | 2 +- .../haveno/core/offer/OpenOfferManager.java | 1 + .../java/haveno/core/offer/SignedOffer.java | 13 +++++++++++++ proto/src/main/proto/pb.proto | 17 +++++++++-------- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/haveno/core/api/CoreDisputesService.java b/core/src/main/java/haveno/core/api/CoreDisputesService.java index d9ef0c6d0d..3413a61df8 100644 --- a/core/src/main/java/haveno/core/api/CoreDisputesService.java +++ b/core/src/main/java/haveno/core/api/CoreDisputesService.java @@ -236,7 +236,7 @@ public class CoreDisputesService { .add(buyerSecurityDeposit)); } else if (payout == DisputePayout.CUSTOM) { if (customWinnerAmount > trade.getWallet().getBalance().longValueExact()) { - throw new RuntimeException("The custom winner payout amount is more than the trade wallet's balance"); + throw new RuntimeException("Winner payout is more than the trade wallet's balance"); } long loserAmount = tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit).subtract(BigInteger.valueOf(customWinnerAmount)).longValueExact(); disputeResult.setBuyerPayoutAmount(BigInteger.valueOf(disputeResult.getWinner() == DisputeResult.Winner.BUYER ? customWinnerAmount : loserAmount)); diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index c52a491923..356ee4e9f0 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -1007,6 +1007,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // create record of signed offer SignedOffer signedOffer = new SignedOffer( System.currentTimeMillis(), + signedOfferPayload.getPubKeyRing().hashCode(), // trader id signedOfferPayload.getId(), offer.getAmount().longValueExact(), txResult.second.longValueExact(), diff --git a/core/src/main/java/haveno/core/offer/SignedOffer.java b/core/src/main/java/haveno/core/offer/SignedOffer.java index e8ea43986d..d4d757944a 100644 --- a/core/src/main/java/haveno/core/offer/SignedOffer.java +++ b/core/src/main/java/haveno/core/offer/SignedOffer.java @@ -18,6 +18,8 @@ package haveno.core.offer; import haveno.common.proto.persistable.PersistablePayload; +import haveno.core.util.JsonUtil; + import java.util.List; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -30,6 +32,8 @@ public final class SignedOffer implements PersistablePayload { @Getter private final long timeStamp; @Getter + private int traderId; + @Getter private final String offerId; @Getter private final long tradeAmount; @@ -47,6 +51,7 @@ public final class SignedOffer implements PersistablePayload { private final String arbitratorSignature; public SignedOffer(long timeStamp, + int traderId, String offerId, long tradeAmount, long penaltyAmount, @@ -56,6 +61,7 @@ public final class SignedOffer implements PersistablePayload { long reserveTxMinerFee, String arbitratorSignature) { this.timeStamp = timeStamp; + this.traderId = traderId; this.offerId = offerId; this.tradeAmount = tradeAmount; this.penaltyAmount = penaltyAmount; @@ -74,6 +80,7 @@ public final class SignedOffer implements PersistablePayload { public protobuf.SignedOffer toProtoMessage() { protobuf.SignedOffer.Builder builder = protobuf.SignedOffer.newBuilder() .setTimeStamp(timeStamp) + .setTraderId(traderId) .setOfferId(offerId) .setTradeAmount(tradeAmount) .setPenaltyAmount(penaltyAmount) @@ -87,6 +94,7 @@ public final class SignedOffer implements PersistablePayload { public static SignedOffer fromProto(protobuf.SignedOffer proto) { return new SignedOffer(proto.getTimeStamp(), + proto.getTraderId(), proto.getOfferId(), proto.getTradeAmount(), proto.getPenaltyAmount(), @@ -102,10 +110,15 @@ public final class SignedOffer implements PersistablePayload { // Getters /////////////////////////////////////////////////////////////////////////////////////////// + public String toJson() { + return JsonUtil.objectToJson(this); + } + @Override public String toString() { return "SignedOffer{" + ",\n timeStamp=" + timeStamp + + ",\n traderId=" + traderId + ",\n offerId=" + offerId + ",\n tradeAmount=" + tradeAmount + ",\n penaltyAmount=" + penaltyAmount + diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 9b53cf1410..38ea007916 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1348,14 +1348,15 @@ message SignedOfferList { message SignedOffer { int64 time_stamp = 1; - string offer_id = 2; - uint64 trade_amount = 3; - uint64 penalty_amount = 4; - string reserve_tx_hash = 5; - string reserve_tx_hex = 6; - repeated string reserve_tx_key_images = 7; - uint64 reserve_tx_miner_fee = 8; - string arbitrator_signature = 9; + int32 trader_id = 2; + string offer_id = 3; + uint64 trade_amount = 4; + uint64 penalty_amount = 5; + string reserve_tx_hash = 6; + string reserve_tx_hex = 7; + repeated string reserve_tx_key_images = 8; + uint64 reserve_tx_miner_fee = 9; + string arbitrator_signature = 10; } message OpenOffer {