From cd108387a2b37e94194e014b44e26649533bb2de Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 10 Nov 2021 04:47:37 -0500 Subject: [PATCH] restore dispute summary message --- .../core/support/dispute/DisputeResult.java | 8 ++ .../witness/AccountAgeWitnessServiceTest.java | 1 + .../windows/DisputeSummaryWindow.java | 73 ++++++++----------- .../dispute/DisputeSummaryVerification.java | 34 ++++----- proto/src/main/proto/pb.proto | 2 +- 5 files changed, 57 insertions(+), 61 deletions(-) diff --git a/core/src/main/java/bisq/core/support/dispute/DisputeResult.java b/core/src/main/java/bisq/core/support/dispute/DisputeResult.java index 20135baed1..338186a104 100644 --- a/core/src/main/java/bisq/core/support/dispute/DisputeResult.java +++ b/core/src/main/java/bisq/core/support/dispute/DisputeResult.java @@ -80,6 +80,9 @@ public final class DisputeResult implements NetworkPayload { @Setter @Nullable private ChatMessage chatMessage; + @Setter + @Nullable + private byte[] arbitratorSignature; private long buyerPayoutAmount; private long sellerPayoutAmount; @Setter @@ -111,6 +114,7 @@ public final class DisputeResult implements NetworkPayload { boolean screenCast, String summaryNotes, @Nullable ChatMessage chatMessage, + @Nullable byte[] arbitratorSignature, @Nullable String arbitratorPayoutTxSigned, @Nullable String arbitratorUpdatedMultisigHex, long buyerPayoutAmount, @@ -127,6 +131,7 @@ public final class DisputeResult implements NetworkPayload { this.screenCastProperty.set(screenCast); this.summaryNotesProperty.set(summaryNotes); this.chatMessage = chatMessage; + this.arbitratorSignature = arbitratorSignature; this.arbitratorSignedPayoutTxHex = arbitratorPayoutTxSigned; this.arbitratorUpdatedMultisigHex = arbitratorUpdatedMultisigHex; this.buyerPayoutAmount = buyerPayoutAmount; @@ -151,6 +156,7 @@ public final class DisputeResult implements NetworkPayload { proto.getScreenCast(), proto.getSummaryNotes(), proto.getChatMessage() == null ? null : ChatMessage.fromPayloadProto(proto.getChatMessage()), + proto.getArbitratorSignature().toByteArray(), ProtoUtil.stringOrNullFromProto(proto.getArbitratorSignedPayoutTxHex()), ProtoUtil.stringOrNullFromProto(proto.getArbitratorUpdatedMultisigHex()), proto.getBuyerPayoutAmount(), @@ -175,6 +181,7 @@ public final class DisputeResult implements NetworkPayload { .setCloseDate(closeDate) .setIsLoserPublisher(isLoserPublisher); + Optional.ofNullable(arbitratorSignature).ifPresent(arbitratorSignature -> builder.setArbitratorSignature(ByteString.copyFrom(arbitratorSignature))); Optional.ofNullable(arbitratorSignedPayoutTxHex).ifPresent(arbitratorPayoutTxSigned -> builder.setArbitratorSignedPayoutTxHex(arbitratorPayoutTxSigned)); Optional.ofNullable(arbitratorUpdatedMultisigHex).ifPresent(arbitratorUpdatedMultisigHex -> builder.setArbitratorUpdatedMultisigHex(arbitratorUpdatedMultisigHex)); Optional.ofNullable(arbitratorPubKey).ifPresent(arbitratorPubKey -> builder.setArbitratorPubKey(ByteString.copyFrom(arbitratorPubKey))); @@ -257,6 +264,7 @@ public final class DisputeResult implements NetworkPayload { ",\n screenCastProperty=" + screenCastProperty + ",\n summaryNotesProperty=" + summaryNotesProperty + ",\n chatMessage=" + chatMessage + + ",\n arbitratorSignature=" + Utilities.bytesAsHexString(arbitratorSignature) + ",\n arbitratorPayoutTxSigned=" + arbitratorSignedPayoutTxHex + ",\n arbitratorUpdatedMultisigHex=" + arbitratorUpdatedMultisigHex + ",\n buyerPayoutAmount=" + buyerPayoutAmount + diff --git a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java index 0155ff370c..abea6c4e6a 100644 --- a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java +++ b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java @@ -213,6 +213,7 @@ public class AccountAgeWitnessServiceTest { null, null, null, + null, 100000, 0, null, diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/DisputeSummaryWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/DisputeSummaryWindow.java index e6c5a2bebf..cf7f1d8d98 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/DisputeSummaryWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/DisputeSummaryWindow.java @@ -23,10 +23,10 @@ import bisq.desktop.components.BisqTextArea; import bisq.desktop.components.InputTextField; import bisq.desktop.main.overlays.Overlay; import bisq.desktop.main.overlays.popups.Popup; +import bisq.desktop.main.support.dispute.DisputeSummaryVerification; import bisq.desktop.util.DisplayUtils; import bisq.desktop.util.Layout; -import bisq.core.btc.model.XmrAddressEntry; import bisq.core.btc.wallet.TradeWalletService; import bisq.core.btc.wallet.XmrWalletService; import bisq.core.locale.Res; @@ -801,58 +801,45 @@ public class DisputeSummaryWindow extends Overlay { return; } -// boolean isRefundAgent = disputeManager instanceof RefundManager; + boolean isRefundAgent = disputeManager instanceof RefundManager; disputeResult.setLoserPublisher(isLoserPublisherCheckBox.isSelected()); disputeResult.setCloseDate(new Date()); dispute.setDisputeResult(disputeResult); dispute.setIsClosed(); -// DisputeResult.Reason reason = disputeResult.getReason(); + DisputeResult.Reason reason = disputeResult.getReason(); summaryNotesTextArea.textProperty().unbindBidirectional(disputeResult.summaryNotesProperty()); - // TODO (woodser): not used for xmr? calls setArbitratorSignature() + String role = isRefundAgent ? Res.get("shared.refundAgent") : Res.get("shared.mediator"); + String agentNodeAddress = checkNotNull(disputeManager.getAgentNodeAddress(dispute)).getFullAddress(); + Contract contract = dispute.getContract(); + String currencyCode = contract.getOfferPayload().getCurrencyCode(); + String amount = formatter.formatCoinWithCode(contract.getTradeAmount()); -// String role = isRefundAgent ? Res.get("shared.refundAgent") : Res.get("shared.mediator"); -// String agentNodeAddress = checkNotNull(disputeManager.getAgentNodeAddress(dispute)).getFullAddress(); -// Contract contract = dispute.getContract(); -// String currencyCode = contract.getOfferPayload().getCurrencyCode(); -// String amount = formatter.formatCoinWithCode(contract.getTradeAmount()); -// -// -// String textToSign = Res.get("disputeSummaryWindow.close.msg", -// DisplayUtils.formatDateTime(disputeResult.getCloseDate()), -// role, -// agentNodeAddress, -// dispute.getShortTradeId(), -// currencyCode, -// amount, -// formatter.formatCoinWithCode(disputeResult.getBuyerPayoutAmount()), -// formatter.formatCoinWithCode(disputeResult.getSellerPayoutAmount()), -// Res.get("disputeSummaryWindow.reason." + reason.name()), -// disputeResult.summaryNotesProperty().get() -// ); -// -// if (reason == DisputeResult.Reason.OPTION_TRADE && -// dispute.getChatMessages().size() > 1 && -// dispute.getChatMessages().get(1).isSystemMessage()) { -// textToSign += "\n" + dispute.getChatMessages().get(1).getMessage() + "\n"; -// } -// -// String summaryText = DisputeSummaryVerification.signAndApply(disputeManager, disputeResult, textToSign); -// -// if (isRefundAgent) { -// summaryText += Res.get("disputeSummaryWindow.close.nextStepsForRefundAgentArbitration"); -// } else { -// summaryText += Res.get("disputeSummaryWindow.close.nextStepsForMediation"); -// } + String textToSign = Res.get("disputeSummaryWindow.close.msg", + DisplayUtils.formatDateTime(disputeResult.getCloseDate()), + role, + agentNodeAddress, + dispute.getShortTradeId(), + currencyCode, + amount, + formatter.formatCoinWithCode(disputeResult.getBuyerPayoutAmount()), + formatter.formatCoinWithCode(disputeResult.getSellerPayoutAmount()), + Res.get("disputeSummaryWindow.reason." + reason.name()), + disputeResult.summaryNotesProperty().get() + ); - String summaryText = Res.get("disputeSummaryWindow.close.msg", - DisplayUtils.formatDateTime(disputeResult.getCloseDate()), - formatter.formatCoinWithCode(disputeResult.getBuyerPayoutAmount()), - formatter.formatCoinWithCode(disputeResult.getSellerPayoutAmount()), - disputeResult.summaryNotesProperty().get()); + if (reason == DisputeResult.Reason.OPTION_TRADE && + dispute.getChatMessages().size() > 1 && + dispute.getChatMessages().get(1).isSystemMessage()) { + textToSign += "\n" + dispute.getChatMessages().get(1).getMessage() + "\n"; + } - if (dispute.isMediationDispute()) { + String summaryText = DisputeSummaryVerification.signAndApply(disputeManager, disputeResult, textToSign); + + if (isRefundAgent) { + summaryText += Res.get("disputeSummaryWindow.close.nextStepsForRefundAgentArbitration"); + } else { summaryText += Res.get("disputeSummaryWindow.close.nextStepsForMediation"); } diff --git a/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeSummaryVerification.java b/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeSummaryVerification.java index 9551b62a5c..8ddec2de70 100644 --- a/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeSummaryVerification.java +++ b/desktop/src/main/java/bisq/desktop/main/support/dispute/DisputeSummaryVerification.java @@ -33,6 +33,7 @@ import bisq.common.crypto.Hash; import bisq.common.crypto.Sig; import bisq.common.util.Utilities; +import java.security.KeyPair; import java.security.PublicKey; import lombok.extern.slf4j.Slf4j; @@ -48,24 +49,23 @@ public class DisputeSummaryVerification { public static String signAndApply(DisputeManager> disputeManager, DisputeResult disputeResult, String textToSign) { - throw new RuntimeException("DisputeSummaryVerification.signAndApply() not implemented"); -// byte[] hash = Hash.getSha256Hash(textToSign); -// KeyPair signatureKeyPair = disputeManager.getSignatureKeyPair(); -// String sigAsHex; -// try { -// byte[] signature = Sig.sign(signatureKeyPair.getPrivate(), hash); -// sigAsHex = Utilities.encodeToHex(signature); -// disputeResult.setArbitratorSignature(signature); -// } catch (CryptoException e) { -// sigAsHex = "Signing failed"; -// } -// -// return Res.get("disputeSummaryWindow.close.msgWithSig", -// textToSign, -// SEPARATOR1, -// sigAsHex, -// SEPARATOR2); + byte[] hash = Hash.getSha256Hash(textToSign); + KeyPair signatureKeyPair = disputeManager.getSignatureKeyPair(); + String sigAsHex; + try { + byte[] signature = Sig.sign(signatureKeyPair.getPrivate(), hash); + sigAsHex = Utilities.encodeToHex(signature); + disputeResult.setArbitratorSignature(signature); + } catch (CryptoException e) { + sigAsHex = "Signing failed"; + } + + return Res.get("disputeSummaryWindow.close.msgWithSig", + textToSign, + SEPARATOR1, + sigAsHex, + SEPARATOR2); } public static String verifySignature(String input, diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 37e210a5a2..5fdc7b3bc8 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -964,7 +964,7 @@ message DisputeResult { bool screen_cast = 7; string summary_notes = 8; ChatMessage chat_message = 9; - reserved 10; // was bytes arbitrator_signature = 10; + bytes arbitrator_signature = 10; int64 buyer_payout_amount = 11; int64 seller_payout_amount = 12; bytes arbitrator_pub_key = 13;