From ff52c43d4f19c3f5f66a07625950c8e08fca6ca3 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Tue, 9 Jan 2024 12:56:30 -0600 Subject: [PATCH] Allow mediation of failed and closed trades. --- .../java/bisq/core/api/CoreTradesService.java | 2 +- .../core/support/dispute/DisputeManager.java | 38 ++++++++++++++----- .../arbitration/ArbitrationManager.java | 4 +- .../dispute/mediation/MediationManager.java | 4 +- .../support/dispute/refund/RefundManager.java | 5 ++- .../java/bisq/core/trade/TradeManager.java | 2 +- .../failedtrades/FailedTradesDataModel.java | 2 +- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/bisq/core/api/CoreTradesService.java b/core/src/main/java/bisq/core/api/CoreTradesService.java index 17f10803565..8dc40e78377 100644 --- a/core/src/main/java/bisq/core/api/CoreTradesService.java +++ b/core/src/main/java/bisq/core/api/CoreTradesService.java @@ -371,7 +371,7 @@ void unFailTrade(String tradeId) { failedTradesManager.getTradeById(tradeId).ifPresentOrElse(failedTrade -> { verifyCanUnfailTrade(failedTrade); failedTradesManager.removeTrade(failedTrade); - tradeManager.addFailedTradeToPendingTrades(failedTrade); + tradeManager.addTradeToPendingTrades(failedTrade); log.info("Failed trade {} changed to open trade.", tradeId); }, () -> { throw new NotFoundException(format("failed trade '%s' not found", tradeId)); diff --git a/core/src/main/java/bisq/core/support/dispute/DisputeManager.java b/core/src/main/java/bisq/core/support/dispute/DisputeManager.java index fefb2db9b91..8e1e43be872 100644 --- a/core/src/main/java/bisq/core/support/dispute/DisputeManager.java +++ b/core/src/main/java/bisq/core/support/dispute/DisputeManager.java @@ -38,6 +38,7 @@ import bisq.core.support.messages.ChatMessage; import bisq.core.trade.ClosedTradableManager; import bisq.core.trade.TradeManager; +import bisq.core.trade.bisq_v1.FailedTradesManager; import bisq.core.trade.bisq_v1.TradeDataValidation; import bisq.core.trade.model.bisq_v1.Contract; import bisq.core.trade.model.bisq_v1.Trade; @@ -91,6 +92,7 @@ public abstract class DisputeManager> extends Sup protected final BtcWalletService btcWalletService; protected final TradeManager tradeManager; protected final ClosedTradableManager closedTradableManager; + private final FailedTradesManager failedTradesManager; protected final OpenOfferManager openOfferManager; protected final PubKeyRing pubKeyRing; protected final DisputeListService disputeListService; @@ -116,6 +118,7 @@ public DisputeManager(P2PService p2PService, WalletsSetup walletsSetup, TradeManager tradeManager, ClosedTradableManager closedTradableManager, + FailedTradesManager failedTradesManager, OpenOfferManager openOfferManager, DaoFacade daoFacade, KeyRing keyRing, @@ -128,6 +131,7 @@ public DisputeManager(P2PService p2PService, this.btcWalletService = btcWalletService; this.tradeManager = tradeManager; this.closedTradableManager = closedTradableManager; + this.failedTradesManager = failedTradesManager; this.openOfferManager = openOfferManager; this.daoFacade = daoFacade; this.pubKeyRing = keyRing.getPubKeyRing(); @@ -447,21 +451,37 @@ protected void onOpenNewDisputeMessage(OpenNewDisputeMessage openNewDisputeMessa // Not-dispute-requester receives that msg from dispute agent protected void onPeerOpenedDisputeMessage(PeerOpenedDisputeMessage peerOpenedDisputeMessage) { + Dispute dispute = peerOpenedDisputeMessage.getDispute(); + tradeManager.getTradeById(dispute.getTradeId()).ifPresentOrElse( + trade -> peerOpenedDisputeForTrade(peerOpenedDisputeMessage, dispute, trade), + () -> closedTradableManager.getTradableById(dispute.getTradeId()).ifPresentOrElse( + closedTradable -> newDisputeRevertsClosedTrade(peerOpenedDisputeMessage, dispute, (Trade)closedTradable), + () -> failedTradesManager.getTradeById(dispute.getTradeId()).ifPresent( + trade -> newDisputeRevertsFailedTrade(peerOpenedDisputeMessage, dispute, trade)))); + } + + private void newDisputeRevertsFailedTrade(PeerOpenedDisputeMessage peerOpenedDisputeMessage, Dispute dispute, Trade trade) { + log.info("Peer dispute ticket received, reverting failed trade {} to pending", trade.getShortId()); + failedTradesManager.removeTrade(trade); + tradeManager.addTradeToPendingTrades(trade); + peerOpenedDisputeForTrade(peerOpenedDisputeMessage, dispute, trade); + } + + private void newDisputeRevertsClosedTrade(PeerOpenedDisputeMessage peerOpenedDisputeMessage, Dispute dispute, Trade trade) { + log.info("Peer dispute ticket received, reverting closed trade {} to pending", trade.getShortId()); + closedTradableManager.remove(trade); + tradeManager.addTradeToPendingTrades(trade); + peerOpenedDisputeForTrade(peerOpenedDisputeMessage, dispute, trade); + } + + private void peerOpenedDisputeForTrade(PeerOpenedDisputeMessage peerOpenedDisputeMessage, Dispute dispute, Trade trade) { + String errorMessage = null; T disputeList = getDisputeList(); if (disputeList == null) { log.warn("disputes is null"); return; } - String errorMessage = null; - Dispute dispute = peerOpenedDisputeMessage.getDispute(); - - Optional optionalTrade = tradeManager.getTradeById(dispute.getTradeId()); - if (optionalTrade.isEmpty()) { - return; - } - - Trade trade = optionalTrade.get(); try { DisputeValidation.validateDisputeData(dispute, btcWalletService); DisputeValidation.validateNodeAddresses(dispute, config); diff --git a/core/src/main/java/bisq/core/support/dispute/arbitration/ArbitrationManager.java b/core/src/main/java/bisq/core/support/dispute/arbitration/ArbitrationManager.java index b879011989d..da8dc39948c 100644 --- a/core/src/main/java/bisq/core/support/dispute/arbitration/ArbitrationManager.java +++ b/core/src/main/java/bisq/core/support/dispute/arbitration/ArbitrationManager.java @@ -42,6 +42,7 @@ import bisq.core.support.messages.SupportMessage; import bisq.core.trade.ClosedTradableManager; import bisq.core.trade.TradeManager; +import bisq.core.trade.bisq_v1.FailedTradesManager; import bisq.core.trade.model.Tradable; import bisq.core.trade.model.bisq_v1.Contract; import bisq.core.trade.model.bisq_v1.Trade; @@ -91,13 +92,14 @@ public ArbitrationManager(P2PService p2PService, WalletsSetup walletsSetup, TradeManager tradeManager, ClosedTradableManager closedTradableManager, + FailedTradesManager failedTradesManager, OpenOfferManager openOfferManager, DaoFacade daoFacade, KeyRing keyRing, ArbitrationDisputeListService arbitrationDisputeListService, Config config, PriceFeedService priceFeedService) { - super(p2PService, tradeWalletService, walletService, walletsSetup, tradeManager, closedTradableManager, + super(p2PService, tradeWalletService, walletService, walletsSetup, tradeManager, closedTradableManager, failedTradesManager, openOfferManager, daoFacade, keyRing, arbitrationDisputeListService, config, priceFeedService); } diff --git a/core/src/main/java/bisq/core/support/dispute/mediation/MediationManager.java b/core/src/main/java/bisq/core/support/dispute/mediation/MediationManager.java index 8e640588925..7c010b72adf 100644 --- a/core/src/main/java/bisq/core/support/dispute/mediation/MediationManager.java +++ b/core/src/main/java/bisq/core/support/dispute/mediation/MediationManager.java @@ -37,6 +37,7 @@ import bisq.core.support.messages.SupportMessage; import bisq.core.trade.ClosedTradableManager; import bisq.core.trade.TradeManager; +import bisq.core.trade.bisq_v1.FailedTradesManager; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.bisq_v1.DisputeProtocol; import bisq.core.trade.protocol.bisq_v1.model.ProcessModel; @@ -88,13 +89,14 @@ public MediationManager(P2PService p2PService, WalletsSetup walletsSetup, TradeManager tradeManager, ClosedTradableManager closedTradableManager, + FailedTradesManager failedTradesManager, OpenOfferManager openOfferManager, DaoFacade daoFacade, KeyRing keyRing, MediationDisputeListService mediationDisputeListService, Config config, PriceFeedService priceFeedService) { - super(p2PService, tradeWalletService, walletService, walletsSetup, tradeManager, closedTradableManager, + super(p2PService, tradeWalletService, walletService, walletsSetup, tradeManager, closedTradableManager, failedTradesManager, openOfferManager, daoFacade, keyRing, mediationDisputeListService, config, priceFeedService); p2PService.getNetworkNode().addMessageListener(this); // listening for FileTransferPart message } diff --git a/core/src/main/java/bisq/core/support/dispute/refund/RefundManager.java b/core/src/main/java/bisq/core/support/dispute/refund/RefundManager.java index d0b417db53e..0108eb24023 100644 --- a/core/src/main/java/bisq/core/support/dispute/refund/RefundManager.java +++ b/core/src/main/java/bisq/core/support/dispute/refund/RefundManager.java @@ -39,6 +39,7 @@ import bisq.core.support.messages.SupportMessage; import bisq.core.trade.ClosedTradableManager; import bisq.core.trade.TradeManager; +import bisq.core.trade.bisq_v1.FailedTradesManager; import bisq.core.trade.model.bisq_v1.Trade; import bisq.network.p2p.AckMessageSourceType; @@ -55,6 +56,7 @@ import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.Transaction; +import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.core.TransactionInput; import org.bitcoinj.core.TransactionOutPoint; import org.bitcoinj.core.TransactionOutput; @@ -92,6 +94,7 @@ public RefundManager(P2PService p2PService, WalletsSetup walletsSetup, TradeManager tradeManager, ClosedTradableManager closedTradableManager, + FailedTradesManager failedTradesManager, OpenOfferManager openOfferManager, DaoFacade daoFacade, DelayedPayoutTxReceiverService delayedPayoutTxReceiverService, @@ -100,7 +103,7 @@ public RefundManager(P2PService p2PService, Config config, PriceFeedService priceFeedService, MempoolService mempoolService) { - super(p2PService, tradeWalletService, walletService, walletsSetup, tradeManager, closedTradableManager, + super(p2PService, tradeWalletService, walletService, walletsSetup, tradeManager, closedTradableManager, failedTradesManager, openOfferManager, daoFacade, keyRing, refundDisputeListService, config, priceFeedService); this.delayedPayoutTxReceiverService = delayedPayoutTxReceiverService; diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index 18b3ab89e45..b1d7398345e 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -801,7 +801,7 @@ public void onMoveInvalidTradeToFailedTrades(Trade trade) { failedTradesManager.add(trade); } - public void addFailedTradeToPendingTrades(Trade trade) { + public void addTradeToPendingTrades(Trade trade) { if (!trade.isInitialized()) { initPersistedTrade(trade); } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesDataModel.java index b55a0f0a336..bd669f4d30b 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/failedtrades/FailedTradesDataModel.java @@ -102,7 +102,7 @@ public boolean onMoveTradeToPendingTrades(Trade trade) { } failedTradesManager.removeTrade(trade); - tradeManager.addFailedTradeToPendingTrades(trade); + tradeManager.addTradeToPendingTrades(trade); return true; }