From 673f23b6a0685ac956552c3867d8f5395d015661 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Thu, 12 Aug 2021 08:29:52 +0100 Subject: [PATCH] Improvement to commit f71516f Now only skipping the HTLC redemption if the AT is finished and the balance has been redeemed by the buyer. This allows HTLCs to be refunded for ATs that have been refunded or cancelled. --- .../api/resource/CrossChainHtlcResource.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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)