Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mediation of failed and closed trades #6998

Merged
merged 1 commit into from Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/api/CoreTradesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
38 changes: 29 additions & 9 deletions core/src/main/java/bisq/core/support/dispute/DisputeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +92,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> 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<T> disputeListService;
Expand All @@ -116,6 +118,7 @@ public DisputeManager(P2PService p2PService,
WalletsSetup walletsSetup,
TradeManager tradeManager,
ClosedTradableManager closedTradableManager,
FailedTradesManager failedTradesManager,
OpenOfferManager openOfferManager,
DaoFacade daoFacade,
KeyRing keyRing,
Expand All @@ -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();
Expand Down Expand Up @@ -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<Trade> optionalTrade = tradeManager.getTradeById(dispute.getTradeId());
if (optionalTrade.isEmpty()) {
return;
}

Trade trade = optionalTrade.get();
try {
DisputeValidation.validateDisputeData(dispute, btcWalletService);
DisputeValidation.validateNodeAddresses(dispute, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -92,6 +94,7 @@ public RefundManager(P2PService p2PService,
WalletsSetup walletsSetup,
TradeManager tradeManager,
ClosedTradableManager closedTradableManager,
FailedTradesManager failedTradesManager,
OpenOfferManager openOfferManager,
DaoFacade daoFacade,
DelayedPayoutTxReceiverService delayedPayoutTxReceiverService,
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/trade/TradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public boolean onMoveTradeToPendingTrades(Trade trade) {
}

failedTradesManager.removeTrade(trade);
tradeManager.addFailedTradeToPendingTrades(trade);
tradeManager.addTradeToPendingTrades(trade);
return true;
}

Expand Down