Remove storage from dispute. We do persistence from outside now.

Impl. PersistablePayload
Make openingDate final and contr param
This commit is contained in:
chimp1984 2020-10-01 18:38:32 -05:00
parent 8f38de30e9
commit 158b7a92f9
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3

View file

@ -25,7 +25,7 @@ import bisq.core.trade.Contract;
import bisq.common.crypto.PubKeyRing;
import bisq.common.proto.ProtoUtil;
import bisq.common.proto.network.NetworkPayload;
import bisq.common.storage.Storage;
import bisq.common.proto.persistable.PersistablePayload;
import bisq.common.util.Utilities;
import com.google.protobuf.ByteString;
@ -57,7 +57,7 @@ import javax.annotation.Nullable;
@Slf4j
@EqualsAndHashCode
@Getter
public final class Dispute implements NetworkPayload {
public final class Dispute implements NetworkPayload, PersistablePayload {
private final String tradeId;
private final String id;
private final int traderId;
@ -85,15 +85,14 @@ public final class Dispute implements NetworkPayload {
private final PubKeyRing agentPubKeyRing; // dispute agent
private final boolean isSupportTicket;
private final ObservableList<ChatMessage> chatMessages = FXCollections.observableArrayList();
private BooleanProperty isClosedProperty = new SimpleBooleanProperty();
private final BooleanProperty isClosedProperty = new SimpleBooleanProperty();
// disputeResultProperty.get is Nullable!
private ObjectProperty<DisputeResult> disputeResultProperty = new SimpleObjectProperty<>();
private final ObjectProperty<DisputeResult> disputeResultProperty = new SimpleObjectProperty<>();
private final long openingDate;
@Nullable
@Setter
private String disputePayoutTxId;
private long openingDate;
transient private Storage<? extends DisputeList> storage;
@Setter
// Added v1.2.0
private SupportType supportType;
// Only used at refundAgent so that he knows how the mediator resolved the case
@ -118,7 +117,7 @@ public final class Dispute implements NetworkPayload {
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
public Dispute(Storage<? extends DisputeList> storage,
public Dispute(long openingDate,
String tradeId,
int traderId,
boolean disputeOpenerIsBuyer,
@ -137,51 +136,7 @@ public final class Dispute implements NetworkPayload {
PubKeyRing agentPubKeyRing,
boolean isSupportTicket,
SupportType supportType) {
this(tradeId,
traderId,
disputeOpenerIsBuyer,
disputeOpenerIsMaker,
traderPubKeyRing,
tradeDate,
contract,
contractHash,
depositTxSerialized,
payoutTxSerialized,
depositTxId,
payoutTxId,
contractAsJson,
makerContractSignature,
takerContractSignature,
agentPubKeyRing,
isSupportTicket,
supportType);
this.storage = storage;
openingDate = new Date().getTime();
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
public Dispute(String tradeId,
int traderId,
boolean disputeOpenerIsBuyer,
boolean disputeOpenerIsMaker,
PubKeyRing traderPubKeyRing,
long tradeDate,
Contract contract,
@Nullable byte[] contractHash,
@Nullable byte[] depositTxSerialized,
@Nullable byte[] payoutTxSerialized,
@Nullable String depositTxId,
@Nullable String payoutTxId,
String contractAsJson,
@Nullable String makerContractSignature,
@Nullable String takerContractSignature,
PubKeyRing agentPubKeyRing,
boolean isSupportTicket,
SupportType supportType) {
this.openingDate = openingDate;
this.tradeId = tradeId;
this.traderId = traderId;
this.disputeOpenerIsBuyer = disputeOpenerIsBuyer;
@ -205,6 +160,11 @@ public final class Dispute implements NetworkPayload {
uid = UUID.randomUUID().toString();
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public protobuf.Dispute toProtoMessage() {
// Needed to avoid ConcurrentModificationException
@ -244,7 +204,8 @@ public final class Dispute implements NetworkPayload {
}
public static Dispute fromProto(protobuf.Dispute proto, CoreProtoResolver coreProtoResolver) {
Dispute dispute = new Dispute(proto.getTradeId(),
Dispute dispute = new Dispute(proto.getOpeningDate(),
proto.getTradeId(),
proto.getTraderId(),
proto.getDisputeOpenerIsBuyer(),
proto.getDisputeOpenerIsMaker(),
@ -267,7 +228,6 @@ public final class Dispute implements NetworkPayload {
.map(ChatMessage::fromPayloadProto)
.collect(Collectors.toList()));
dispute.openingDate = proto.getOpeningDate();
dispute.isClosedProperty.set(proto.getIsClosed());
if (proto.hasDisputeResult())
dispute.disputeResultProperty.set(DisputeResult.fromProto(proto.getDisputeResult()));
@ -299,7 +259,6 @@ public final class Dispute implements NetworkPayload {
public void addAndPersistChatMessage(ChatMessage chatMessage) {
if (!chatMessages.contains(chatMessage)) {
chatMessages.add(chatMessage);
storage.queueUpForSave();
} else {
log.error("disputeDirectMessage already exists");
}
@ -310,35 +269,14 @@ public final class Dispute implements NetworkPayload {
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
// In case we get the object via the network storage is not set as its transient, so we need to set it.
public void setStorage(Storage<? extends DisputeList> storage) {
this.storage = storage;
}
public void setIsClosed(boolean isClosed) {
boolean changed = this.isClosedProperty.get() != isClosed;
this.isClosedProperty.set(isClosed);
if (changed)
storage.queueUpForSave();
}
public void setDisputeResult(DisputeResult disputeResult) {
boolean changed = disputeResultProperty.get() == null || !disputeResultProperty.get().equals(disputeResult);
disputeResultProperty.set(disputeResult);
if (changed)
storage.queueUpForSave();
}
public void setDisputePayoutTxId(String disputePayoutTxId) {
boolean changed = this.disputePayoutTxId == null || !this.disputePayoutTxId.equals(disputePayoutTxId);
this.disputePayoutTxId = disputePayoutTxId;
if (changed)
storage.queueUpForSave();
}
public void setSupportType(SupportType supportType) {
this.supportType = supportType;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
@ -396,7 +334,6 @@ public final class Dispute implements NetworkPayload {
",\n disputeResultProperty=" + disputeResultProperty +
",\n disputePayoutTxId='" + disputePayoutTxId + '\'' +
",\n openingDate=" + openingDate +
",\n storage=" + storage +
",\n supportType=" + supportType +
",\n mediatorsDisputeResult='" + mediatorsDisputeResult + '\'' +
",\n delayedPayoutTxId='" + delayedPayoutTxId + '\'' +