mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-24 06:49:31 -05:00
set mailbox message comparator in trade manager to fix npe
This commit is contained in:
parent
481b6c871a
commit
1a5a754f18
@ -47,14 +47,19 @@ import haveno.core.provider.price.PriceFeedService;
|
||||
import haveno.core.support.dispute.arbitration.arbitrator.Arbitrator;
|
||||
import haveno.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
|
||||
import haveno.core.support.dispute.mediation.mediator.MediatorManager;
|
||||
import haveno.core.support.dispute.messages.DisputeClosedMessage;
|
||||
import haveno.core.support.dispute.messages.DisputeOpenedMessage;
|
||||
import haveno.core.trade.Trade.DisputeState;
|
||||
import haveno.core.trade.Trade.Phase;
|
||||
import haveno.core.trade.failed.FailedTradesManager;
|
||||
import haveno.core.trade.handlers.TradeResultHandler;
|
||||
import haveno.core.trade.messages.DepositRequest;
|
||||
import haveno.core.trade.messages.DepositResponse;
|
||||
import haveno.core.trade.messages.DepositsConfirmedMessage;
|
||||
import haveno.core.trade.messages.InitMultisigRequest;
|
||||
import haveno.core.trade.messages.InitTradeRequest;
|
||||
import haveno.core.trade.messages.PaymentReceivedMessage;
|
||||
import haveno.core.trade.messages.PaymentSentMessage;
|
||||
import haveno.core.trade.messages.SignContractRequest;
|
||||
import haveno.core.trade.messages.SignContractResponse;
|
||||
import haveno.core.trade.messages.TradeMessage;
|
||||
@ -80,6 +85,8 @@ import haveno.network.p2p.DecryptedMessageWithPubKey;
|
||||
import haveno.network.p2p.NodeAddress;
|
||||
import haveno.network.p2p.P2PService;
|
||||
import haveno.network.p2p.SendMailboxMessageListener;
|
||||
import haveno.network.p2p.mailbox.MailboxMessage;
|
||||
import haveno.network.p2p.mailbox.MailboxMessageService;
|
||||
import haveno.network.p2p.network.TorNetworkNode;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.LongProperty;
|
||||
@ -100,6 +107,8 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -153,6 +162,31 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
||||
private final LongProperty numPendingTrades = new SimpleLongProperty();
|
||||
private final ReferralIdService referralIdService;
|
||||
|
||||
// set comparator for processing mailbox messages
|
||||
static {
|
||||
MailboxMessageService.setMailboxMessageComparator(new MailboxMessageComparator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort mailbox messages for processing.
|
||||
*/
|
||||
public static class MailboxMessageComparator implements Comparator<MailboxMessage> {
|
||||
private static List<Class<? extends MailboxMessage>> messageOrder = Arrays.asList(
|
||||
AckMessage.class,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
|
@ -24,14 +24,13 @@ import haveno.common.crypto.PubKeyRing;
|
||||
import haveno.common.handlers.ErrorMessageHandler;
|
||||
import haveno.common.proto.network.NetworkEnvelope;
|
||||
import haveno.common.taskrunner.Task;
|
||||
import haveno.core.support.dispute.messages.DisputeClosedMessage;
|
||||
import haveno.core.support.dispute.messages.DisputeOpenedMessage;
|
||||
import haveno.core.trade.ArbitratorTrade;
|
||||
import haveno.core.trade.BuyerTrade;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.core.trade.SellerTrade;
|
||||
import haveno.core.trade.Trade;
|
||||
import haveno.core.trade.TradeManager;
|
||||
import haveno.core.trade.TradeManager.MailboxMessageComparator;
|
||||
import haveno.core.trade.handlers.TradeResultHandler;
|
||||
import haveno.core.trade.messages.DepositRequest;
|
||||
import haveno.core.trade.messages.DepositResponse;
|
||||
@ -70,11 +69,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
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;
|
||||
|
||||
@Slf4j
|
||||
@ -93,11 +89,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
||||
|
||||
private int reprocessPaymentReceivedMessageCount;
|
||||
|
||||
// set comparator for processing mailbox messages
|
||||
static {
|
||||
MailboxMessageService.setMailboxMessageComparator(new MailboxMessageComparator());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -184,23 +175,6 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
|
||||
.forEach(this::handleMailboxMessage);
|
||||
}
|
||||
|
||||
public static class MailboxMessageComparator implements Comparator<MailboxMessage> {
|
||||
private static List<Class<? extends MailboxMessage>> messageOrder = Arrays.asList(
|
||||
AckMessage.class,
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user