From 50bacfd825ea8c4c418d8563dfbc8cd967567d98 Mon Sep 17 00:00:00 2001 From: Chi Nul Date: Mon, 20 Aug 2018 14:08:29 +0200 Subject: [PATCH] Improve comments in OfferUtil Add docstring for getRoundedFiatAmount(). Expand and reword docstring for getAdjustedAmount(). Break some long lines, and make the checkArgument() failure message accurate. --- src/main/java/bisq/core/offer/OfferUtil.java | 34 ++++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/java/bisq/core/offer/OfferUtil.java b/src/main/java/bisq/core/offer/OfferUtil.java index 2a500bc1..fa31a319 100644 --- a/src/main/java/bisq/core/offer/OfferUtil.java +++ b/src/main/java/bisq/core/offer/OfferUtil.java @@ -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); } @@ -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; @@ -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; @@ -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