Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow zero fees #871

Merged
merged 6 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 8 additions & 1 deletion 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,7 +72,9 @@ public static BigDecimal validateAmount(String messagePrefix, String amount)
} catch (NumberFormatException e) {
throw new BadRequestException(messagePrefix + "amount is invalid", e);
}
if (sAmount.signum() < 1) {
if (allowZero && 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