diff --git a/src/main/java/org/qortal/api/resource/CrossChainHtlcResource.java b/src/main/java/org/qortal/api/resource/CrossChainHtlcResource.java index c0d4a94b..46d7ebc6 100644 --- a/src/main/java/org/qortal/api/resource/CrossChainHtlcResource.java +++ b/src/main/java/org/qortal/api/resource/CrossChainHtlcResource.java @@ -479,8 +479,6 @@ public class CrossChainHtlcResource { ) @ApiErrors({ApiError.INVALID_CRITERIA, ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN}) public boolean refundAllHtlc() { - Security.checkApiCallAllowed(request); - Security.checkApiCallAllowed(request); boolean success = false; @@ -561,11 +559,6 @@ public class CrossChainHtlcResource { if (atData == null) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN); - if (atData.getIsFinished()) { - LOGGER.info(String.format("Skipping finished AT %s", atAddress)); - throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA); - } - ACCT acct = SupportedBlockchain.getAcctByCodeHash(atData.getCodeHash()); if (acct == null) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA); @@ -574,6 +567,13 @@ public class CrossChainHtlcResource { if (crossChainTradeData == null) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA); + // If the AT is "finished" then it will have a zero balance + // In these cases we should avoid HTLC refunds if tbe QORT haven't been returned to the seller + if (atData.getIsFinished() && crossChainTradeData.mode != AcctMode.REFUNDED && crossChainTradeData.mode != AcctMode.CANCELLED) { + LOGGER.info(String.format("Skipping AT %s because the QORT has already been redemed", atAddress)); + throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA); + } + List allTradeBotData = repository.getCrossChainRepository().getAllTradeBotData(); TradeBotData tradeBotData = allTradeBotData.stream().filter(tradeBotDataItem -> tradeBotDataItem.getAtAddress().equals(atAddress)).findFirst().orElse(null); if (tradeBotData == null)