restore dispute summary message

This commit is contained in:
woodser 2021-11-10 04:47:37 -05:00
parent 673aa3a437
commit cd108387a2
5 changed files with 57 additions and 61 deletions

View File

@ -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 +

View File

@ -213,6 +213,7 @@ public class AccountAgeWitnessServiceTest {
null,
null,
null,
null,
100000,
0,
null,

View File

@ -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<DisputeSummaryWindow> {
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");
}

View File

@ -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<? extends DisputeList<Dispute>> 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,

View File

@ -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;