Skip to content

Commit

Permalink
Allow zero fees (#871)
Browse files Browse the repository at this point in the history
* Allow zero fees

* Bump version

* Update changelog

* Small fix

* Fix ingres

* Revert "Fix ingres"

This reverts commit 625d042.
  • Loading branch information
Ifropc authored May 9, 2023
1 parent 8c56ac7 commit 63a6a39
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ subprojects {

allprojects {
group = "org.stellar.anchor-sdk"
version = "1.2.12"
version = "1.2.13"

tasks.jar {
manifest {
Expand Down
16 changes: 14 additions & 2 deletions core/src/main/java/org/stellar/anchor/util/SepHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down

0 comments on commit 63a6a39

Please sign in to comment.