diff --git a/CHANGELOG.md b/CHANGELOG.md index 6859127e26..787bf0928e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## 1.2.13 +* Allow zero fees in `PATCH /transactions` request [#871](https://github.com/stellar/java-stellar-anchor-sdk/pull/871) + ## 1.2.12 * Don't set amount_out for indicative quote. [#823](https://github.com/stellar/java-stellar-anchor-sdk/pull/823) * Add docker-compose files to run e2e tests with containers diff --git a/build.gradle.kts b/build.gradle.kts index 1fc9a533af..a36f604f58 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -118,7 +118,7 @@ subprojects { allprojects { group = "org.stellar.anchor-sdk" - version = "1.2.12" + version = "1.2.13" tasks.jar { manifest { diff --git a/core/src/main/java/org/stellar/anchor/util/SepHelper.java b/core/src/main/java/org/stellar/anchor/util/SepHelper.java index dd3755d9a8..28014bc201 100644 --- a/core/src/main/java/org/stellar/anchor/util/SepHelper.java +++ b/core/src/main/java/org/stellar/anchor/util/SepHelper.java @@ -55,6 +55,11 @@ public static void validateAmount(String amount) throws AnchorException { } public static BigDecimal validateAmount(String messagePrefix, String amount) + throws AnchorException { + return validateAmount(messagePrefix, amount, false); + } + + public static BigDecimal validateAmount(String messagePrefix, String amount, boolean allowZero) throws BadRequestException { // assetName if (StringHelper.isEmpty(amount)) { @@ -67,8 +72,15 @@ public static BigDecimal validateAmount(String messagePrefix, String amount) } catch (NumberFormatException e) { throw new BadRequestException(messagePrefix + "amount is invalid", e); } - if (sAmount.signum() < 1) { - throw new BadRequestException(messagePrefix + "amount should be positive"); + + if (allowZero) { + if (sAmount.signum() < 0) { + throw new BadRequestException(messagePrefix + "amount should be non-negative"); + } + } else { + if (sAmount.signum() < 1) { + throw new BadRequestException(messagePrefix + "amount should be positive"); + } } return sAmount; } diff --git a/platform/src/main/java/org/stellar/anchor/platform/service/TransactionService.java b/platform/src/main/java/org/stellar/anchor/platform/service/TransactionService.java index 881a452ded..e3afa9523c 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/service/TransactionService.java +++ b/platform/src/main/java/org/stellar/anchor/platform/service/TransactionService.java @@ -162,7 +162,7 @@ void updateSep31Transaction(PatchTransactionRequest ptr, Sep31Transaction txn) if (ptr.getAmountFee() != null && (!Objects.equals(txn.getAmountFee(), ptr.getAmountFee().getAmount()) || !Objects.equals(txn.getAmountFeeAsset(), ptr.getAmountFee().getAsset()))) { - validateAsset("amount_fee", ptr.getAmountFee()); + validateAsset("amount_fee", ptr.getAmountFee(), true); txn.setAmountFee(ptr.getAmountFee().getAmount()); txn.setAmountFeeAsset(ptr.getAmountFee().getAsset()); txWasUpdated = true; @@ -236,12 +236,17 @@ void validateIfStatusIsSupported(String status) throws BadRequestException { * @throws BadRequestException if the provided asset is not supported */ void validateAsset(String fieldName, Amount amount) throws BadRequestException { + validateAsset(fieldName, amount, false); + } + + void validateAsset(String fieldName, Amount amount, boolean allowZero) + throws BadRequestException { if (amount == null) { return; } // asset amount needs to be non-empty and valid - SepHelper.validateAmount(fieldName + ".", amount.getAmount()); + SepHelper.validateAmount(fieldName + ".", amount.getAmount(), allowZero); // asset name cannot be empty if (StringHelper.isEmpty(amount.getAsset())) {