From d136815552b8bb532573b356973c577b25a70b3a Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 13 Sep 2021 18:11:06 -0400 Subject: [PATCH] support creating offer from grpc api fee payment currency is xmr scale atomic units from grpc api to centineros for consistency implement ParsingUtils.atomicUnitsToCentineros() --- core/src/main/java/bisq/core/offer/OfferUtil.java | 2 +- core/src/main/java/bisq/core/util/ParsingUtils.java | 12 ++++++++++++ .../java/bisq/daemon/grpc/GrpcOffersService.java | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index 8ea47fd2be..714a27f5b9 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -91,7 +91,7 @@ public class OfferUtil { private final TradeStatisticsManager tradeStatisticsManager; private final Predicate isValidFeePaymentCurrencyCode = (c) -> - c.equalsIgnoreCase("BSQ") || c.equalsIgnoreCase("BTC"); + c.equalsIgnoreCase("XMR"); @Inject public OfferUtil(AccountAgeWitnessService accountAgeWitnessService, diff --git a/core/src/main/java/bisq/core/util/ParsingUtils.java b/core/src/main/java/bisq/core/util/ParsingUtils.java index b840eebb84..b248b48419 100644 --- a/core/src/main/java/bisq/core/util/ParsingUtils.java +++ b/core/src/main/java/bisq/core/util/ParsingUtils.java @@ -19,6 +19,8 @@ public class ParsingUtils { /** * Multiplier to convert centineros (the base XMR unit of Coin) to atomic units. + * + * TODO: change base unit to atomic units and long */ private static BigInteger CENTINEROS_AU_MULTIPLIER = BigInteger.valueOf(10000); @@ -42,6 +44,16 @@ public class ParsingUtils { return BigInteger.valueOf(centineros).multiply(ParsingUtils.CENTINEROS_AU_MULTIPLIER); } + /** + * Convert atomic units to centineros. + * + * @param atomicUnits is an amount in atomic units + * @return the amount in centineros + */ + public static long atomicUnitsToCentineros(long atomicUnits) { + return atomicUnits / CENTINEROS_AU_MULTIPLIER.longValue(); + } + public static Coin parseToCoin(String input, CoinFormatter coinFormatter) { return parseToCoin(input, coinFormatter.getMonetaryFormat()); } diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java index 54658e4c9a..f520a806b1 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java @@ -21,7 +21,7 @@ import bisq.core.api.CoreApi; import bisq.core.api.model.OfferInfo; import bisq.core.offer.Offer; import bisq.core.offer.OpenOffer; - +import bisq.core.util.ParsingUtils; import bisq.proto.grpc.CancelOfferReply; import bisq.proto.grpc.CancelOfferRequest; import bisq.proto.grpc.CreateOfferReply; @@ -149,8 +149,8 @@ class GrpcOffersService extends OffersImplBase { req.getPrice(), req.getUseMarketBasedPrice(), req.getMarketPriceMargin(), - req.getAmount(), - req.getMinAmount(), + ParsingUtils.atomicUnitsToCentineros(req.getAmount()), // scale atomic unit to centineros for consistency TODO switch base to atomic units? + ParsingUtils.atomicUnitsToCentineros(req.getMinAmount()), req.getBuyerSecurityDeposit(), req.getTriggerPrice(), req.getPaymentAccountId(),