Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Improve comments in OfferUtil
Browse files Browse the repository at this point in the history
Add docstring for getRoundedFiatAmount().

Expand and reword docstring for getAdjustedAmount().

Break some long lines, and make the checkArgument() failure message
accurate.
  • Loading branch information
chirhonul committed Aug 20, 2018
1 parent e5039a2 commit 50bacfd
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ static Volume getAdjustedFiatVolume(Volume volumeByAmount, int factor) {
return Volume.parse(String.valueOf(roundedVolume), volumeByAmount.getCurrencyCode());
}

/**
* Calculate the possibly adjusted amount for {@code amount}, taking into account the
* {@code price} and {@code maxTradeLimit} and {@code factor}.
*
* @param amount Bitcoin amount which is a candidate for getting rounded.
* @param price Price used in relation ot that amount.
* @param maxTradeLimit The max. trade limit of the users account, in satoshis.
* @return The adjusted amount
*/
public static Coin getRoundedFiatAmount(Coin amount, Price price, long maxTradeLimit) {
return getAdjustedAmount(amount, price, maxTradeLimit, 1);
}
Expand All @@ -178,16 +187,20 @@ public static Coin getAdjustedAmountForHalCash(Coin amount, Price price, long ma
}

/**
* Calculate the possibly adjusted amount for {@code amount}, taking into account the
* {@code price} and {@code maxTradeLimit} and {@code factor}.
*
* @param amount Bitcoin amount which is a candidate for getting rounded
* @param price Price used in relation ot that amount
* @param maxTradeLimit The max. trade limit of the users account.
* @param factor The factor used for rounding. E.g. 1 means rounded to units of 1 EUR, 10 means rounded to 10 EUR...
* @param amount Bitcoin amount which is a candidate for getting rounded.
* @param price Price used in relation ot that amount.
* @param maxTradeLimit The max. trade limit of the users account, in satoshis.
* @param factor The factor used for rounding. E.g. 1 means rounded to units of
* 1 EUR, 10 means rounded to 10 EUR, etc.
* @return The adjusted amount
*/
@VisibleForTesting
static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, int factor) {
// Amount must result in a volume of min factor units of the fiat currency, e.g. 1 EUR or 10 EUR in case of HalCash
// Amount must result in a volume of min factor units of the fiat currency, e.g. 1 EUR or
// 10 EUR in case of HalCash.
Volume smallestUnitForVolume = Volume.parse(String.valueOf(factor), price.getCurrencyCode());
if (smallestUnitForVolume.getValue() <= 0)
return Coin.ZERO;
Expand All @@ -196,10 +209,11 @@ static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, int
long minTradeAmount = Restrictions.getMinTradeAmount().value;

// We use 10 000 satoshi as min allowed amount
checkArgument(minTradeAmount >= 10000, "MinTradeAmount must be positive");

checkArgument(
minTradeAmount >= 10_000,
"MinTradeAmount must be at least 10k satoshi"
);
smallestUnitForAmount = Coin.valueOf(Math.max(minTradeAmount, smallestUnitForAmount.value));

// We don't allow smaller amount values than smallestUnitForAmount
if (amount.compareTo(smallestUnitForAmount) < 0)
amount = smallestUnitForAmount;
Expand All @@ -209,8 +223,8 @@ static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, int
if (volume.getValue() <= 0)
return Coin.ZERO;

// From that adjusted volume we calculate back the amount. It might be a bit different as the amount used as
// input before due rounding.
// From that adjusted volume we calculate back the amount. It might be a bit different as
// the amount used as input before due rounding.
amount = price.getAmountByVolume(volume);

// For the amount we allow only 4 decimal places
Expand Down

0 comments on commit 50bacfd

Please sign in to comment.