Allow mediation of failed and closed trades.

This commit is contained in:
jmacxx 2024-01-09 12:56:30 -06:00
parent 566ab53c8f
commit ff52c43d4f
No known key found for this signature in database
GPG Key ID: 155297BABFE94A1B
7 changed files with 42 additions and 15 deletions

View File

@ -371,7 +371,7 @@ class CoreTradesService {
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));

View File

@ -38,6 +38,7 @@ import bisq.core.support.dispute.messages.PeerOpenedDisputeMessage;
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<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;
@ -116,6 +118,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
WalletsSetup walletsSetup,
TradeManager tradeManager,
ClosedTradableManager closedTradableManager,
FailedTradesManager failedTradesManager,
OpenOfferManager openOfferManager,
DaoFacade daoFacade,
KeyRing keyRing,
@ -128,6 +131,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
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 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
// 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);

View File

@ -42,6 +42,7 @@ import bisq.core.support.messages.ChatMessage;
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 final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
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);
}

View File

@ -37,6 +37,7 @@ import bisq.core.support.messages.ChatMessage;
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 final class MediationManager extends DisputeManager<MediationDisputeList>
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
}

View File

@ -39,6 +39,7 @@ import bisq.core.support.messages.ChatMessage;
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 bisq.common.util.Tuple2;
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 final class RefundManager extends DisputeManager<RefundDisputeList> {
WalletsSetup walletsSetup,
TradeManager tradeManager,
ClosedTradableManager closedTradableManager,
FailedTradesManager failedTradesManager,
OpenOfferManager openOfferManager,
DaoFacade daoFacade,
DelayedPayoutTxReceiverService delayedPayoutTxReceiverService,
@ -100,7 +103,7 @@ public final class RefundManager extends DisputeManager<RefundDisputeList> {
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;

View File

@ -801,7 +801,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
failedTradesManager.add(trade);
}
public void addFailedTradeToPendingTrades(Trade trade) {
public void addTradeToPendingTrades(Trade trade) {
if (!trade.isInitialized()) {
initPersistedTrade(trade);
}

View File

@ -102,7 +102,7 @@ class FailedTradesDataModel extends ActivatableDataModel {
}
failedTradesManager.removeTrade(trade);
tradeManager.addFailedTradeToPendingTrades(trade);
tradeManager.addTradeToPendingTrades(trade);
return true;
}