mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 14:42:37 +01:00
Add comments, cleanup, fix wrong param name
This commit is contained in:
parent
cb673764df
commit
8e3a3514a3
5 changed files with 71 additions and 64 deletions
|
@ -96,10 +96,12 @@ public class DisputeChatSession extends ChatSession {
|
|||
return !dispute.isClosed();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Not dependent on selected dispute
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NodeAddress getPeerNodeAddress(DisputeCommunicationMessage message) {
|
||||
Optional<Dispute> disputeOptional = disputeManager.findDispute(message.getTradeId(), message.getTraderId());
|
||||
|
@ -111,6 +113,7 @@ public class DisputeChatSession extends ChatSession {
|
|||
return disputeManager.getNodeAddressPubKeyRingTuple(disputeOptional.get()).first;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PubKeyRing getPeerPubKeyRing(DisputeCommunicationMessage message) {
|
||||
Optional<Dispute> disputeOptional = disputeManager.findDispute(message.getTradeId(), message.getTraderId());
|
||||
|
@ -128,23 +131,23 @@ public class DisputeChatSession extends ChatSession {
|
|||
log.info("Received {} with tradeId {} and uid {}",
|
||||
message.getClass().getSimpleName(), message.getTradeId(), message.getUid());
|
||||
|
||||
if (message instanceof OpenNewDisputeMessage)
|
||||
if (message instanceof OpenNewDisputeMessage) {
|
||||
disputeManager.onOpenNewDisputeMessage((OpenNewDisputeMessage) message);
|
||||
else if (message instanceof PeerOpenedDisputeMessage)
|
||||
} else if (message instanceof PeerOpenedDisputeMessage) {
|
||||
disputeManager.onPeerOpenedDisputeMessage((PeerOpenedDisputeMessage) message);
|
||||
else if (message instanceof DisputeCommunicationMessage) {
|
||||
if (((DisputeCommunicationMessage)message).getType() != DisputeCommunicationMessage.Type.DISPUTE){
|
||||
log.debug("Ignore non distpute type communication message");
|
||||
} else if (message instanceof DisputeCommunicationMessage) {
|
||||
if (((DisputeCommunicationMessage) message).getType() != DisputeCommunicationMessage.Type.DISPUTE) {
|
||||
log.debug("Ignore non dispute type communication message");
|
||||
return;
|
||||
}
|
||||
disputeManager.getChatManager().onDisputeDirectMessage((DisputeCommunicationMessage) message);
|
||||
}
|
||||
else if (message instanceof DisputeResultMessage)
|
||||
} else if (message instanceof DisputeResultMessage) {
|
||||
disputeManager.onDisputeResultMessage((DisputeResultMessage) message);
|
||||
else if (message instanceof PeerPublishedDisputePayoutTxMessage)
|
||||
} else if (message instanceof PeerPublishedDisputePayoutTxMessage) {
|
||||
disputeManager.onDisputedPayoutTxMessage((PeerPublishedDisputePayoutTxMessage) message);
|
||||
else
|
||||
} else {
|
||||
log.warn("Unsupported message at dispatchMessage.\nmessage=" + message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -162,14 +165,13 @@ public class DisputeChatSession extends ChatSession {
|
|||
@Override
|
||||
public void storeDisputeCommunicationMessage(DisputeCommunicationMessage message) {
|
||||
Optional<Dispute> disputeOptional = disputeManager.findDispute(message.getTradeId(), message.getTraderId());
|
||||
|
||||
if (disputeOptional.isPresent()) {
|
||||
if (disputeOptional.get().getDisputeCommunicationMessages().stream()
|
||||
.noneMatch(m -> m.getUid().equals(message.getUid())))
|
||||
if (disputeOptional.get().getDisputeCommunicationMessages().stream().noneMatch(m -> m.getUid().equals(message.getUid()))) {
|
||||
disputeOptional.get().addDisputeCommunicationMessage(message);
|
||||
else
|
||||
} else {
|
||||
log.warn("We got a disputeCommunicationMessage what we have already stored. UId = {} TradeId = {}",
|
||||
message.getUid(), message.getTradeId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,8 +70,6 @@ import javafx.beans.property.SimpleIntegerProperty;
|
|||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -103,8 +101,6 @@ public class DisputeManager implements PersistedDataHost {
|
|||
@Getter
|
||||
private DisputeList disputes;
|
||||
private final String disputeInfo;
|
||||
// private final CopyOnWriteArraySet<DecryptedMessageWithPubKey> decryptedMailboxMessageWithPubKeys = new CopyOnWriteArraySet<>();
|
||||
// private final CopyOnWriteArraySet<DecryptedMessageWithPubKey> decryptedDirectMessageWithPubKeys = new CopyOnWriteArraySet<>();
|
||||
private final Map<String, Dispute> openDisputes;
|
||||
private final Map<String, Dispute> closedDisputes;
|
||||
private final Map<String, Timer> delayMsgMap = new HashMap<>();
|
||||
|
@ -632,6 +628,7 @@ public class DisputeManager implements PersistedDataHost {
|
|||
|
||||
chatManager.sendAckMessage(peerOpenedDisputeMessage, dispute.getArbitratorPubKeyRing(), errorMessage == null, errorMessage);
|
||||
}
|
||||
|
||||
// We get that message at both peers. The dispute object is in context of the trader
|
||||
public void onDisputeResultMessage(DisputeResultMessage disputeResultMessage) {
|
||||
String errorMessage = null;
|
||||
|
|
|
@ -78,6 +78,7 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
|
|||
void onMessageStateChanged();
|
||||
}
|
||||
|
||||
// Added with v1.1.6. Old clients will not have set that field and we fall back to entry 0 which is DISPUTE.
|
||||
private final DisputeCommunicationMessage.Type type;
|
||||
private final String tradeId;
|
||||
private final int traderId;
|
||||
|
@ -182,40 +183,44 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
|
|||
.build();
|
||||
}
|
||||
|
||||
public static DisputeCommunicationMessage fromProto(protobuf.DisputeCommunicationMessage protobuf,
|
||||
public static DisputeCommunicationMessage fromProto(protobuf.DisputeCommunicationMessage proto,
|
||||
int messageVersion) {
|
||||
// If we get a msg from an old client type will be ordinal 0 which is the dispute entry and as we only added
|
||||
// the trade case it is the desired behaviour.
|
||||
DisputeCommunicationMessage.Type type = DisputeCommunicationMessage.Type.fromProto(proto.getType());
|
||||
final DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(
|
||||
DisputeCommunicationMessage.Type.fromProto(protobuf.getType()),
|
||||
protobuf.getTradeId(),
|
||||
protobuf.getTraderId(),
|
||||
protobuf.getSenderIsTrader(),
|
||||
protobuf.getMessage(),
|
||||
new ArrayList<>(protobuf.getAttachmentsList().stream().map(Attachment::fromProto).collect(Collectors.toList())),
|
||||
NodeAddress.fromProto(protobuf.getSenderNodeAddress()),
|
||||
protobuf.getDate(),
|
||||
protobuf.getArrived(),
|
||||
protobuf.getStoredInMailbox(),
|
||||
protobuf.getUid(),
|
||||
type,
|
||||
proto.getTradeId(),
|
||||
proto.getTraderId(),
|
||||
proto.getSenderIsTrader(),
|
||||
proto.getMessage(),
|
||||
new ArrayList<>(proto.getAttachmentsList().stream().map(Attachment::fromProto).collect(Collectors.toList())),
|
||||
NodeAddress.fromProto(proto.getSenderNodeAddress()),
|
||||
proto.getDate(),
|
||||
proto.getArrived(),
|
||||
proto.getStoredInMailbox(),
|
||||
proto.getUid(),
|
||||
messageVersion,
|
||||
protobuf.getAcknowledged(),
|
||||
protobuf.getSendMessageError().isEmpty() ? null : protobuf.getSendMessageError(),
|
||||
protobuf.getAckError().isEmpty() ? null : protobuf.getAckError());
|
||||
disputeCommunicationMessage.setSystemMessage(protobuf.getIsSystemMessage());
|
||||
proto.getAcknowledged(),
|
||||
proto.getSendMessageError().isEmpty() ? null : proto.getSendMessageError(),
|
||||
proto.getAckError().isEmpty() ? null : proto.getAckError());
|
||||
disputeCommunicationMessage.setSystemMessage(proto.getIsSystemMessage());
|
||||
return disputeCommunicationMessage;
|
||||
}
|
||||
|
||||
public static DisputeCommunicationMessage fromPayloadProto(protobuf.DisputeCommunicationMessage protobuf) {
|
||||
public static DisputeCommunicationMessage fromPayloadProto(protobuf.DisputeCommunicationMessage proto) {
|
||||
// We have the case that an envelope got wrapped into a payload.
|
||||
// We don't check the message version here as it was checked in the carrier envelope already (in connection class)
|
||||
// Payloads don't have a message version and are also used for persistence
|
||||
// We set the value to -1 to indicate it is set but irrelevant
|
||||
return fromProto(protobuf, -1);
|
||||
return fromProto(proto, -1);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void addAllAttachments(List<Attachment> attachments) {
|
||||
this.attachments.addAll(attachments);
|
||||
}
|
||||
|
@ -280,8 +285,12 @@ public final class DisputeCommunicationMessage extends DisputeMessage {
|
|||
}
|
||||
|
||||
private void notifyChangeListener() {
|
||||
if (listener != null && listener.get() != null)
|
||||
listener.get().onMessageStateChanged();
|
||||
if (listener != null) {
|
||||
Listener listener = this.listener.get();
|
||||
if (listener != null) {
|
||||
listener.onMessageStateChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -461,30 +461,30 @@ public abstract class Trade implements Tradable, Model {
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
public static Trade fromProto(Trade trade, protobuf.Trade protobuf, CoreProtoResolver coreProtoResolver) {
|
||||
trade.setTakeOfferDate(protobuf.getTakeOfferDate());
|
||||
trade.setProcessModel(ProcessModel.fromProto(protobuf.getProcessModel(), coreProtoResolver));
|
||||
trade.setState(State.fromProto(protobuf.getState()));
|
||||
trade.setDisputeState(DisputeState.fromProto(protobuf.getDisputeState()));
|
||||
trade.setTradePeriodState(TradePeriodState.fromProto(protobuf.getTradePeriodState()));
|
||||
trade.setTakerFeeTxId(ProtoUtil.stringOrNullFromProto(protobuf.getTakerFeeTxId()));
|
||||
trade.setDepositTxId(ProtoUtil.stringOrNullFromProto(protobuf.getDepositTxId()));
|
||||
trade.setPayoutTxId(ProtoUtil.stringOrNullFromProto(protobuf.getPayoutTxId()));
|
||||
trade.setContract(protobuf.hasContract() ? Contract.fromProto(protobuf.getContract(), coreProtoResolver) : null);
|
||||
trade.setContractAsJson(ProtoUtil.stringOrNullFromProto(protobuf.getContractAsJson()));
|
||||
trade.setContractHash(ProtoUtil.byteArrayOrNullFromProto(protobuf.getContractHash()));
|
||||
trade.setTakerContractSignature(ProtoUtil.stringOrNullFromProto(protobuf.getTakerContractSignature()));
|
||||
trade.setMakerContractSignature(ProtoUtil.stringOrNullFromProto(protobuf.getMakerContractSignature()));
|
||||
trade.setArbitratorNodeAddress(protobuf.hasArbitratorNodeAddress() ? NodeAddress.fromProto(protobuf.getArbitratorNodeAddress()) : null);
|
||||
trade.setMediatorNodeAddress(protobuf.hasMediatorNodeAddress() ? NodeAddress.fromProto(protobuf.getMediatorNodeAddress()) : null);
|
||||
trade.setArbitratorBtcPubKey(ProtoUtil.byteArrayOrNullFromProto(protobuf.getArbitratorBtcPubKey()));
|
||||
trade.setTakerPaymentAccountId(ProtoUtil.stringOrNullFromProto(protobuf.getTakerPaymentAccountId()));
|
||||
trade.setErrorMessage(ProtoUtil.stringOrNullFromProto(protobuf.getErrorMessage()));
|
||||
trade.setArbitratorPubKeyRing(protobuf.hasArbitratorPubKeyRing() ? PubKeyRing.fromProto(protobuf.getArbitratorPubKeyRing()) : null);
|
||||
trade.setMediatorPubKeyRing(protobuf.hasMediatorPubKeyRing() ? PubKeyRing.fromProto(protobuf.getMediatorPubKeyRing()) : null);
|
||||
trade.setCounterCurrencyTxId(protobuf.getCounterCurrencyTxId().isEmpty() ? null : protobuf.getCounterCurrencyTxId());
|
||||
public static Trade fromProto(Trade trade, protobuf.Trade proto, CoreProtoResolver coreProtoResolver) {
|
||||
trade.setTakeOfferDate(proto.getTakeOfferDate());
|
||||
trade.setProcessModel(ProcessModel.fromProto(proto.getProcessModel(), coreProtoResolver));
|
||||
trade.setState(State.fromProto(proto.getState()));
|
||||
trade.setDisputeState(DisputeState.fromProto(proto.getDisputeState()));
|
||||
trade.setTradePeriodState(TradePeriodState.fromProto(proto.getTradePeriodState()));
|
||||
trade.setTakerFeeTxId(ProtoUtil.stringOrNullFromProto(proto.getTakerFeeTxId()));
|
||||
trade.setDepositTxId(ProtoUtil.stringOrNullFromProto(proto.getDepositTxId()));
|
||||
trade.setPayoutTxId(ProtoUtil.stringOrNullFromProto(proto.getPayoutTxId()));
|
||||
trade.setContract(proto.hasContract() ? Contract.fromProto(proto.getContract(), coreProtoResolver) : null);
|
||||
trade.setContractAsJson(ProtoUtil.stringOrNullFromProto(proto.getContractAsJson()));
|
||||
trade.setContractHash(ProtoUtil.byteArrayOrNullFromProto(proto.getContractHash()));
|
||||
trade.setTakerContractSignature(ProtoUtil.stringOrNullFromProto(proto.getTakerContractSignature()));
|
||||
trade.setMakerContractSignature(ProtoUtil.stringOrNullFromProto(proto.getMakerContractSignature()));
|
||||
trade.setArbitratorNodeAddress(proto.hasArbitratorNodeAddress() ? NodeAddress.fromProto(proto.getArbitratorNodeAddress()) : null);
|
||||
trade.setMediatorNodeAddress(proto.hasMediatorNodeAddress() ? NodeAddress.fromProto(proto.getMediatorNodeAddress()) : null);
|
||||
trade.setArbitratorBtcPubKey(ProtoUtil.byteArrayOrNullFromProto(proto.getArbitratorBtcPubKey()));
|
||||
trade.setTakerPaymentAccountId(ProtoUtil.stringOrNullFromProto(proto.getTakerPaymentAccountId()));
|
||||
trade.setErrorMessage(ProtoUtil.stringOrNullFromProto(proto.getErrorMessage()));
|
||||
trade.setArbitratorPubKeyRing(proto.hasArbitratorPubKeyRing() ? PubKeyRing.fromProto(proto.getArbitratorPubKeyRing()) : null);
|
||||
trade.setMediatorPubKeyRing(proto.hasMediatorPubKeyRing() ? PubKeyRing.fromProto(proto.getMediatorPubKeyRing()) : null);
|
||||
trade.setCounterCurrencyTxId(proto.getCounterCurrencyTxId().isEmpty() ? null : proto.getCounterCurrencyTxId());
|
||||
|
||||
trade.communicationMessages.addAll(protobuf.getCommunicationMessagesList().stream()
|
||||
trade.communicationMessages.addAll(proto.getCommunicationMessagesList().stream()
|
||||
.map(DisputeCommunicationMessage::fromPayloadProto)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
|
|
|
@ -132,14 +132,14 @@ public class TradeChatSession extends ChatSession {
|
|||
log.info("Received {} with tradeId {} and uid {}",
|
||||
message.getClass().getSimpleName(), message.getTradeId(), message.getUid());
|
||||
if (message instanceof DisputeCommunicationMessage) {
|
||||
if (((DisputeCommunicationMessage)message).getType() != DisputeCommunicationMessage.Type.TRADE){
|
||||
if (((DisputeCommunicationMessage) message).getType() != DisputeCommunicationMessage.Type.TRADE) {
|
||||
log.debug("Ignore non trade type communication message");
|
||||
return;
|
||||
}
|
||||
chatManager.onDisputeDirectMessage((DisputeCommunicationMessage) message);
|
||||
}
|
||||
else
|
||||
} else {
|
||||
log.warn("Unsupported message at dispatchMessage.\nmessage=" + message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -166,5 +166,4 @@ public class TradeChatSession extends ChatSession {
|
|||
message.getUid(), message.getTradeId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue