From cc9ea4ab08f7f3a211c939ed008d95a6d6a43fe3 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 10 Aug 2018 22:19:59 +0200 Subject: [PATCH 1/6] Add HalCash --- .../bisq/core/payment/HalCashAccount.java | 46 ++++++++ .../core/payment/PaymentAccountFactory.java | 2 + .../payload/HalCashAccountPayload.java | 102 ++++++++++++++++++ .../core/payment/payload/PaymentMethod.java | 3 + .../bisq/core/proto/CoreProtoResolver.java | 3 + .../resources/i18n/displayStrings.properties | 13 ++- 6 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/main/java/bisq/core/payment/HalCashAccount.java create mode 100644 src/main/java/bisq/core/payment/payload/HalCashAccountPayload.java diff --git a/src/main/java/bisq/core/payment/HalCashAccount.java b/src/main/java/bisq/core/payment/HalCashAccount.java new file mode 100644 index 00000000..dba8ee82 --- /dev/null +++ b/src/main/java/bisq/core/payment/HalCashAccount.java @@ -0,0 +1,46 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.core.payment; + +import bisq.core.locale.FiatCurrency; +import bisq.core.payment.payload.HalCashAccountPayload; +import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.payload.PaymentMethod; + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +public final class HalCashAccount extends PaymentAccount { + public HalCashAccount() { + super(PaymentMethod.HAL_CASH); + setSingleTradeCurrency(new FiatCurrency("EUR")); + } + + @Override + protected PaymentAccountPayload createPayload() { + return new HalCashAccountPayload(paymentMethod.getId(), id); + } + + public void setMobileNr(String mobileNr) { + ((HalCashAccountPayload) paymentAccountPayload).setMobileNr(mobileNr); + } + + public String getMobileNr() { + return ((HalCashAccountPayload) paymentAccountPayload).getMobileNr(); + } +} diff --git a/src/main/java/bisq/core/payment/PaymentAccountFactory.java b/src/main/java/bisq/core/payment/PaymentAccountFactory.java index 2d6fad15..df8a96b9 100644 --- a/src/main/java/bisq/core/payment/PaymentAccountFactory.java +++ b/src/main/java/bisq/core/payment/PaymentAccountFactory.java @@ -72,6 +72,8 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) { return new MoneyGramAccount(); case PaymentMethod.WESTERN_UNION_ID: return new WesternUnionAccount(); + case PaymentMethod.HAL_CASH_ID: + return new HalCashAccount(); case PaymentMethod.F2F_ID: return new F2FAccount(); default: diff --git a/src/main/java/bisq/core/payment/payload/HalCashAccountPayload.java b/src/main/java/bisq/core/payment/payload/HalCashAccountPayload.java new file mode 100644 index 00000000..34b2d3c1 --- /dev/null +++ b/src/main/java/bisq/core/payment/payload/HalCashAccountPayload.java @@ -0,0 +1,102 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.core.payment.payload; + +import io.bisq.generated.protobuffer.PB; + +import com.google.protobuf.Message; + +import org.springframework.util.CollectionUtils; + +import java.nio.charset.Charset; + +import java.util.HashMap; +import java.util.Map; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.extern.slf4j.Slf4j; + +import javax.annotation.Nullable; + +@EqualsAndHashCode(callSuper = true) +@ToString +@Setter +@Getter +@Slf4j +public final class HalCashAccountPayload extends PaymentAccountPayload { + private String mobileNr = ""; + + public HalCashAccountPayload(String paymentMethod, String id) { + super(paymentMethod, id); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + private HalCashAccountPayload(String paymentMethod, String id, + String mobileNr, + long maxTradePeriod, + @Nullable Map excludeFromJsonDataMap) { + super(paymentMethod, + id, + maxTradePeriod, + excludeFromJsonDataMap); + this.mobileNr = mobileNr; + } + + @Override + public Message toProtoMessage() { + return getPaymentAccountPayloadBuilder() + .setHalCashAccountPayload(PB.HalCashAccountPayload.newBuilder() + .setMobileNr(mobileNr)) + .build(); + } + + public static HalCashAccountPayload fromProto(PB.PaymentAccountPayload proto) { + return new HalCashAccountPayload(proto.getPaymentMethodId(), + proto.getId(), + proto.getHalCashAccountPayload().getMobileNr(), + proto.getMaxTradePeriod(), + CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap())); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public String getPaymentDetails() { + return "HalCash - Mobile no.: " + mobileNr; + } + + @Override + public String getPaymentDetailsForTradePopup() { + return "Mobile no.: " + mobileNr; + } + + @Override + public byte[] getAgeWitnessInputData() { + return super.getAgeWitnessInputData(mobileNr.getBytes(Charset.forName("UTF-8"))); + } +} diff --git a/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/src/main/java/bisq/core/payment/payload/PaymentMethod.java index e1549e55..209b512d 100644 --- a/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -77,6 +77,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable { public static final String CASH_DEPOSIT_ID = "CASH_DEPOSIT"; public static final String MONEY_GRAM_ID = "MONEY_GRAM"; public static final String WESTERN_UNION_ID = "WESTERN_UNION"; + public static final String HAL_CASH_ID = "HAL_CASH"; public static final String F2F_ID = "F2F"; public static final String BLOCK_CHAINS_ID = "BLOCK_CHAINS"; @@ -107,6 +108,7 @@ public final class PaymentMethod implements PersistablePayload, Comparable { public static PaymentMethod MONEY_GRAM; public static PaymentMethod WESTERN_UNION; public static PaymentMethod F2F; + public static PaymentMethod HAL_CASH; public static PaymentMethod BLOCK_CHAINS; private static List ALL_VALUES; @@ -210,6 +212,7 @@ public static List getAllValues() { NATIONAL_BANK = new PaymentMethod(NATIONAL_BANK_ID, 4 * DAY, maxTradeLimitMidRisk), SAME_BANK = new PaymentMethod(SAME_BANK_ID, 2 * DAY, maxTradeLimitMidRisk), SPECIFIC_BANKS = new PaymentMethod(SPECIFIC_BANKS_ID, 4 * DAY, maxTradeLimitMidRisk), + HAL_CASH = new PaymentMethod(HAL_CASH_ID, DAY, maxTradeLimitLowRisk), F2F = new PaymentMethod(F2F_ID, 4 * DAY, maxTradeLimitLowRisk), // Trans national diff --git a/src/main/java/bisq/core/proto/CoreProtoResolver.java b/src/main/java/bisq/core/proto/CoreProtoResolver.java index d2c14e4b..2597db57 100644 --- a/src/main/java/bisq/core/proto/CoreProtoResolver.java +++ b/src/main/java/bisq/core/proto/CoreProtoResolver.java @@ -26,6 +26,7 @@ import bisq.core.payment.payload.CryptoCurrencyAccountPayload; import bisq.core.payment.payload.F2FAccountPayload; import bisq.core.payment.payload.FasterPaymentsAccountPayload; +import bisq.core.payment.payload.HalCashAccountPayload; import bisq.core.payment.payload.InteracETransferAccountPayload; import bisq.core.payment.payload.MoneyBeamAccountPayload; import bisq.core.payment.payload.MoneyGramAccountPayload; @@ -128,6 +129,8 @@ public PaymentAccountPayload fromProto(PB.PaymentAccountPayload proto) { return PerfectMoneyAccountPayload.fromProto(proto); case SWISH_ACCOUNT_PAYLOAD: return SwishAccountPayload.fromProto(proto); + case HAL_CASH_ACCOUNT_PAYLOAD: + return HalCashAccountPayload.fromProto(proto); case U_S_POSTAL_MONEY_ORDER_ACCOUNT_PAYLOAD: return USPostalMoneyOrderAccountPayload.fromProto(proto); default: diff --git a/src/main/resources/i18n/displayStrings.properties b/src/main/resources/i18n/displayStrings.properties index f2804d66..c8ae6769 100644 --- a/src/main/resources/i18n/displayStrings.properties +++ b/src/main/resources/i18n/displayStrings.properties @@ -545,7 +545,10 @@ portfolio.pending.step2_buyer.westernUnionMTCNInfo.headline=Send MTCN and receip portfolio.pending.step2_buyer.westernUnionMTCNInfo.msg=You need to send the MTCN (tracking number) and a photo of the receipt by email to the BTC seller.\n\ The receipt must clearly show the seller''s full name, city, country and the amount. The seller''s email is: {0}.\n\n\ Did you send the MTCN and contract to the seller? - +portfolio.pending.step2_buyer.halCashInfo.headline=Send HalCash code +portfolio.pending.step2_buyer.halCashInfo.msg=You need to send a text message with the HalCash code as well as the \ + trade ID ({0}) to the BTC seller.\nThe seller''s mobile nr. is {1}.\n\n\ + Did you send the code to the seller? portfolio.pending.step2_buyer.confirmStart.headline=Confirm that you have started the payment portfolio.pending.step2_buyer.confirmStart.msg=Did you initiate the {0} payment to your trading partner? portfolio.pending.step2_buyer.confirmStart.yes=Yes, I have started the payment @@ -591,6 +594,8 @@ portfolio.pending.step3_seller.westernUnion=The buyer has to send you the MTCN ( The receipt must clearly show your full name, city, country and the amount. Please check your email if you received the MTCN.\n\n\ After closing that popup you will see the BTC buyer's name and address for picking up the money from Western Union.\n\n\ Only confirm receipt after you have successfully picked up the money! +portfolio.pending.step3_seller.halCash=The buyer has to send you the HalCash code as text message. Beside that you will receive a message from HalCash with the required information to withdraw the EUR from a HalCash supporting ATM.\n\n\ + After you have picked up the money from the ATM please confirm here the receipt of the payment! portfolio.pending.step3_seller.bankCheck=\n\nPlease also verify that the sender's name in your bank statement matches that one from the trade contract:\nSender's name: {0}\n\n\ If the name is not the same as the one displayed here, {1} @@ -1835,6 +1840,9 @@ payment.moneyGram.info=When using MoneyGram the BTC buyer has to send the Author The receipt must clearly show the seller's full name, country, state and the amount. The buyer will get displayed the seller's email in the trade process. payment.westernUnion.info=When using Western Union the BTC buyer has to send the MTCN (tracking number) and a photo of the receipt by email to the BTC seller. \ The receipt must clearly show the seller's full name, city, country and the amount. The buyer will get displayed the seller's email in the trade process. +payment.halCash.info=When using HalCash the BTC buyer need to send the BTC seller the HalCash code via a text message from the mobile phone.\n\n\ + Please check make sure to not exceed the maximum amount your bank allows you to send with HalCash.\n\n\ + In case of a dispute the BTC seller need to provide the proof that he sent the EUR. payment.limits.info=Please be aware that all bank transfers carry a certain amount of chargeback risk.\n\ \n\ To mitigate this risk, Bisq sets per-trade limits based on two factors:\n\ @@ -1921,6 +1929,7 @@ SWISH=Swish CLEAR_X_CHANGE=Zelle (ClearXchange) CHASE_QUICK_PAY=Chase QuickPay INTERAC_E_TRANSFER=Interac e-Transfer +HAL_CASH=HalCash BLOCK_CHAINS=Altcoins # suppress inspection "UnusedProperty" @@ -1957,6 +1966,8 @@ CHASE_QUICK_PAY_SHORT=Chase QuickPay # suppress inspection "UnusedProperty" INTERAC_E_TRANSFER_SHORT=Interac e-Transfer # suppress inspection "UnusedProperty" +HAL_CASH_SHORT=HalCash +# suppress inspection "UnusedProperty" BLOCK_CHAINS_SHORT=Altcoins From 290af8bd2b16a2feda8221670f5623801191906d Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 11 Aug 2018 20:48:42 +0200 Subject: [PATCH 2/6] Add adjustment fro multiple ofg 10 EUR for HalCash With ATMs one can withdraw only multiples of 10 EUR. We adjust the input values the way that the EUR amount leads to multiple of 10. MinAmount and amount will be adjusted. Please note that a similar approach like implemented here for HalCash can be used for removing the decimal places from fiat amounts to improve privacy. We keep that for a follow up PR to not mix 2 different use cases. --- src/main/java/bisq/core/offer/Offer.java | 11 ++++---- src/main/java/bisq/core/offer/OfferUtil.java | 28 +++++++++++++++++++ src/main/java/bisq/core/trade/Trade.java | 13 +++++++-- .../resources/i18n/displayStrings.properties | 9 ++++-- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/main/java/bisq/core/offer/Offer.java b/src/main/java/bisq/core/offer/Offer.java index 7b925522..4afed5c7 100644 --- a/src/main/java/bisq/core/offer/Offer.java +++ b/src/main/java/bisq/core/offer/Offer.java @@ -225,12 +225,11 @@ public void checkTradePriceTolerance(long takersTradePrice) throws TradePriceOut public Volume getVolumeByAmount(Coin amount) { Price price = getPrice(); if (price != null && amount != null) { - // try { - return price.getVolumeByAmount(amount); - /* } catch (Throwable t) { - log.error("getVolumeByAmount failed. Error=" + t.getMessage()); - return null; - }*/ + Volume volumeByAmount = price.getVolumeByAmount(amount); + if (offerPayload.getPaymentMethodId().equals(PaymentMethod.HAL_CASH_ID)) + volumeByAmount = OfferUtil.getAdjustedVolumeForHalCash(volumeByAmount); + + return volumeByAmount; } else { return null; } diff --git a/src/main/java/bisq/core/offer/OfferUtil.java b/src/main/java/bisq/core/offer/OfferUtil.java index 5b32329f..e1b15c80 100644 --- a/src/main/java/bisq/core/offer/OfferUtil.java +++ b/src/main/java/bisq/core/offer/OfferUtil.java @@ -19,6 +19,8 @@ import bisq.core.app.BisqEnvironment; import bisq.core.btc.wallet.BsqWalletService; +import bisq.core.monetary.Price; +import bisq.core.monetary.Volume; import bisq.core.provider.fee.FeeService; import bisq.core.user.Preferences; import bisq.core.util.CoinUtil; @@ -27,6 +29,8 @@ import org.bitcoinj.core.Coin; +import lombok.extern.slf4j.Slf4j; + import javax.annotation.Nullable; /** @@ -36,6 +40,7 @@ * Long-term there could be a GUI-agnostic OfferService which provides these and other functionalities to both the * GUI and the API. */ +@Slf4j public class OfferUtil { /** @@ -131,4 +136,27 @@ public static boolean isBsqForFeeAvailable(BsqWalletService bsqWalletService, @N availableBalance != null && !availableBalance.subtract(makerFee).isNegative(); } + + public static Volume getAdjustedVolumeForHalCash(Volume volumeByAmount) { + // EUR has precision 4 and we want multiple of 10 so we divide by 100000 then + // round and multiply with 10 + long rounded = Math.max(1, Math.round((double) volumeByAmount.getValue() / 100000d)); + return Volume.parse(String.valueOf(rounded * 10), "EUR"); + } + + public static Coin getAdjustedMinAmountForHalCash(Coin minAmount, Price price) { + // Min amount must result in a volume of min 10 EUR + Volume minVolume = Volume.parse(String.valueOf(10), "EUR"); + Coin minAmountByMinVolume = price.getAmountByVolume(minVolume); + if (minAmount.compareTo(minAmountByMinVolume) < 0) + minAmount = minAmountByMinVolume; + + // We adjust the minAmount so that the minVolume is a multiple of 10 EUR + minVolume = getAdjustedVolumeForHalCash(price.getVolumeByAmount(minAmount)); + minAmount = price.getAmountByVolume(minVolume); + + // We want only 4 decimal places + long rounded = Math.round((double) minAmount.value / 10000d) * 10000; + return Coin.valueOf(rounded); + } } diff --git a/src/main/java/bisq/core/trade/Trade.java b/src/main/java/bisq/core/trade/Trade.java index 293b61c9..1a26ce75 100644 --- a/src/main/java/bisq/core/trade/Trade.java +++ b/src/main/java/bisq/core/trade/Trade.java @@ -26,8 +26,10 @@ import bisq.core.monetary.Price; import bisq.core.monetary.Volume; import bisq.core.offer.Offer; +import bisq.core.offer.OfferUtil; import bisq.core.offer.OpenOfferManager; import bisq.core.payment.AccountAgeWitnessService; +import bisq.core.payment.payload.PaymentMethod; import bisq.core.proto.CoreProtoResolver; import bisq.core.trade.protocol.ProcessModel; import bisq.core.trade.protocol.TradeProtocol; @@ -697,10 +699,15 @@ public Date getTakeOfferDate() { @Nullable public Volume getTradeVolume() { - if (getTradeAmount() != null && getTradePrice() != null) - return getTradePrice().getVolumeByAmount(getTradeAmount()); - else + if (getTradeAmount() != null && getTradePrice() != null) { + Volume volumeByAmount = getTradePrice().getVolumeByAmount(getTradeAmount()); + if (offer != null && offer.getPaymentMethod().getId().equals(PaymentMethod.HAL_CASH_ID)) + volumeByAmount = OfferUtil.getAdjustedVolumeForHalCash(volumeByAmount); + + return volumeByAmount; + } else { return null; + } } public Date getHalfTradePeriodDate() { diff --git a/src/main/resources/i18n/displayStrings.properties b/src/main/resources/i18n/displayStrings.properties index c8ae6769..a3676c60 100644 --- a/src/main/resources/i18n/displayStrings.properties +++ b/src/main/resources/i18n/displayStrings.properties @@ -1481,7 +1481,6 @@ popup.warning.noArbitratorSelected.msg=You need to setup at least one arbitrator popup.warning.notFullyConnected=You need to wait until you are fully connected to the network.\nThat might take up to about 2 minutes at startup. popup.warning.notSufficientConnectionsToBtcNetwork=You need to wait until you have at least {0} connections to the Bitcoin network. popup.warning.downloadNotComplete=You need to wait until the download of missing Bitcoin blocks is complete. - popup.warning.removeOffer=Are you sure you want to remove that offer?\nThe maker fee of {0} will be lost if you remove that offer. popup.warning.tooLargePercentageValue=You cannot set a percentage of 100% or larger. popup.warning.examplePercentageValue=Please enter a percentage number like \"5.4\" for 5.4% @@ -1841,7 +1840,13 @@ payment.moneyGram.info=When using MoneyGram the BTC buyer has to send the Author payment.westernUnion.info=When using Western Union the BTC buyer has to send the MTCN (tracking number) and a photo of the receipt by email to the BTC seller. \ The receipt must clearly show the seller's full name, city, country and the amount. The buyer will get displayed the seller's email in the trade process. payment.halCash.info=When using HalCash the BTC buyer need to send the BTC seller the HalCash code via a text message from the mobile phone.\n\n\ - Please check make sure to not exceed the maximum amount your bank allows you to send with HalCash.\n\n\ + Please make sure to not exceed the maximum amount your bank allows you to send with HalCash. \ + The min. amount per withdrawal is 10 EUR and the max. amount is 600 EUR. For repeated withdrawals it is \ + 3000 EUR per receiver per day and 6000 EUR per receiver per month. Please cross check those limits with your \ + bank to be sure they use the same limits as stated here.\n\n\ + The withdrawal amount must be a multiple of 10 EUR as you cannot withdraw other amounts from an ATM. The\ + UI in the create-offer and take-offer screen will adjust the BTC amount so that the EUR amount is correct. You cannot use market \ + based price as the EUR amount would be changing with changing prices.\n\n\ In case of a dispute the BTC seller need to provide the proof that he sent the EUR. payment.limits.info=Please be aware that all bank transfers carry a certain amount of chargeback risk.\n\ \n\ From 33470c0a0d60d3bbb4cf66ba355bcff62b5d8cfb Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 13 Aug 2018 19:30:01 +0200 Subject: [PATCH 3/6] Fix text --- src/main/resources/i18n/displayStrings.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/i18n/displayStrings.properties b/src/main/resources/i18n/displayStrings.properties index a3676c60..8ffed119 100644 --- a/src/main/resources/i18n/displayStrings.properties +++ b/src/main/resources/i18n/displayStrings.properties @@ -1847,7 +1847,7 @@ payment.halCash.info=When using HalCash the BTC buyer need to send the BTC selle The withdrawal amount must be a multiple of 10 EUR as you cannot withdraw other amounts from an ATM. The\ UI in the create-offer and take-offer screen will adjust the BTC amount so that the EUR amount is correct. You cannot use market \ based price as the EUR amount would be changing with changing prices.\n\n\ - In case of a dispute the BTC seller need to provide the proof that he sent the EUR. + In case of a dispute the BTC buyer need to provide the proof that he sent the EUR. payment.limits.info=Please be aware that all bank transfers carry a certain amount of chargeback risk.\n\ \n\ To mitigate this risk, Bisq sets per-trade limits based on two factors:\n\ From 75f05fdeb6225caae9010c4e99cf72bff60dd9e3 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Tue, 14 Aug 2018 17:47:01 +0200 Subject: [PATCH 4/6] Add missing space --- src/main/resources/i18n/displayStrings.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/i18n/displayStrings.properties b/src/main/resources/i18n/displayStrings.properties index 8ffed119..0ad5ea03 100644 --- a/src/main/resources/i18n/displayStrings.properties +++ b/src/main/resources/i18n/displayStrings.properties @@ -1844,7 +1844,7 @@ payment.halCash.info=When using HalCash the BTC buyer need to send the BTC selle The min. amount per withdrawal is 10 EUR and the max. amount is 600 EUR. For repeated withdrawals it is \ 3000 EUR per receiver per day and 6000 EUR per receiver per month. Please cross check those limits with your \ bank to be sure they use the same limits as stated here.\n\n\ - The withdrawal amount must be a multiple of 10 EUR as you cannot withdraw other amounts from an ATM. The\ + The withdrawal amount must be a multiple of 10 EUR as you cannot withdraw other amounts from an ATM. The \ UI in the create-offer and take-offer screen will adjust the BTC amount so that the EUR amount is correct. You cannot use market \ based price as the EUR amount would be changing with changing prices.\n\n\ In case of a dispute the BTC buyer need to provide the proof that he sent the EUR. From f07e7ea26e474d8ee1ac175fc70c8957c539abcc Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 14 Aug 2018 19:00:44 +0200 Subject: [PATCH 5/6] Adjust amount in case of edit offer --- src/main/java/bisq/core/offer/OfferUtil.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/bisq/core/offer/OfferUtil.java b/src/main/java/bisq/core/offer/OfferUtil.java index e1b15c80..2f231fce 100644 --- a/src/main/java/bisq/core/offer/OfferUtil.java +++ b/src/main/java/bisq/core/offer/OfferUtil.java @@ -144,19 +144,19 @@ public static Volume getAdjustedVolumeForHalCash(Volume volumeByAmount) { return Volume.parse(String.valueOf(rounded * 10), "EUR"); } - public static Coin getAdjustedMinAmountForHalCash(Coin minAmount, Price price) { - // Min amount must result in a volume of min 10 EUR - Volume minVolume = Volume.parse(String.valueOf(10), "EUR"); - Coin minAmountByMinVolume = price.getAmountByVolume(minVolume); - if (minAmount.compareTo(minAmountByMinVolume) < 0) - minAmount = minAmountByMinVolume; + public static Coin getAdjustedAmountForHalCash(Coin amount, Price price) { + // Amount must result in a volume of min 10 EUR + Volume volume = Volume.parse(String.valueOf(10), "EUR"); + Coin amountByVolume = price.getAmountByVolume(volume); + if (amount.compareTo(amountByVolume) < 0) + amount = amountByVolume; - // We adjust the minAmount so that the minVolume is a multiple of 10 EUR - minVolume = getAdjustedVolumeForHalCash(price.getVolumeByAmount(minAmount)); - minAmount = price.getAmountByVolume(minVolume); + // We adjust the amount so that the volume is a multiple of 10 EUR + volume = getAdjustedVolumeForHalCash(price.getVolumeByAmount(amount)); + amount = price.getAmountByVolume(volume); // We want only 4 decimal places - long rounded = Math.round((double) minAmount.value / 10000d) * 10000; + long rounded = Math.round((double) amount.value / 10000d) * 10000; return Coin.valueOf(rounded); } } From 03002659813547da64389ddbcca1d6ee42b136d2 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 14 Aug 2018 20:46:15 +0200 Subject: [PATCH 6/6] Add check fro trade limit and adjust if needed --- src/main/java/bisq/core/offer/OfferUtil.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/bisq/core/offer/OfferUtil.java b/src/main/java/bisq/core/offer/OfferUtil.java index 2f231fce..31aeb816 100644 --- a/src/main/java/bisq/core/offer/OfferUtil.java +++ b/src/main/java/bisq/core/offer/OfferUtil.java @@ -144,19 +144,26 @@ public static Volume getAdjustedVolumeForHalCash(Volume volumeByAmount) { return Volume.parse(String.valueOf(rounded * 10), "EUR"); } - public static Coin getAdjustedAmountForHalCash(Coin amount, Price price) { + public static Coin getAdjustedAmountForHalCash(Coin amount, Price price, long maxTradeLimit) { // Amount must result in a volume of min 10 EUR - Volume volume = Volume.parse(String.valueOf(10), "EUR"); - Coin amountByVolume = price.getAmountByVolume(volume); - if (amount.compareTo(amountByVolume) < 0) - amount = amountByVolume; + Volume volume10EUR = Volume.parse(String.valueOf(10), "EUR"); + Coin amountByVolume10EUR = price.getAmountByVolume(volume10EUR); + // We set min amount so it has a volume of 10 EUR + if (amount.compareTo(amountByVolume10EUR) < 0) + amount = amountByVolume10EUR; // We adjust the amount so that the volume is a multiple of 10 EUR - volume = getAdjustedVolumeForHalCash(price.getVolumeByAmount(amount)); + Volume volume = getAdjustedVolumeForHalCash(price.getVolumeByAmount(amount)); amount = price.getAmountByVolume(volume); // We want only 4 decimal places long rounded = Math.round((double) amount.value / 10000d) * 10000; + + if (rounded > maxTradeLimit) { + // If we are above out trade limit we reduce the amount by the correlating 10 EUR volume + rounded = Math.min(maxTradeLimit, rounded - amountByVolume10EUR.value); + } + return Coin.valueOf(rounded); } }