diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index b69aa7ae..62a22644 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -381,7 +381,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi } private void initTradeAndProtocol(Trade trade, TradeProtocol tradeProtocol) { - tradeProtocol.initialize(processModelServiceProvider, this, trade.getOffer()); + tradeProtocol.initialize(processModelServiceProvider, this); requestPersistence(); // TODO requesting persistence twice with initPersistedTrade() } diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerProtocol.java index 2fe57c5a..7e0f325c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerProtocol.java @@ -19,7 +19,6 @@ package bisq.core.trade.protocol; import bisq.core.trade.SellerTrade; import bisq.core.trade.Trade; -import bisq.core.trade.messages.PaymentSentMessage; import bisq.core.trade.messages.SignContractResponse; import bisq.core.trade.messages.TradeMessage; import bisq.core.trade.protocol.tasks.ApplyFilter; diff --git a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java index 5dad52e3..1e744041 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TradeProtocol.java @@ -17,7 +17,8 @@ package bisq.core.trade.protocol; -import bisq.core.offer.Offer; +import bisq.core.support.dispute.messages.DisputeClosedMessage; +import bisq.core.support.dispute.messages.DisputeOpenedMessage; import bisq.core.trade.ArbitratorTrade; import bisq.core.trade.BuyerTrade; import bisq.core.trade.Trade; @@ -63,8 +64,11 @@ import bisq.common.handlers.ErrorMessageHandler; import bisq.common.proto.network.NetworkEnvelope; import bisq.common.taskrunner.Task; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; +import java.util.List; import java.util.concurrent.CountDownLatch; import lombok.extern.slf4j.Slf4j; @@ -168,9 +172,26 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D .filter(this::isMyMessage) .filter(e -> e instanceof MailboxMessage) .map(e -> (MailboxMessage) e) + .sorted(new MailboxMessageComparator()) .forEach(this::handleMailboxMessage); } + private static class MailboxMessageComparator implements Comparator { + private static List> messageOrder = Arrays.asList( + DepositsConfirmedMessage.class, + PaymentSentMessage.class, + PaymentReceivedMessage.class, + DisputeOpenedMessage.class, + DisputeClosedMessage.class); + + @Override + public int compare(MailboxMessage m1, MailboxMessage m2) { + int idx1 = messageOrder.indexOf(m1.getClass()); + int idx2 = messageOrder.indexOf(m2.getClass()); + return idx1 - idx2; + } + } + private void handleMailboxMessage(MailboxMessage mailboxMessage) { if (mailboxMessage instanceof TradeMessage) { TradeMessage tradeMessage = (TradeMessage) mailboxMessage; @@ -209,8 +230,8 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D public abstract Class[] getDepositsConfirmedTasks(); - public void initialize(ProcessModelServiceProvider serviceProvider, TradeManager tradeManager, Offer offer) { - processModel.applyTransient(serviceProvider, tradeManager, offer); + public void initialize(ProcessModelServiceProvider serviceProvider, TradeManager tradeManager) { + processModel.applyTransient(serviceProvider, tradeManager, trade.getOffer()); onInitialized(); }