Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTP: improve backwards compatibility for mediation #3439

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions core/src/main/java/bisq/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,17 @@ public void onFault(String errorMessage) {
private void maybeUpdatePersistedOffers() {
// We need to clone to avoid ConcurrentModificationException
ArrayList<OpenOffer> openOffersClone = new ArrayList<>(openOffers.getList());
openOffersClone.forEach(openOffer -> {
Offer originalOffer = openOffer.getOffer();
openOffersClone.forEach(originalOpenOffer -> {
Offer originalOffer = originalOpenOffer.getOffer();

OfferPayload originalOfferPayload = originalOffer.getOfferPayload();
// We added CAPABILITIES with entry for Capability.MEDIATION in v1.1.6 and want to rewrite a
// persisted offer after the user has updated to 1.1.6 so their offer will be accepted by the network.
// We added CAPABILITIES with entry for Capability.MEDIATION in v1.1.6 and
// Capability.REFUND_AGENT in v1.2.0 and want to rewrite a
// persisted offer after the user has updated to 1.2.0 so their offer will be accepted by the network.

if (originalOfferPayload.getProtocolVersion() < Version.TRADE_PROTOCOL_VERSION ||
!OfferRestrictions.hasOfferMandatoryCapability(originalOffer, Capability.MEDIATION)) {
!OfferRestrictions.hasOfferMandatoryCapability(originalOffer, Capability.MEDIATION) ||
!OfferRestrictions.hasOfferMandatoryCapability(originalOffer, Capability.REFUND_AGENT)) {
// We rewrite our offer with the additional capabilities entry

Map<String, String> originalExtraDataMap = originalOfferPayload.getExtraDataMap();
Expand Down Expand Up @@ -775,15 +777,15 @@ private void maybeUpdatePersistedOffers() {
updatedExtraDataMap,
protocolVersion);

// Save states from original data to use the for updated
// Save states from original data to use for the updated
Offer.State originalOfferState = originalOffer.getState();
OpenOffer.State originalOpenOfferState = openOffer.getState();
OpenOffer.State originalOpenOfferState = originalOpenOffer.getState();

// remove old offer
originalOffer.setState(Offer.State.REMOVED);
openOffer.setState(OpenOffer.State.CANCELED);
openOffer.setStorage(openOfferTradableListStorage);
openOffers.remove(openOffer);
originalOpenOffer.setState(OpenOffer.State.CANCELED);
originalOpenOffer.setStorage(openOfferTradableListStorage);
openOffers.remove(originalOpenOffer);

// Create new Offer
Offer updatedOffer = new Offer(updatedPayload);
Expand All @@ -795,7 +797,7 @@ private void maybeUpdatePersistedOffers() {
updatedOpenOffer.setStorage(openOfferTradableListStorage);
openOffers.add(updatedOpenOffer);

log.info("Converted offer to support new Capability.MEDIATION capability. id={}", originalOffer.getId());
log.info("Converted offer to support new Capability.MEDIATION and Capability.REFUND_AGENT capability. id={}", originalOffer.getId());
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/bisq/core/support/dispute/Dispute.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ public void setDisputePayoutTxId(String disputePayoutTxId) {
storage.queueUpForSave();
}

public void setSupportType(SupportType supportType) {
this.supportType = supportType;
}

///////////////////////////////////////////////////////////////////////////////////////////
// Getters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ protected void onOpenNewDisputeMessage(OpenNewDisputeMessage openNewDisputeMessa

String errorMessage = null;
Dispute dispute = openNewDisputeMessage.getDispute();

// Disputes from clients < 1.2.0 always have support type ARBITRATION in dispute as the field didn't exist before
dispute.setSupportType(openNewDisputeMessage.getSupportType());

dispute.setStorage(disputeListService.getStorage());
Contract contractFromOpener = dispute.getContract();
PubKeyRing peersPubKeyRing = dispute.isDisputeOpenerIsBuyer() ? contractFromOpener.getSellerPubKeyRing() : contractFromOpener.getBuyerPubKeyRing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.support.dispute.arbitration;

import bisq.core.proto.CoreProtoResolver;
import bisq.core.support.SupportType;
import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.DisputeList;

Expand All @@ -33,6 +34,8 @@
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;

@Slf4j
@ToString
/*
Expand Down Expand Up @@ -67,6 +70,9 @@ private ArbitrationDisputeList(Storage<ArbitrationDisputeList> storage, List<Dis

@Override
public Message toProtoMessage() {

list.forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.ARBITRATION), "Support type has to be ARBITRATION"));

return protobuf.PersistableEnvelope.newBuilder().setArbitrationDisputeList(protobuf.ArbitrationDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list)))).build();
}
Expand All @@ -77,7 +83,11 @@ public static ArbitrationDisputeList fromProto(protobuf.ArbitrationDisputeList p
List<Dispute> list = proto.getDisputeList().stream()
.map(disputeProto -> Dispute.fromProto(disputeProto, coreProtoResolver))
.collect(Collectors.toList());
list.forEach(e -> e.setStorage(storage));

list.forEach(e -> {
checkArgument(e.getSupportType().equals(SupportType.ARBITRATION), "Support type has to be ARBITRATION");
e.setStorage(storage);
});
return new ArbitrationDisputeList(storage, list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.support.dispute.mediation;

import bisq.core.proto.CoreProtoResolver;
import bisq.core.support.SupportType;
import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.DisputeList;

Expand All @@ -33,6 +34,8 @@
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;

@Slf4j
@ToString
/*
Expand Down Expand Up @@ -66,6 +69,9 @@ private MediationDisputeList(Storage<MediationDisputeList> storage, List<Dispute

@Override
public Message toProtoMessage() {

list.forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.MEDIATION), "Support type has to be MEDIATION"));

return protobuf.PersistableEnvelope.newBuilder().setMediationDisputeList(protobuf.MediationDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list)))).build();
}
Expand All @@ -76,7 +82,11 @@ public static MediationDisputeList fromProto(protobuf.MediationDisputeList proto
List<Dispute> list = proto.getDisputeList().stream()
.map(disputeProto -> Dispute.fromProto(disputeProto, coreProtoResolver))
.collect(Collectors.toList());
list.forEach(e -> e.setStorage(storage));

list.forEach(e -> {
checkArgument(e.getSupportType().equals(SupportType.MEDIATION), "Support type has to be MEDIATION");
e.setStorage(storage);
});
return new MediationDisputeList(storage, list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.support.dispute.refund;

import bisq.core.proto.CoreProtoResolver;
import bisq.core.support.SupportType;
import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.DisputeList;

Expand All @@ -33,6 +34,8 @@
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;

@Slf4j
@ToString
/*
Expand Down Expand Up @@ -67,6 +70,9 @@ private RefundDisputeList(Storage<RefundDisputeList> storage, List<Dispute> list

@Override
public Message toProtoMessage() {

list.forEach(dispute -> checkArgument(dispute.getSupportType().equals(SupportType.REFUND), "Support type has to be REFUND"));

return protobuf.PersistableEnvelope.newBuilder().setRefundDisputeList(protobuf.RefundDisputeList.newBuilder()
.addAllDispute(ProtoUtil.collectionToProto(new ArrayList<>(list)))).build();
}
Expand All @@ -77,7 +83,11 @@ public static RefundDisputeList fromProto(protobuf.RefundDisputeList proto,
List<Dispute> list = proto.getDisputeList().stream()
.map(disputeProto -> Dispute.fromProto(disputeProto, coreProtoResolver))
.collect(Collectors.toList());
list.forEach(e -> e.setStorage(storage));

list.forEach(e -> {
checkArgument(e.getSupportType().equals(SupportType.REFUND), "Support type has to be REFUND");
e.setStorage(storage);
});
return new RefundDisputeList(storage, list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public abstract class DisputeView extends ActivatableView<VBox, Void> {
protected final KeyRing keyRing;
private final TradeManager tradeManager;
protected final BSFormatter formatter;
private final DisputeSummaryWindow disputeSummaryWindow;
protected final DisputeSummaryWindow disputeSummaryWindow;
private final PrivateNotificationManager privateNotificationManager;
private final ContractWindow contractWindow;
private final TradeDetailsWindow tradeDetailsWindow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ protected SupportType getType() {
protected DisputeSession getConcreteDisputeChatSession(Dispute dispute) {
return new MediationSession(dispute, disputeManager.isTrader(dispute));
}

@Override
protected void onCloseDispute(Dispute dispute) {
disputeSummaryWindow.onFinalizeDispute(() -> chatView.removeInputBox())
.show(dispute);
}
}