skip reset address entries when failed trade is scheduled for deletion

This commit is contained in:
woodser 2025-03-07 09:43:29 -05:00 committed by woodser
parent 8b1d2aa203
commit bf97fbc7ea
2 changed files with 14 additions and 1 deletions

View File

@ -923,8 +923,8 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
requestPersistence();
}, errorMessage -> {
log.warn("Taker error during trade initialization: " + errorMessage);
xmrWalletService.resetAddressEntriesForOpenOffer(trade.getId()); // TODO: move to maybe remove on error
trade.onProtocolError();
xmrWalletService.resetAddressEntriesForOpenOffer(trade.getId()); // TODO: move this into protocol error handling
errorMessageHandler.handleErrorMessage(errorMessage);
});
@ -1285,6 +1285,12 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
}
}
public boolean hasFailedScheduledTrade(String offerId) {
synchronized (failedTradesManager) {
return failedTradesManager.getTradeById(offerId).isPresent() && failedTradesManager.getTradeById(offerId).get().isProtocolErrorHandlingScheduled();
}
}
public Optional<Trade> getOpenTradeByUid(String tradeUid) {
synchronized (tradableList) {
return tradableList.stream().filter(e -> e.getUid().equals(tradeUid)).findFirst();

View File

@ -1016,6 +1016,13 @@ public class XmrWalletService extends XmrWalletBase {
public synchronized void resetAddressEntriesForOpenOffer(String offerId) {
log.info("resetAddressEntriesForOpenOffer offerId={}", offerId);
// skip if failed trade is scheduled for processing // TODO: do not call this function in this case?
if (tradeManager.hasFailedScheduledTrade(offerId)) {
log.warn("Refusing to reset address entries because trade is scheduled for deletion with offerId={}", offerId);
return;
}
swapAddressEntryToAvailable(offerId, XmrAddressEntry.Context.OFFER_FUNDING);
// swap trade payout to available if applicable