From a20449458bd5c8531109a019cc4b7f1bc066f204 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 21:05:34 -0500 Subject: [PATCH 01/30] Remove trailing spaces --- core/src/main/resources/btc_regtest.seednodes | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/resources/btc_regtest.seednodes b/core/src/main/resources/btc_regtest.seednodes index caa87710d68..148e6ecb9e0 100644 --- a/core/src/main/resources/btc_regtest.seednodes +++ b/core/src/main/resources/btc_regtest.seednodes @@ -1,4 +1,4 @@ -# By default developers use either port 2002 or 3002 or both as local seed nodes. If they want to use regtest +# By default developers use either port 2002 or 3002 or both as local seed nodes. If they want to use regtest # with Tor they have to add a program argument to pass the custom onion address of the local Tor seed node. # E.g. --seedNodes=YOUR_ONION.onion:2002 @@ -6,7 +6,7 @@ # 1. Run a seed node with prog args: --bitcoinNetwork=regtest --nodePort=2002 --appName=bisq_seed_node_localhost_YOUR_ONION # 2. Find your local onion address in bisq_seed_node_localhost_YOUR_ONION/regtest/tor/hiddenservice/hostname # 3. Shut down the seed node -# 4. Rename YOUR_ONION at the directory with your local onion address as well as the appName program argument to reflect +# 4. Rename YOUR_ONION at the directory with your local onion address as well as the appName program argument to reflect # the real onion address. # 5. Start the seed node again # 6. Start the Bisq app which wants to connect to that seed node with program argument `--seedNodes=YOUR_ONION.onion:2002` From f6b097235fdf32e22159a52b08a76177328b1f74 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 21:06:42 -0500 Subject: [PATCH 02/30] Add toProtoTradeStatistics2 method API will use getTradeStatistics and expect TradeStatistics2 not PersistableNetworkPayload --- .../core/trade/statistics/TradeStatistics2.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics2.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics2.java index feb0b6ed14d..601284f4e74 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics2.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics2.java @@ -171,8 +171,7 @@ public byte[] createHash() { return Hash.getSha256Ripemd160hash(Utilities.objectToJson(this).getBytes(Charsets.UTF_8)); } - @Override - public protobuf.PersistableNetworkPayload toProtoMessage() { + private protobuf.TradeStatistics2.Builder getBuilder() { final protobuf.TradeStatistics2.Builder builder = protobuf.TradeStatistics2.newBuilder() .setDirection(OfferPayload.Direction.toProtoMessage(direction)) .setBaseCurrency(baseCurrency) @@ -190,12 +189,16 @@ public protobuf.PersistableNetworkPayload toProtoMessage() { .setDepositTxId(depositTxId) .setHash(ByteString.copyFrom(hash)); Optional.ofNullable(extraDataMap).ifPresent(builder::putAllExtraData); - return protobuf.PersistableNetworkPayload.newBuilder().setTradeStatistics2(builder).build(); + return builder; } - public protobuf.TradeStatistics2 toProtoTradeStatistics2() { - return toProtoMessage().getTradeStatistics2(); + return getBuilder().build(); + } + + @Override + public protobuf.PersistableNetworkPayload toProtoMessage() { + return protobuf.PersistableNetworkPayload.newBuilder().setTradeStatistics2(getBuilder()).build(); } public static TradeStatistics2 fromProto(protobuf.TradeStatistics2 proto) { From 838113f986d5c4d7e27e64104ee2487451f19598 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 21:31:01 -0500 Subject: [PATCH 03/30] Add CreateOfferService class --- .../bisq/core/offer/CreateOfferService.java | 44 +++++++++++++++++++ .../main/offer/MutableOfferDataModel.java | 6 ++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/bisq/core/offer/CreateOfferService.java diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java new file mode 100644 index 00000000000..dc609912ec0 --- /dev/null +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -0,0 +1,44 @@ +/* + * 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.offer; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Singleton +public class CreateOfferService { + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor, Initialization + /////////////////////////////////////////////////////////////////////////////////////////// + + @Inject + public CreateOfferService() { + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // API + /////////////////////////////////////////////////////////////////////////////////////////// + + +} diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 97ff63c8f1c..7b3723385de 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -35,6 +35,7 @@ import bisq.core.locale.TradeCurrency; import bisq.core.monetary.Price; import bisq.core.monetary.Volume; +import bisq.core.offer.CreateOfferService; import bisq.core.offer.Offer; import bisq.core.offer.OfferPayload; import bisq.core.offer.OfferUtil; @@ -95,6 +96,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public abstract class MutableOfferDataModel extends OfferDataModel implements BsqBalanceListener { + private final CreateOfferService createOfferService; protected final OpenOfferManager openOfferManager; private final BsqWalletService bsqWalletService; private final Preferences preferences; @@ -149,7 +151,8 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public MutableOfferDataModel(OpenOfferManager openOfferManager, + public MutableOfferDataModel(CreateOfferService createOfferService, + OpenOfferManager openOfferManager, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, Preferences preferences, @@ -166,6 +169,7 @@ public MutableOfferDataModel(OpenOfferManager openOfferManager, MakerFeeProvider makerFeeProvider, Navigation navigation) { super(btcWalletService); + this.createOfferService = createOfferService; this.openOfferManager = openOfferManager; this.bsqWalletService = bsqWalletService; From bdf0d86fa4f9d0d3cd0d2583c61c3d9435e9e809 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 21:31:36 -0500 Subject: [PATCH 04/30] Remove commented out code --- .../main/offer/MutableOfferDataModel.java | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 7b3723385de..f9a9f671a44 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -201,28 +201,6 @@ public MutableOfferDataModel(CreateOfferService createOfferService, @Override public void onBalanceChanged(Coin balance, Transaction tx) { updateBalance(); - - /* if (isMainNet.get()) { - SettableFuture future = blockchainService.requestFee(tx.getHashAsString()); - Futures.addCallback(future, new FutureCallback() { - public void onSuccess(Coin fee) { - UserThread.execute(() -> feeFromFundingTxProperty.set(fee)); - } - - public void onFailure(@NotNull Throwable throwable) { - UserThread.execute(() -> new Popup<>() - .warning("We did not get a response for the request of the mining fee used " + - "in the funding transaction.\n\n" + - "Are you sure you used a sufficiently high fee of at least " + - formatter.formatCoinWithCode(FeePolicy.getMinRequiredFeeForFundingTx()) + "?") - .actionButtonText("Yes, I used a sufficiently high fee.") - .onAction(() -> feeFromFundingTxProperty.set(FeePolicy.getMinRequiredFeeForFundingTx())) - .closeButtonText("No. Let's cancel that payment.") - .onClose(() -> feeFromFundingTxProperty.set(Coin.ZERO)) - .show()); - } - }); - }*/ } }; From e30875eb15708f98365e2e2b5b3cd495a1236510 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 21:33:17 -0500 Subject: [PATCH 05/30] User weaker access, add final --- .../java/bisq/desktop/main/offer/MutableOfferDataModel.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index f9a9f671a44..e586d357982 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -111,7 +111,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs private final TxFeeEstimationService txFeeEstimationService; private final ReferralIdService referralIdService; private final BSFormatter btcFormatter; - private MakerFeeProvider makerFeeProvider; + private final MakerFeeProvider makerFeeProvider; private final Navigation navigation; private final String offerId; private final BalanceListener btcBalanceListener; @@ -133,7 +133,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs // Percentage value of buyer security deposit. E.g. 0.01 means 1% of trade amount protected final DoubleProperty buyerSecurityDeposit = new SimpleDoubleProperty(); - protected final DoubleProperty sellerSecurityDeposit = new SimpleDoubleProperty(); + private final DoubleProperty sellerSecurityDeposit = new SimpleDoubleProperty(); protected final ObservableList paymentAccounts = FXCollections.observableArrayList(); @@ -757,7 +757,7 @@ protected Coin getBuyerSecurityDepositAsCoin() { return getBoundedBuyerSecurityDepositAsCoin(percentOfAmountAsCoin); } - Coin getSellerSecurityDepositAsCoin() { + private Coin getSellerSecurityDepositAsCoin() { Coin amountAsCoin = this.amount.get(); if (amountAsCoin == null) amountAsCoin = Coin.ZERO; From 9865c80b9635cbb9939729caf4ca7f3da44ae441 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 21:34:14 -0500 Subject: [PATCH 06/30] Add getRandomOfferId method --- .../main/java/bisq/core/offer/CreateOfferService.java | 11 ++++++++++- .../desktop/main/offer/MutableOfferDataModel.java | 7 ++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index dc609912ec0..04704dd645e 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -17,9 +17,14 @@ package bisq.core.offer; +import bisq.common.app.Version; +import bisq.common.util.Utilities; + import javax.inject.Inject; import javax.inject.Singleton; +import java.util.UUID; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -40,5 +45,9 @@ public CreateOfferService() { // API /////////////////////////////////////////////////////////////////////////////////////////// - + public String getRandomOfferId() { + return Utilities.getRandomPrefix(5, 8) + "-" + + UUID.randomUUID().toString() + "-" + + Version.VERSION.replace(".", ""); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index e586d357982..f634a850473 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -89,7 +89,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.UUID; import javax.annotation.Nullable; @@ -169,8 +168,8 @@ public MutableOfferDataModel(CreateOfferService createOfferService, MakerFeeProvider makerFeeProvider, Navigation navigation) { super(btcWalletService); - this.createOfferService = createOfferService; + this.createOfferService = createOfferService; this.openOfferManager = openOfferManager; this.bsqWalletService = bsqWalletService; this.preferences = preferences; @@ -187,9 +186,7 @@ public MutableOfferDataModel(CreateOfferService createOfferService, this.makerFeeProvider = makerFeeProvider; this.navigation = navigation; - offerId = Utilities.getRandomPrefix(5, 8) + "-" + - UUID.randomUUID().toString() + "-" + - Version.VERSION.replace(".", ""); + offerId = createOfferService.getRandomOfferId(); shortOfferId = Utilities.getShortId(offerId); addressEntry = btcWalletService.getOrCreateAddressEntry(offerId, AddressEntry.Context.OFFER_FUNDING); From 15f986051322e03cb73a32ae6a6329d10bcb5d07 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 21:35:01 -0500 Subject: [PATCH 07/30] Add getSellerSecurityDeposit method --- core/src/main/java/bisq/core/offer/CreateOfferService.java | 7 +++++++ .../bisq/desktop/main/offer/MutableOfferDataModel.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 04704dd645e..8d18b538e75 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -17,6 +17,8 @@ package bisq.core.offer; +import bisq.core.btc.wallet.Restrictions; + import bisq.common.app.Version; import bisq.common.util.Utilities; @@ -50,4 +52,9 @@ public String getRandomOfferId() { UUID.randomUUID().toString() + "-" + Version.VERSION.replace(".", ""); } + + public double getSellerSecurityDeposit() { + return Restrictions.getSellerSecurityDepositAsPercent(); + } + } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index f634a850473..62c1bd396bd 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -192,7 +192,7 @@ public MutableOfferDataModel(CreateOfferService createOfferService, useMarketBasedPrice.set(preferences.isUsePercentageBasedPrice()); buyerSecurityDeposit.set(preferences.getBuyerSecurityDepositAsPercent(null)); - sellerSecurityDeposit.set(Restrictions.getSellerSecurityDepositAsPercent()); + sellerSecurityDeposit.set(createOfferService.getSellerSecurityDeposit()); btcBalanceListener = new BalanceListener(getAddressEntry().getAddress()) { @Override From 947fe5ae19194d398da0e46774d9750f2df909a5 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 21:53:59 -0500 Subject: [PATCH 08/30] Add getEstimatedFeeAndTxSize method - Rename estimateTxSize to updateEstimatedFeeAndTxSize - Add getEstimatedFeeAndTxSize method to CreateOfferService - Add dependent methods and fields --- .../bisq/core/offer/CreateOfferService.java | 95 ++++++++++++++++++- .../main/offer/MutableOfferDataModel.java | 12 +-- .../main/offer/MutableOfferViewModel.java | 2 +- 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 8d18b538e75..0f6cc5b39d9 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -17,11 +17,18 @@ package bisq.core.offer; +import bisq.core.btc.TxFeeEstimationService; +import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.Restrictions; +import bisq.core.user.Preferences; +import bisq.core.util.CoinUtil; import bisq.common.app.Version; +import bisq.common.util.Tuple2; import bisq.common.util.Utilities; +import org.bitcoinj.core.Coin; + import javax.inject.Inject; import javax.inject.Singleton; @@ -32,6 +39,10 @@ @Slf4j @Singleton public class CreateOfferService { + private final TxFeeEstimationService txFeeEstimationService; + private final MakerFeeProvider makerFeeProvider; + private final BsqWalletService bsqWalletService; + private final Preferences preferences; /////////////////////////////////////////////////////////////////////////////////////////// @@ -39,7 +50,15 @@ public class CreateOfferService { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public CreateOfferService() { + public CreateOfferService(TxFeeEstimationService txFeeEstimationService, + MakerFeeProvider makerFeeProvider, + BsqWalletService bsqWalletService, + Preferences preferences + ) { + this.txFeeEstimationService = txFeeEstimationService; + this.makerFeeProvider = makerFeeProvider; + this.bsqWalletService = bsqWalletService; + this.preferences = preferences; } @@ -57,4 +76,78 @@ public double getSellerSecurityDeposit() { return Restrictions.getSellerSecurityDepositAsPercent(); } + public Tuple2 getEstimatedFeeAndTxSize(Coin amount, + OfferPayload.Direction direction, + double buyerSecurityDeposit, + double sellerSecurityDeposit) { + Coin reservedFundsForOffer = getReservedFundsForOffer(direction, amount, buyerSecurityDeposit, sellerSecurityDeposit); + + return txFeeEstimationService.getEstimatedFeeAndTxSizeForMaker(reservedFundsForOffer, + getMakerFee(amount)); + } + + public Coin getReservedFundsForOffer(OfferPayload.Direction direction, + Coin amount, + double buyerSecurityDeposit, + double sellerSecurityDeposit) { + + Coin reservedFundsForOffer = getSecurityDeposit(direction, + amount, + buyerSecurityDeposit, + sellerSecurityDeposit); + if (!isBuyOffer(direction)) + reservedFundsForOffer = reservedFundsForOffer.add(amount); + + return reservedFundsForOffer; + } + + public Coin getSecurityDeposit(OfferPayload.Direction direction, + Coin amount, + double buyerSecurityDeposit, + double sellerSecurityDeposit) { + return isBuyOffer(direction) ? + getBuyerSecurityDepositAsCoin(amount, buyerSecurityDeposit) : + getSellerSecurityDepositAsCoin(amount, sellerSecurityDeposit); + } + + public Coin getMakerFee(Coin amount) { + return makerFeeProvider.getMakerFee(bsqWalletService, preferences, amount); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + + public boolean isBuyOffer(OfferPayload.Direction direction) { + return OfferUtil.isBuyOffer(direction); + } + + + private Coin getBuyerSecurityDepositAsCoin(Coin amount, double buyerSecurityDeposit) { + Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(buyerSecurityDeposit, amount); + return getBoundedBuyerSecurityDepositAsCoin(percentOfAmountAsCoin); + } + + private Coin getSellerSecurityDepositAsCoin(Coin amount, double sellerSecurityDeposit) { + Coin amountAsCoin = amount; + if (amountAsCoin == null) + amountAsCoin = Coin.ZERO; + + Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(sellerSecurityDeposit, amountAsCoin); + return getBoundedSellerSecurityDepositAsCoin(percentOfAmountAsCoin); + } + + + private Coin getBoundedBuyerSecurityDepositAsCoin(Coin value) { + // We need to ensure that for small amount values we don't get a too low BTC amount. We limit it with using the + // MinBuyerSecurityDepositAsCoin from Restrictions. + return Coin.valueOf(Math.max(Restrictions.getMinBuyerSecurityDepositAsCoin().value, value.value)); + } + + private Coin getBoundedSellerSecurityDepositAsCoin(Coin value) { + // We need to ensure that for small amount values we don't get a too low BTC amount. We limit it with using the + // MinSellerSecurityDepositAsCoin from Restrictions. + return Coin.valueOf(Math.max(Restrictions.getMinSellerSecurityDepositAsCoin().value, value.value)); + } } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 62c1bd396bd..8ae519ee6dd 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -390,13 +390,11 @@ Offer createAndGetOffer() { } // This works only if we have already funds in the wallet - public void estimateTxSize() { - Coin reservedFundsForOffer = getSecurityDeposit(); - if (!isBuyOffer()) - reservedFundsForOffer = reservedFundsForOffer.add(amount.get()); - - Tuple2 estimatedFeeAndTxSize = txFeeEstimationService.getEstimatedFeeAndTxSizeForMaker(reservedFundsForOffer, - getMakerFee()); + public void updateEstimatedFeeAndTxSize() { + Tuple2 estimatedFeeAndTxSize = createOfferService.getEstimatedFeeAndTxSize(amount.get(), + direction, + buyerSecurityDeposit.get(), + sellerSecurityDeposit.get()); txFeeFromFeeService = estimatedFeeAndTxSize.first; feeTxSize = estimatedFeeAndTxSize.second; } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java index 56aaeb922aa..203b8b5d089 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferViewModel.java @@ -681,7 +681,7 @@ public void onCurrencySelected(TradeCurrency tradeCurrency) { } void onShowPayFundsScreen(Runnable actionHandler) { - dataModel.estimateTxSize(); + dataModel.updateEstimatedFeeAndTxSize(); dataModel.requestTxFee(actionHandler); showPayFundsScreenDisplayed.set(true); updateSpinnerInfo(); From 8423845f3758ec07196633f8c7ee567951ade97f Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 22:03:53 -0500 Subject: [PATCH 09/30] Use methods from createOfferService - Use getBuyerSecurityDepositAsCoin and getSellerSecurityDepositAsCoin from CreateOfferService --- core/src/main/java/bisq/core/offer/CreateOfferService.java | 5 ++--- .../java/bisq/desktop/main/offer/MutableOfferDataModel.java | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 0f6cc5b39d9..a33ad87335f 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -123,13 +123,12 @@ public boolean isBuyOffer(OfferPayload.Direction direction) { return OfferUtil.isBuyOffer(direction); } - - private Coin getBuyerSecurityDepositAsCoin(Coin amount, double buyerSecurityDeposit) { + public Coin getBuyerSecurityDepositAsCoin(Coin amount, double buyerSecurityDeposit) { Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(buyerSecurityDeposit, amount); return getBoundedBuyerSecurityDepositAsCoin(percentOfAmountAsCoin); } - private Coin getSellerSecurityDepositAsCoin(Coin amount, double sellerSecurityDeposit) { + public Coin getSellerSecurityDepositAsCoin(Coin amount, double sellerSecurityDeposit) { Coin amountAsCoin = amount; if (amountAsCoin == null) amountAsCoin = Coin.ZERO; diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 8ae519ee6dd..861d79bbe09 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -346,6 +346,8 @@ Offer createAndGetOffer() { currencyCode, makerFeeAsCoin); + Coin buyerSecurityDepositAsCoin = createOfferService.getBuyerSecurityDepositAsCoin(amount.get(), buyerSecurityDeposit.get()); + Coin sellerSecurityDepositAsCoin = createOfferService.getSellerSecurityDepositAsCoin(amount.get(), sellerSecurityDeposit.get()); OfferPayload offerPayload = new OfferPayload(offerId, new Date().getTime(), p2PService.getAddress(), @@ -372,8 +374,8 @@ Offer createAndGetOffer() { txFeeFromFeeService.value, makerFeeAsCoin.value, isCurrencyForMakerFeeBtc(), - getBuyerSecurityDepositAsCoin().value, - getSellerSecurityDepositAsCoin().value, + buyerSecurityDepositAsCoin.value, + sellerSecurityDepositAsCoin.value, maxTradeLimit, maxTradePeriod, useAutoClose, From 8eea87ef3233022484d0a2da4867e6f81461a477 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 22:14:44 -0500 Subject: [PATCH 10/30] Use txFeeFromFeeService from createOfferService - Use getEstimatedFeeAndTxSize from CreateOfferService for txFeeFromFeeService --- core/src/main/java/bisq/core/offer/CreateOfferService.java | 4 +--- .../java/bisq/desktop/main/offer/MutableOfferDataModel.java | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index a33ad87335f..bba901fdd53 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -81,9 +81,7 @@ public Tuple2 getEstimatedFeeAndTxSize(Coin amount, double buyerSecurityDeposit, double sellerSecurityDeposit) { Coin reservedFundsForOffer = getReservedFundsForOffer(direction, amount, buyerSecurityDeposit, sellerSecurityDeposit); - - return txFeeEstimationService.getEstimatedFeeAndTxSizeForMaker(reservedFundsForOffer, - getMakerFee(amount)); + return txFeeEstimationService.getEstimatedFeeAndTxSizeForMaker(reservedFundsForOffer, getMakerFee(amount)); } public Coin getReservedFundsForOffer(OfferPayload.Direction direction, diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 861d79bbe09..408493b4c16 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -348,6 +348,7 @@ Offer createAndGetOffer() { Coin buyerSecurityDepositAsCoin = createOfferService.getBuyerSecurityDepositAsCoin(amount.get(), buyerSecurityDeposit.get()); Coin sellerSecurityDepositAsCoin = createOfferService.getSellerSecurityDepositAsCoin(amount.get(), sellerSecurityDeposit.get()); + Coin txFeeFromFeeService = createOfferService.getEstimatedFeeAndTxSize(amount.get(), direction, buyerSecurityDeposit.get(), sellerSecurityDeposit.get()).first; OfferPayload offerPayload = new OfferPayload(offerId, new Date().getTime(), p2PService.getAddress(), From 7d2016a83904d133223738e2a6cb4d5bc68831e4 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 22:34:22 -0500 Subject: [PATCH 11/30] Use getPriceAsLong from createOfferService --- .../bisq/core/offer/CreateOfferService.java | 37 ++++++++++++++++++- .../main/offer/MutableOfferDataModel.java | 4 +- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index bba901fdd53..000ccdd5c98 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -20,6 +20,11 @@ import bisq.core.btc.TxFeeEstimationService; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.Restrictions; +import bisq.core.monetary.Price; +import bisq.core.payment.HalCashAccount; +import bisq.core.payment.PaymentAccount; +import bisq.core.provider.price.MarketPrice; +import bisq.core.provider.price.PriceFeedService; import bisq.core.user.Preferences; import bisq.core.util.CoinUtil; @@ -43,6 +48,7 @@ public class CreateOfferService { private final MakerFeeProvider makerFeeProvider; private final BsqWalletService bsqWalletService; private final Preferences preferences; + private final PriceFeedService priceFeedService; /////////////////////////////////////////////////////////////////////////////////////////// @@ -53,12 +59,13 @@ public class CreateOfferService { public CreateOfferService(TxFeeEstimationService txFeeEstimationService, MakerFeeProvider makerFeeProvider, BsqWalletService bsqWalletService, - Preferences preferences - ) { + Preferences preferences, + PriceFeedService priceFeedService) { this.txFeeEstimationService = txFeeEstimationService; this.makerFeeProvider = makerFeeProvider; this.bsqWalletService = bsqWalletService; this.preferences = preferences; + this.priceFeedService = priceFeedService; } @@ -113,6 +120,32 @@ public Coin getMakerFee(Coin amount) { } + public long getPriceAsLong(Price price, + PaymentAccount paymentAccount, + boolean useMarketBasedPrice, + String currencyCode) { + boolean useMarketBasedPriceValue = isUseMarketBasedPriceValue(useMarketBasedPrice, currencyCode, paymentAccount); + return price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; + } + + private boolean isUseMarketBasedPriceValue(boolean useMarketBasedPrice, + String currencyCode, + PaymentAccount paymentAccount) { + return useMarketBasedPrice && + isMarketPriceAvailable(currencyCode) && + !isHalCashAccount(paymentAccount); + } + + private boolean isHalCashAccount(PaymentAccount paymentAccount) { + return paymentAccount instanceof HalCashAccount; + } + + private boolean isMarketPriceAvailable(String currencyCode) { + MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode); + return marketPrice != null && marketPrice.isExternallyProvidedPrice(); + } + + /////////////////////////////////////////////////////////////////////////////////////////// // Private /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 408493b4c16..abfeee78d85 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -304,7 +304,9 @@ void onTabSelected(boolean isSelected) { @SuppressWarnings("ConstantConditions") Offer createAndGetOffer() { boolean useMarketBasedPriceValue = isUseMarketBasedPriceValue(); - long priceAsLong = price.get() != null && !useMarketBasedPriceValue ? price.get().getValue() : 0L; + + long priceAsLong = createOfferService.getPriceAsLong(price.get(), paymentAccount, useMarketBasedPrice.get(), tradeCurrencyCode.get()); + String currencyCode = tradeCurrencyCode.get(); boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode); String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode(); From 646808623c46ce502eb747ca924eb156f86b54cc Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 22:41:53 -0500 Subject: [PATCH 12/30] Use marketPriceMarginParam from createOfferService --- .../main/java/bisq/core/offer/CreateOfferService.java | 11 ++++++++--- .../desktop/main/offer/MutableOfferDataModel.java | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 000ccdd5c98..3d9758c9675 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -128,14 +128,15 @@ public long getPriceAsLong(Price price, return price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; } - private boolean isUseMarketBasedPriceValue(boolean useMarketBasedPrice, - String currencyCode, - PaymentAccount paymentAccount) { + public boolean isUseMarketBasedPriceValue(boolean useMarketBasedPrice, + String currencyCode, + PaymentAccount paymentAccount) { return useMarketBasedPrice && isMarketPriceAvailable(currencyCode) && !isHalCashAccount(paymentAccount); } + private boolean isHalCashAccount(PaymentAccount paymentAccount) { return paymentAccount instanceof HalCashAccount; } @@ -145,6 +146,9 @@ private boolean isMarketPriceAvailable(String currencyCode) { return marketPrice != null && marketPrice.isExternallyProvidedPrice(); } + public double marketPriceMarginParam(boolean useMarketBasedPriceValue, double marketPriceMargin) { + return useMarketBasedPriceValue ? marketPriceMargin : 0; + } /////////////////////////////////////////////////////////////////////////////////////////// // Private @@ -180,4 +184,5 @@ private Coin getBoundedSellerSecurityDepositAsCoin(Coin value) { // MinSellerSecurityDepositAsCoin from Restrictions. return Coin.valueOf(Math.max(Restrictions.getMinSellerSecurityDepositAsCoin().value, value.value)); } + } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index abfeee78d85..1330322e242 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -303,7 +303,7 @@ void onTabSelected(boolean isSelected) { @SuppressWarnings("ConstantConditions") Offer createAndGetOffer() { - boolean useMarketBasedPriceValue = isUseMarketBasedPriceValue(); + boolean useMarketBasedPriceValue = createOfferService.isUseMarketBasedPriceValue(useMarketBasedPrice.get(), tradeCurrencyCode.get(), paymentAccount); long priceAsLong = createOfferService.getPriceAsLong(price.get(), paymentAccount, useMarketBasedPrice.get(), tradeCurrencyCode.get()); @@ -312,7 +312,8 @@ Offer createAndGetOffer() { String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode(); String counterCurrencyCode = isCryptoCurrency ? Res.getBaseCurrencyCode() : currencyCode; - double marketPriceMarginParam = useMarketBasedPriceValue ? marketPriceMargin : 0; + double marketPriceMarginParam = createOfferService.marketPriceMarginParam(useMarketBasedPriceValue, marketPriceMargin); + long amountAsLong = this.amount.get() != null ? this.amount.get().getValue() : 0L; long minAmountAsLong = this.minAmount.get() != null ? this.minAmount.get().getValue() : 0L; From b5848251017a9cfde0a790287a8cebf6b276fe6d Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 22:42:39 -0500 Subject: [PATCH 13/30] Pass useMarketBasedPriceValue to getPriceAsLong --- core/src/main/java/bisq/core/offer/CreateOfferService.java | 6 +----- .../java/bisq/desktop/main/offer/MutableOfferDataModel.java | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 3d9758c9675..3c9ef19348b 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -120,11 +120,7 @@ public Coin getMakerFee(Coin amount) { } - public long getPriceAsLong(Price price, - PaymentAccount paymentAccount, - boolean useMarketBasedPrice, - String currencyCode) { - boolean useMarketBasedPriceValue = isUseMarketBasedPriceValue(useMarketBasedPrice, currencyCode, paymentAccount); + public long getPriceAsLong(Price price, boolean useMarketBasedPriceValue) { return price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 1330322e242..a7caa00ae90 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -305,7 +305,7 @@ void onTabSelected(boolean isSelected) { Offer createAndGetOffer() { boolean useMarketBasedPriceValue = createOfferService.isUseMarketBasedPriceValue(useMarketBasedPrice.get(), tradeCurrencyCode.get(), paymentAccount); - long priceAsLong = createOfferService.getPriceAsLong(price.get(), paymentAccount, useMarketBasedPrice.get(), tradeCurrencyCode.get()); + long priceAsLong = createOfferService.getPriceAsLong(price.get(), useMarketBasedPriceValue); String currencyCode = tradeCurrencyCode.get(); boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode); From ef27dbd03db0400ad333fbd7f404b1b257a3972a Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 22:44:40 -0500 Subject: [PATCH 14/30] Use getMaxTradeLimit from createOfferService --- .../java/bisq/core/offer/CreateOfferService.java | 16 +++++++++++++++- .../main/offer/MutableOfferDataModel.java | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 3c9ef19348b..9be08b137e6 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -17,6 +17,7 @@ package bisq.core.offer; +import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.btc.TxFeeEstimationService; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.Restrictions; @@ -49,6 +50,7 @@ public class CreateOfferService { private final BsqWalletService bsqWalletService; private final Preferences preferences; private final PriceFeedService priceFeedService; + private final AccountAgeWitnessService accountAgeWitnessService; /////////////////////////////////////////////////////////////////////////////////////////// @@ -60,12 +62,14 @@ public CreateOfferService(TxFeeEstimationService txFeeEstimationService, MakerFeeProvider makerFeeProvider, BsqWalletService bsqWalletService, Preferences preferences, - PriceFeedService priceFeedService) { + PriceFeedService priceFeedService, + AccountAgeWitnessService accountAgeWitnessService) { this.txFeeEstimationService = txFeeEstimationService; this.makerFeeProvider = makerFeeProvider; this.bsqWalletService = bsqWalletService; this.preferences = preferences; this.priceFeedService = priceFeedService; + this.accountAgeWitnessService = accountAgeWitnessService; } @@ -146,6 +150,16 @@ public double marketPriceMarginParam(boolean useMarketBasedPriceValue, double ma return useMarketBasedPriceValue ? marketPriceMargin : 0; } + public long getMaxTradeLimit(PaymentAccount paymentAccount, + String currencyCode, + OfferPayload.Direction direction) { + if (paymentAccount != null) { + return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode, direction); + } else { + return 0; + } + } + /////////////////////////////////////////////////////////////////////////////////////////// // Private /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index a7caa00ae90..d1a2c48092d 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -322,7 +322,7 @@ Offer createAndGetOffer() { String bankId = PaymentAccountUtil.getBankId(paymentAccount); String countryCode = PaymentAccountUtil.getCountryCode(paymentAccount); - long maxTradeLimit = getMaxTradeLimit(); + long maxTradeLimit = createOfferService.getMaxTradeLimit(paymentAccount, tradeCurrencyCode.get(), direction); long maxTradePeriod = paymentAccount.getMaxTradePeriod(); // reserved for future use cases From c4b88ab512e7a7784bd3ab67557057432d6c8d56 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 22:56:42 -0500 Subject: [PATCH 15/30] Use createAndGetOffer from createOfferService --- .../bisq/core/offer/CreateOfferService.java | 141 +++++++++++++++++- .../main/offer/MutableOfferDataModel.java | 107 ++----------- 2 files changed, 149 insertions(+), 99 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 9be08b137e6..2796861bfeb 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -20,16 +20,26 @@ import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.btc.TxFeeEstimationService; import bisq.core.btc.wallet.BsqWalletService; +import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.Restrictions; +import bisq.core.filter.FilterManager; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.Res; import bisq.core.monetary.Price; import bisq.core.payment.HalCashAccount; import bisq.core.payment.PaymentAccount; +import bisq.core.payment.PaymentAccountUtil; import bisq.core.provider.price.MarketPrice; import bisq.core.provider.price.PriceFeedService; +import bisq.core.trade.statistics.ReferralIdService; import bisq.core.user.Preferences; +import bisq.core.user.User; import bisq.core.util.CoinUtil; +import bisq.network.p2p.P2PService; + import bisq.common.app.Version; +import bisq.common.crypto.PubKeyRing; import bisq.common.util.Tuple2; import bisq.common.util.Utilities; @@ -38,6 +48,11 @@ import javax.inject.Inject; import javax.inject.Singleton; +import com.google.common.collect.Lists; + +import java.util.Date; +import java.util.List; +import java.util.Map; import java.util.UUID; import lombok.extern.slf4j.Slf4j; @@ -51,6 +66,12 @@ public class CreateOfferService { private final Preferences preferences; private final PriceFeedService priceFeedService; private final AccountAgeWitnessService accountAgeWitnessService; + private final ReferralIdService referralIdService; + private final FilterManager filterManager; + private final P2PService p2PService; + private final PubKeyRing pubKeyRing; + private final User user; + private final BtcWalletService btcWalletService; /////////////////////////////////////////////////////////////////////////////////////////// @@ -63,13 +84,25 @@ public CreateOfferService(TxFeeEstimationService txFeeEstimationService, BsqWalletService bsqWalletService, Preferences preferences, PriceFeedService priceFeedService, - AccountAgeWitnessService accountAgeWitnessService) { + AccountAgeWitnessService accountAgeWitnessService, + ReferralIdService referralIdService, + FilterManager filterManager, + P2PService p2PService, + PubKeyRing pubKeyRing, + User user, + BtcWalletService btcWalletService) { this.txFeeEstimationService = txFeeEstimationService; this.makerFeeProvider = makerFeeProvider; this.bsqWalletService = bsqWalletService; this.preferences = preferences; this.priceFeedService = priceFeedService; this.accountAgeWitnessService = accountAgeWitnessService; + this.referralIdService = referralIdService; + this.filterManager = filterManager; + this.p2PService = p2PService; + this.pubKeyRing = pubKeyRing; + this.user = user; + this.btcWalletService = btcWalletService; } @@ -160,6 +193,108 @@ public long getMaxTradeLimit(PaymentAccount paymentAccount, } } + public Offer createAndGetOffer(String offerId, + OfferPayload.Direction direction, + String currencyCode, + Coin amount, + Coin minAmount, + boolean useMarketBasedPrice, + Price price, + double marketPriceMargin, + double buyerSecurityDeposit, + PaymentAccount paymentAccount) { + boolean useMarketBasedPriceValue = isUseMarketBasedPriceValue(useMarketBasedPrice, currencyCode, paymentAccount); + + long priceAsLong = getPriceAsLong(price, useMarketBasedPriceValue); + + boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode); + String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode(); + String counterCurrencyCode = isCryptoCurrency ? Res.getBaseCurrencyCode() : currencyCode; + + double marketPriceMarginParam = marketPriceMarginParam(useMarketBasedPriceValue, marketPriceMargin); + + long amountAsLong = amount != null ? amount.getValue() : 0L; + long minAmountAsLong = minAmount != null ? minAmount.getValue() : 0L; + + List acceptedCountryCodes = PaymentAccountUtil.getAcceptedCountryCodes(paymentAccount); + List acceptedBanks = PaymentAccountUtil.getAcceptedBanks(paymentAccount); + String bankId = PaymentAccountUtil.getBankId(paymentAccount); + String countryCode = PaymentAccountUtil.getCountryCode(paymentAccount); + + long maxTradeLimit = getMaxTradeLimit(paymentAccount, currencyCode, direction); + long maxTradePeriod = paymentAccount.getMaxTradePeriod(); + + // reserved for future use cases + // Use null values if not set + boolean isPrivateOffer = false; + boolean useAutoClose = false; + boolean useReOpenAfterAutoClose = false; + long lowerClosePrice = 0; + long upperClosePrice = 0; + String hashOfChallenge = null; + + Coin makerFeeAsCoin = getMakerFee(amount); + + Map extraDataMap = OfferUtil.getExtraDataMap(accountAgeWitnessService, + referralIdService, + paymentAccount, + currencyCode, + preferences); + + OfferUtil.validateOfferData(filterManager, + p2PService, + buyerSecurityDeposit, + paymentAccount, + currencyCode, + makerFeeAsCoin); + + Coin buyerSecurityDepositAsCoin = getBuyerSecurityDepositAsCoin(amount, buyerSecurityDeposit); + double sellerSecurityDeposit = getSellerSecurityDeposit(); + Coin sellerSecurityDepositAsCoin = getSellerSecurityDepositAsCoin(amount, getSellerSecurityDeposit()); + Coin txFeeFromFeeService = getEstimatedFeeAndTxSize(amount, direction, buyerSecurityDeposit, sellerSecurityDeposit).first; + OfferPayload offerPayload = new OfferPayload(offerId, + new Date().getTime(), + p2PService.getAddress(), + pubKeyRing, + OfferPayload.Direction.valueOf(direction.name()), + priceAsLong, + marketPriceMarginParam, + useMarketBasedPriceValue, + amountAsLong, + minAmountAsLong, + baseCurrencyCode, + counterCurrencyCode, + Lists.newArrayList(user.getAcceptedArbitratorAddresses()), + Lists.newArrayList(user.getAcceptedMediatorAddresses()), + paymentAccount.getPaymentMethod().getId(), + paymentAccount.getId(), + null, + countryCode, + acceptedCountryCodes, + bankId, + acceptedBanks, + Version.VERSION, + btcWalletService.getLastBlockSeenHeight(), + txFeeFromFeeService.value, + makerFeeAsCoin.value, + isCurrencyForMakerFeeBtc(amount), + buyerSecurityDepositAsCoin.value, + sellerSecurityDepositAsCoin.value, + maxTradeLimit, + maxTradePeriod, + useAutoClose, + useReOpenAfterAutoClose, + upperClosePrice, + lowerClosePrice, + isPrivateOffer, + hashOfChallenge, + extraDataMap, + Version.TRADE_PROTOCOL_VERSION); + Offer offer = new Offer(offerPayload); + offer.setPriceFeedService(priceFeedService); + return offer; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Private /////////////////////////////////////////////////////////////////////////////////////////// @@ -195,4 +330,8 @@ private Coin getBoundedSellerSecurityDepositAsCoin(Coin value) { return Coin.valueOf(Math.max(Restrictions.getMinSellerSecurityDepositAsCoin().value, value.value)); } + private boolean isCurrencyForMakerFeeBtc(Coin amount) { + return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); + } + } diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index d1a2c48092d..fdf5f7c8348 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -31,7 +31,6 @@ import bisq.core.btc.wallet.Restrictions; import bisq.core.filter.FilterManager; import bisq.core.locale.CurrencyUtil; -import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; import bisq.core.monetary.Price; import bisq.core.monetary.Volume; @@ -42,7 +41,6 @@ import bisq.core.offer.OpenOfferManager; import bisq.core.payment.HalCashAccount; import bisq.core.payment.PaymentAccount; -import bisq.core.payment.PaymentAccountUtil; import bisq.core.provider.fee.FeeService; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.handlers.TransactionResultHandler; @@ -54,7 +52,6 @@ import bisq.network.p2p.P2PService; -import bisq.common.app.Version; import bisq.common.crypto.KeyRing; import bisq.common.util.MathUtils; import bisq.common.util.Tuple2; @@ -65,8 +62,6 @@ import com.google.inject.Inject; -import com.google.common.collect.Lists; - import javafx.beans.property.BooleanProperty; import javafx.beans.property.DoubleProperty; import javafx.beans.property.ObjectProperty; @@ -84,10 +79,7 @@ import javafx.collections.ObservableList; import javafx.collections.SetChangeListener; -import java.util.Date; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Optional; import javax.annotation.Nullable; @@ -301,98 +293,17 @@ void onTabSelected(boolean isSelected) { // UI actions /////////////////////////////////////////////////////////////////////////////////////////// - @SuppressWarnings("ConstantConditions") Offer createAndGetOffer() { - boolean useMarketBasedPriceValue = createOfferService.isUseMarketBasedPriceValue(useMarketBasedPrice.get(), tradeCurrencyCode.get(), paymentAccount); - - long priceAsLong = createOfferService.getPriceAsLong(price.get(), useMarketBasedPriceValue); - - String currencyCode = tradeCurrencyCode.get(); - boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode); - String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode(); - String counterCurrencyCode = isCryptoCurrency ? Res.getBaseCurrencyCode() : currencyCode; - - double marketPriceMarginParam = createOfferService.marketPriceMarginParam(useMarketBasedPriceValue, marketPriceMargin); - - long amountAsLong = this.amount.get() != null ? this.amount.get().getValue() : 0L; - long minAmountAsLong = this.minAmount.get() != null ? this.minAmount.get().getValue() : 0L; - - List acceptedCountryCodes = PaymentAccountUtil.getAcceptedCountryCodes(paymentAccount); - List acceptedBanks = PaymentAccountUtil.getAcceptedBanks(paymentAccount); - String bankId = PaymentAccountUtil.getBankId(paymentAccount); - String countryCode = PaymentAccountUtil.getCountryCode(paymentAccount); - - long maxTradeLimit = createOfferService.getMaxTradeLimit(paymentAccount, tradeCurrencyCode.get(), direction); - long maxTradePeriod = paymentAccount.getMaxTradePeriod(); - - // reserved for future use cases - // Use null values if not set - boolean isPrivateOffer = false; - boolean useAutoClose = false; - boolean useReOpenAfterAutoClose = false; - long lowerClosePrice = 0; - long upperClosePrice = 0; - String hashOfChallenge = null; - - Coin makerFeeAsCoin = getMakerFee(); - - Map extraDataMap = OfferUtil.getExtraDataMap(accountAgeWitnessService, - referralIdService, - paymentAccount, - currencyCode, - preferences); - - OfferUtil.validateOfferData(filterManager, - p2PService, + return createOfferService.createAndGetOffer(offerId, + direction, + tradeCurrencyCode.get(), + amount.get(), + minAmount.get(), + useMarketBasedPrice.get(), + price.get(), + marketPriceMargin, buyerSecurityDeposit.get(), - paymentAccount, - currencyCode, - makerFeeAsCoin); - - Coin buyerSecurityDepositAsCoin = createOfferService.getBuyerSecurityDepositAsCoin(amount.get(), buyerSecurityDeposit.get()); - Coin sellerSecurityDepositAsCoin = createOfferService.getSellerSecurityDepositAsCoin(amount.get(), sellerSecurityDeposit.get()); - Coin txFeeFromFeeService = createOfferService.getEstimatedFeeAndTxSize(amount.get(), direction, buyerSecurityDeposit.get(), sellerSecurityDeposit.get()).first; - OfferPayload offerPayload = new OfferPayload(offerId, - new Date().getTime(), - p2PService.getAddress(), - keyRing.getPubKeyRing(), - OfferPayload.Direction.valueOf(direction.name()), - priceAsLong, - marketPriceMarginParam, - useMarketBasedPriceValue, - amountAsLong, - minAmountAsLong, - baseCurrencyCode, - counterCurrencyCode, - Lists.newArrayList(user.getAcceptedArbitratorAddresses()), - Lists.newArrayList(user.getAcceptedMediatorAddresses()), - paymentAccount.getPaymentMethod().getId(), - paymentAccount.getId(), - null, - countryCode, - acceptedCountryCodes, - bankId, - acceptedBanks, - Version.VERSION, - btcWalletService.getLastBlockSeenHeight(), - txFeeFromFeeService.value, - makerFeeAsCoin.value, - isCurrencyForMakerFeeBtc(), - buyerSecurityDepositAsCoin.value, - sellerSecurityDepositAsCoin.value, - maxTradeLimit, - maxTradePeriod, - useAutoClose, - useReOpenAfterAutoClose, - upperClosePrice, - lowerClosePrice, - isPrivateOffer, - hashOfChallenge, - extraDataMap, - Version.TRADE_PROTOCOL_VERSION); - Offer offer = new Offer(offerPayload); - offer.setPriceFeedService(priceFeedService); - return offer; + paymentAccount); } // This works only if we have already funds in the wallet From 2b1c754cfd657d7fd38a726f95c95db3982996af Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 22:57:53 -0500 Subject: [PATCH 16/30] Remove unused fields --- .../desktop/main/offer/MutableOfferDataModel.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index fdf5f7c8348..9fd749828d5 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -29,7 +29,6 @@ import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.Restrictions; -import bisq.core.filter.FilterManager; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; import bisq.core.monetary.Price; @@ -44,7 +43,6 @@ import bisq.core.provider.fee.FeeService; import bisq.core.provider.price.PriceFeedService; import bisq.core.trade.handlers.TransactionResultHandler; -import bisq.core.trade.statistics.ReferralIdService; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.BSFormatter; @@ -52,7 +50,6 @@ import bisq.network.p2p.P2PService; -import bisq.common.crypto.KeyRing; import bisq.common.util.MathUtils; import bisq.common.util.Tuple2; import bisq.common.util.Utilities; @@ -92,15 +89,11 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs private final BsqWalletService bsqWalletService; private final Preferences preferences; protected final User user; - private final KeyRing keyRing; private final P2PService p2PService; protected final PriceFeedService priceFeedService; final String shortOfferId; - private final FilterManager filterManager; private final AccountAgeWitnessService accountAgeWitnessService; private final FeeService feeService; - private final TxFeeEstimationService txFeeEstimationService; - private final ReferralIdService referralIdService; private final BSFormatter btcFormatter; private final MakerFeeProvider makerFeeProvider; private final Navigation navigation; @@ -148,14 +141,10 @@ public MutableOfferDataModel(CreateOfferService createOfferService, BsqWalletService bsqWalletService, Preferences preferences, User user, - KeyRing keyRing, P2PService p2PService, PriceFeedService priceFeedService, - FilterManager filterManager, AccountAgeWitnessService accountAgeWitnessService, FeeService feeService, - TxFeeEstimationService txFeeEstimationService, - ReferralIdService referralIdService, BSFormatter btcFormatter, MakerFeeProvider makerFeeProvider, Navigation navigation) { @@ -166,14 +155,10 @@ public MutableOfferDataModel(CreateOfferService createOfferService, this.bsqWalletService = bsqWalletService; this.preferences = preferences; this.user = user; - this.keyRing = keyRing; this.p2PService = p2PService; this.priceFeedService = priceFeedService; - this.filterManager = filterManager; this.accountAgeWitnessService = accountAgeWitnessService; this.feeService = feeService; - this.txFeeEstimationService = txFeeEstimationService; - this.referralIdService = referralIdService; this.btcFormatter = btcFormatter; this.makerFeeProvider = makerFeeProvider; this.navigation = navigation; From 0a58a2a2430c05d01277899cd189b562576698f3 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:02:44 -0500 Subject: [PATCH 17/30] Add createOfferService, remove unused params --- .../main/offer/createoffer/CreateOfferDataModel.java | 6 ++++-- .../main/portfolio/editoffer/EditOfferDataModel.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java index 06c2cfb42ea..a01b457cddb 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java @@ -52,7 +52,8 @@ class CreateOfferDataModel extends MutableOfferDataModel { @Inject - public CreateOfferDataModel(OpenOfferManager openOfferManager, + public CreateOfferDataModel(CreateOfferService createOfferService, + OpenOfferManager openOfferManager, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, Preferences preferences, @@ -68,7 +69,8 @@ public CreateOfferDataModel(OpenOfferManager openOfferManager, BSFormatter btcFormatter, MakerFeeProvider makerFeeProvider, Navigation navigation) { - super(openOfferManager, + super(createOfferService, + openOfferManager, btcWalletService, bsqWalletService, preferences, diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java index f5de8a4763b..73fd0f80522 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java @@ -61,7 +61,8 @@ class EditOfferDataModel extends MutableOfferDataModel { private OpenOffer.State initialState; @Inject - EditOfferDataModel(OpenOfferManager openOfferManager, + EditOfferDataModel(CreateOfferService createOfferService, + OpenOfferManager openOfferManager, BtcWalletService btcWalletService, BsqWalletService bsqWalletService, Preferences preferences, @@ -78,7 +79,8 @@ class EditOfferDataModel extends MutableOfferDataModel { CorePersistenceProtoResolver corePersistenceProtoResolver, MakerFeeProvider makerFeeProvider, Navigation navigation) { - super(openOfferManager, + super(createOfferService, + openOfferManager, btcWalletService, bsqWalletService, preferences, From 5c6b122d20a01f0c3167557038c18404625de8c0 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:03:02 -0500 Subject: [PATCH 18/30] Use weaker access --- .../desktop/main/offer/MutableOfferDataModel.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 9fd749828d5..537f8522b2f 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -122,7 +122,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs protected final ObservableList paymentAccounts = FXCollections.observableArrayList(); protected PaymentAccount paymentAccount; - protected boolean isTabSelected; + boolean isTabSelected; protected double marketPriceMargin = 0; private Coin txFeeFromFeeService = Coin.ZERO; private boolean marketPriceAvailable; @@ -418,7 +418,6 @@ void setPreferredCurrencyForMakerFeeBtc(boolean preferredCurrencyForMakerFeeBtc) // Getters /////////////////////////////////////////////////////////////////////////////////////////// - @SuppressWarnings("BooleanMethodIsAlwaysInverted") boolean isMinAmountLessOrEqualAmount() { //noinspection SimplifiableIfStatement if (minAmount.get() != null && amount.get() != null) @@ -579,7 +578,7 @@ public Coin getTxFee() { return txFeeFromFeeService.subtract(getMakerFee()); } - public void swapTradeToSavings() { + void swapTradeToSavings() { btcWalletService.resetAddressEntriesForOpenOffer(offerId); } @@ -679,7 +678,7 @@ ReadOnlyObjectProperty totalToPayAsCoinProperty() { return totalToPayAsCoin; } - public Coin getBsqBalance() { + Coin getBsqBalance() { return bsqWalletService.getAvailableConfirmedBalance(); } @@ -707,11 +706,11 @@ public boolean isCurrencyForMakerFeeBtc() { return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount.get()); } - public boolean isPreferredFeeCurrencyBtc() { + boolean isPreferredFeeCurrencyBtc() { return preferences.isPayFeeInBtc(); } - public boolean isBsqForFeeAvailable() { + boolean isBsqForFeeAvailable() { return OfferUtil.isBsqForMakerFeeAvailable(bsqWalletService, amount.get()); } @@ -719,7 +718,7 @@ public boolean isHalCashAccount() { return paymentAccount instanceof HalCashAccount; } - public boolean canPlaceOffer() { + boolean canPlaceOffer() { return GUIUtil.isBootstrappedOrShowPopup(p2PService) && GUIUtil.canCreateOrTakeOfferOrShowPopup(user, navigation); } From 35f0040e0ce045a377d83c86a2fb3373058f40d7 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:04:25 -0500 Subject: [PATCH 19/30] Add null checks --- .../java/bisq/core/offer/CreateOfferService.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 2796861bfeb..fc598044234 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -36,6 +36,7 @@ import bisq.core.user.User; import bisq.core.util.CoinUtil; +import bisq.network.p2p.NodeAddress; import bisq.network.p2p.P2PService; import bisq.common.app.Version; @@ -50,6 +51,7 @@ import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; @@ -252,6 +254,16 @@ public Offer createAndGetOffer(String offerId, double sellerSecurityDeposit = getSellerSecurityDeposit(); Coin sellerSecurityDepositAsCoin = getSellerSecurityDepositAsCoin(amount, getSellerSecurityDeposit()); Coin txFeeFromFeeService = getEstimatedFeeAndTxSize(amount, direction, buyerSecurityDeposit, sellerSecurityDeposit).first; + + List acceptedArbitratorAddresses = user.getAcceptedArbitratorAddresses(); + ArrayList arbitratorNodeAddresses = acceptedArbitratorAddresses != null ? + Lists.newArrayList(acceptedArbitratorAddresses) : + new ArrayList<>(); + List acceptedMediatorAddresses = user.getAcceptedMediatorAddresses(); + ArrayList mediatorNodeAddresses = acceptedMediatorAddresses != null ? + Lists.newArrayList(acceptedMediatorAddresses) : + new ArrayList<>(); + OfferPayload offerPayload = new OfferPayload(offerId, new Date().getTime(), p2PService.getAddress(), @@ -264,8 +276,8 @@ public Offer createAndGetOffer(String offerId, minAmountAsLong, baseCurrencyCode, counterCurrencyCode, - Lists.newArrayList(user.getAcceptedArbitratorAddresses()), - Lists.newArrayList(user.getAcceptedMediatorAddresses()), + arbitratorNodeAddresses, + mediatorNodeAddresses, paymentAccount.getPaymentMethod().getId(), paymentAccount.getId(), null, From fe52a33c5f4982d823534a5f0d6bd0b5ab860925 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:18:11 -0500 Subject: [PATCH 20/30] Add log of params, Cleanup --- .../bisq/core/offer/CreateOfferService.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index fc598044234..9c2982a8b03 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -158,7 +158,6 @@ public Coin getMakerFee(Coin amount) { return makerFeeProvider.getMakerFee(bsqWalletService, preferences, amount); } - public long getPriceAsLong(Price price, boolean useMarketBasedPriceValue) { return price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; } @@ -205,6 +204,34 @@ public Offer createAndGetOffer(String offerId, double marketPriceMargin, double buyerSecurityDeposit, PaymentAccount paymentAccount) { + + log.info("offerId={}, \n" + + "currencyCode={}, \n" + + "direction={}, \n" + + "price={}, \n" + + "useMarketBasedPrice={}, \n" + + "marketPriceMargin={}, \n" + + "amount={}, \n" + + "minAmount={}, \n" + + "buyerSecurityDeposit={}, \n" + + "paymentAccount={}, \n", + offerId, currencyCode, direction, price.getValue(), useMarketBasedPrice, marketPriceMargin, + amount.value, minAmount.value, buyerSecurityDeposit, paymentAccount); + + // prints our param list for dev testing api + log.info("{} " + + "{} " + + "{} " + + "{} " + + "{} " + + "{} " + + "{} " + + "{} " + + "{} " + + "{}", + offerId, currencyCode, direction.name(), price.getValue(), useMarketBasedPrice, marketPriceMargin, + amount.value, minAmount.value, buyerSecurityDeposit, paymentAccount.getId()); + boolean useMarketBasedPriceValue = isUseMarketBasedPriceValue(useMarketBasedPrice, currencyCode, paymentAccount); long priceAsLong = getPriceAsLong(price, useMarketBasedPriceValue); @@ -329,7 +356,6 @@ public Coin getSellerSecurityDepositAsCoin(Coin amount, double sellerSecurityDep return getBoundedSellerSecurityDepositAsCoin(percentOfAmountAsCoin); } - private Coin getBoundedBuyerSecurityDepositAsCoin(Coin value) { // We need to ensure that for small amount values we don't get a too low BTC amount. We limit it with using the // MinBuyerSecurityDepositAsCoin from Restrictions. @@ -345,5 +371,4 @@ private Coin getBoundedSellerSecurityDepositAsCoin(Coin value) { private boolean isCurrencyForMakerFeeBtc(Coin amount) { return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); } - } From 5ff5941cdb3b6c4b10323b4a697b0200b5393660 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:18:31 -0500 Subject: [PATCH 21/30] Remove unused fields --- .../java/bisq/desktop/main/offer/MutableOfferDataModel.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 537f8522b2f..3d29bc14414 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -105,10 +105,6 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs protected TradeCurrency tradeCurrency; protected final StringProperty tradeCurrencyCode = new SimpleStringProperty(); protected final BooleanProperty useMarketBasedPrice = new SimpleBooleanProperty(); - //final BooleanProperty isMainNet = new SimpleBooleanProperty(); - //final BooleanProperty isFeeFromFundingTxSufficient = new SimpleBooleanProperty(); - - // final ObjectProperty feeFromFundingTxProperty = new SimpleObjectProperty(Coin.NEGATIVE_SATOSHI); protected final ObjectProperty amount = new SimpleObjectProperty<>(); protected final ObjectProperty minAmount = new SimpleObjectProperty<>(); protected final ObjectProperty price = new SimpleObjectProperty<>(); From a881519857ea048cd6e87743bd1ea12508935371 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:21:34 -0500 Subject: [PATCH 22/30] Use weaker access --- .../bisq/core/offer/CreateOfferService.java | 160 +++++++++--------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 9c2982a8b03..36c5a2426fa 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -118,82 +118,6 @@ public String getRandomOfferId() { Version.VERSION.replace(".", ""); } - public double getSellerSecurityDeposit() { - return Restrictions.getSellerSecurityDepositAsPercent(); - } - - public Tuple2 getEstimatedFeeAndTxSize(Coin amount, - OfferPayload.Direction direction, - double buyerSecurityDeposit, - double sellerSecurityDeposit) { - Coin reservedFundsForOffer = getReservedFundsForOffer(direction, amount, buyerSecurityDeposit, sellerSecurityDeposit); - return txFeeEstimationService.getEstimatedFeeAndTxSizeForMaker(reservedFundsForOffer, getMakerFee(amount)); - } - - public Coin getReservedFundsForOffer(OfferPayload.Direction direction, - Coin amount, - double buyerSecurityDeposit, - double sellerSecurityDeposit) { - - Coin reservedFundsForOffer = getSecurityDeposit(direction, - amount, - buyerSecurityDeposit, - sellerSecurityDeposit); - if (!isBuyOffer(direction)) - reservedFundsForOffer = reservedFundsForOffer.add(amount); - - return reservedFundsForOffer; - } - - public Coin getSecurityDeposit(OfferPayload.Direction direction, - Coin amount, - double buyerSecurityDeposit, - double sellerSecurityDeposit) { - return isBuyOffer(direction) ? - getBuyerSecurityDepositAsCoin(amount, buyerSecurityDeposit) : - getSellerSecurityDepositAsCoin(amount, sellerSecurityDeposit); - } - - public Coin getMakerFee(Coin amount) { - return makerFeeProvider.getMakerFee(bsqWalletService, preferences, amount); - } - - public long getPriceAsLong(Price price, boolean useMarketBasedPriceValue) { - return price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; - } - - public boolean isUseMarketBasedPriceValue(boolean useMarketBasedPrice, - String currencyCode, - PaymentAccount paymentAccount) { - return useMarketBasedPrice && - isMarketPriceAvailable(currencyCode) && - !isHalCashAccount(paymentAccount); - } - - - private boolean isHalCashAccount(PaymentAccount paymentAccount) { - return paymentAccount instanceof HalCashAccount; - } - - private boolean isMarketPriceAvailable(String currencyCode) { - MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode); - return marketPrice != null && marketPrice.isExternallyProvidedPrice(); - } - - public double marketPriceMarginParam(boolean useMarketBasedPriceValue, double marketPriceMargin) { - return useMarketBasedPriceValue ? marketPriceMargin : 0; - } - - public long getMaxTradeLimit(PaymentAccount paymentAccount, - String currencyCode, - OfferPayload.Direction direction) { - if (paymentAccount != null) { - return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode, direction); - } else { - return 0; - } - } - public Offer createAndGetOffer(String offerId, OfferPayload.Direction direction, String currencyCode, @@ -334,20 +258,96 @@ public Offer createAndGetOffer(String offerId, return offer; } + public double getSellerSecurityDeposit() { + return Restrictions.getSellerSecurityDepositAsPercent(); + } + + public Tuple2 getEstimatedFeeAndTxSize(Coin amount, + OfferPayload.Direction direction, + double buyerSecurityDeposit, + double sellerSecurityDeposit) { + Coin reservedFundsForOffer = getReservedFundsForOffer(direction, amount, buyerSecurityDeposit, sellerSecurityDeposit); + return txFeeEstimationService.getEstimatedFeeAndTxSizeForMaker(reservedFundsForOffer, getMakerFee(amount)); + } + + public Coin getReservedFundsForOffer(OfferPayload.Direction direction, + Coin amount, + double buyerSecurityDeposit, + double sellerSecurityDeposit) { + + Coin reservedFundsForOffer = getSecurityDeposit(direction, + amount, + buyerSecurityDeposit, + sellerSecurityDeposit); + if (!isBuyOffer(direction)) + reservedFundsForOffer = reservedFundsForOffer.add(amount); + + return reservedFundsForOffer; + } + + public Coin getSecurityDeposit(OfferPayload.Direction direction, + Coin amount, + double buyerSecurityDeposit, + double sellerSecurityDeposit) { + return isBuyOffer(direction) ? + getBuyerSecurityDepositAsCoin(amount, buyerSecurityDeposit) : + getSellerSecurityDepositAsCoin(amount, sellerSecurityDeposit); + } + + public Coin getMakerFee(Coin amount) { + return makerFeeProvider.getMakerFee(bsqWalletService, preferences, amount); + } + + private boolean isHalCashAccount(PaymentAccount paymentAccount) { + return paymentAccount instanceof HalCashAccount; + } + + private boolean isMarketPriceAvailable(String currencyCode) { + MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode); + return marketPrice != null && marketPrice.isExternallyProvidedPrice(); + } + + public long getMaxTradeLimit(PaymentAccount paymentAccount, + String currencyCode, + OfferPayload.Direction direction) { + if (paymentAccount != null) { + return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode, direction); + } else { + return 0; + } + } + + public boolean isBuyOffer(OfferPayload.Direction direction) { + return OfferUtil.isBuyOffer(direction); + } + + /////////////////////////////////////////////////////////////////////////////////////////// // Private /////////////////////////////////////////////////////////////////////////////////////////// - public boolean isBuyOffer(OfferPayload.Direction direction) { - return OfferUtil.isBuyOffer(direction); + private double marketPriceMarginParam(boolean useMarketBasedPriceValue, double marketPriceMargin) { + return useMarketBasedPriceValue ? marketPriceMargin : 0; + } + + private long getPriceAsLong(Price price, boolean useMarketBasedPriceValue) { + return price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; + } + + private boolean isUseMarketBasedPriceValue(boolean useMarketBasedPrice, + String currencyCode, + PaymentAccount paymentAccount) { + return useMarketBasedPrice && + isMarketPriceAvailable(currencyCode) && + !isHalCashAccount(paymentAccount); } - public Coin getBuyerSecurityDepositAsCoin(Coin amount, double buyerSecurityDeposit) { + private Coin getBuyerSecurityDepositAsCoin(Coin amount, double buyerSecurityDeposit) { Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(buyerSecurityDeposit, amount); return getBoundedBuyerSecurityDepositAsCoin(percentOfAmountAsCoin); } - public Coin getSellerSecurityDepositAsCoin(Coin amount, double sellerSecurityDeposit) { + private Coin getSellerSecurityDepositAsCoin(Coin amount, double sellerSecurityDeposit) { Coin amountAsCoin = amount; if (amountAsCoin == null) amountAsCoin = Coin.ZERO; From 98c2601a361cd2e7020b734f1c17ec663039254b Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:24:38 -0500 Subject: [PATCH 23/30] Remove trivial methods --- .../bisq/core/offer/CreateOfferService.java | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 36c5a2426fa..fc08979cd4e 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -158,13 +158,13 @@ public Offer createAndGetOffer(String offerId, boolean useMarketBasedPriceValue = isUseMarketBasedPriceValue(useMarketBasedPrice, currencyCode, paymentAccount); - long priceAsLong = getPriceAsLong(price, useMarketBasedPriceValue); + long priceAsLong = price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode); String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode(); String counterCurrencyCode = isCryptoCurrency ? Res.getBaseCurrencyCode() : currencyCode; - double marketPriceMarginParam = marketPriceMarginParam(useMarketBasedPriceValue, marketPriceMargin); + double marketPriceMarginParam = useMarketBasedPriceValue ? marketPriceMargin : 0; long amountAsLong = amount != null ? amount.getValue() : 0L; long minAmountAsLong = minAmount != null ? minAmount.getValue() : 0L; @@ -258,10 +258,6 @@ public Offer createAndGetOffer(String offerId, return offer; } - public double getSellerSecurityDeposit() { - return Restrictions.getSellerSecurityDepositAsPercent(); - } - public Tuple2 getEstimatedFeeAndTxSize(Coin amount, OfferPayload.Direction direction, double buyerSecurityDeposit, @@ -294,17 +290,12 @@ public Coin getSecurityDeposit(OfferPayload.Direction direction, getSellerSecurityDepositAsCoin(amount, sellerSecurityDeposit); } - public Coin getMakerFee(Coin amount) { - return makerFeeProvider.getMakerFee(bsqWalletService, preferences, amount); - } - - private boolean isHalCashAccount(PaymentAccount paymentAccount) { - return paymentAccount instanceof HalCashAccount; + public double getSellerSecurityDeposit() { + return Restrictions.getSellerSecurityDepositAsPercent(); } - private boolean isMarketPriceAvailable(String currencyCode) { - MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode); - return marketPrice != null && marketPrice.isExternallyProvidedPrice(); + public Coin getMakerFee(Coin amount) { + return makerFeeProvider.getMakerFee(bsqWalletService, preferences, amount); } public long getMaxTradeLimit(PaymentAccount paymentAccount, @@ -326,12 +317,8 @@ public boolean isBuyOffer(OfferPayload.Direction direction) { // Private /////////////////////////////////////////////////////////////////////////////////////////// - private double marketPriceMarginParam(boolean useMarketBasedPriceValue, double marketPriceMargin) { - return useMarketBasedPriceValue ? marketPriceMargin : 0; - } - - private long getPriceAsLong(Price price, boolean useMarketBasedPriceValue) { - return price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; + private boolean isCurrencyForMakerFeeBtc(Coin amount) { + return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); } private boolean isUseMarketBasedPriceValue(boolean useMarketBasedPrice, @@ -342,6 +329,15 @@ private boolean isUseMarketBasedPriceValue(boolean useMarketBasedPrice, !isHalCashAccount(paymentAccount); } + private boolean isMarketPriceAvailable(String currencyCode) { + MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode); + return marketPrice != null && marketPrice.isExternallyProvidedPrice(); + } + + private boolean isHalCashAccount(PaymentAccount paymentAccount) { + return paymentAccount instanceof HalCashAccount; + } + private Coin getBuyerSecurityDepositAsCoin(Coin amount, double buyerSecurityDeposit) { Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(buyerSecurityDeposit, amount); return getBoundedBuyerSecurityDepositAsCoin(percentOfAmountAsCoin); @@ -367,8 +363,4 @@ private Coin getBoundedSellerSecurityDepositAsCoin(Coin value) { // MinSellerSecurityDepositAsCoin from Restrictions. return Coin.valueOf(Math.max(Restrictions.getMinSellerSecurityDepositAsCoin().value, value.value)); } - - private boolean isCurrencyForMakerFeeBtc(Coin amount) { - return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); - } } From 018cccfe032129a6dbbfe82a651d31ed86bf63d5 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:26:45 -0500 Subject: [PATCH 24/30] Remove trivial methods, rename methods --- .../bisq/core/offer/CreateOfferService.java | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index fc08979cd4e..675abd0e3e2 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -156,7 +156,9 @@ public Offer createAndGetOffer(String offerId, offerId, currencyCode, direction.name(), price.getValue(), useMarketBasedPrice, marketPriceMargin, amount.value, minAmount.value, buyerSecurityDeposit, paymentAccount.getId()); - boolean useMarketBasedPriceValue = isUseMarketBasedPriceValue(useMarketBasedPrice, currencyCode, paymentAccount); + boolean useMarketBasedPriceValue = useMarketBasedPrice && + isMarketPriceAvailable(currencyCode) && + !isHalCashAccount(paymentAccount); long priceAsLong = price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; @@ -201,10 +203,11 @@ public Offer createAndGetOffer(String offerId, currencyCode, makerFeeAsCoin); - Coin buyerSecurityDepositAsCoin = getBuyerSecurityDepositAsCoin(amount, buyerSecurityDeposit); + Coin buyerSecurityDepositAsCoin = getBuyerSecurityDeposit(amount, buyerSecurityDeposit); double sellerSecurityDeposit = getSellerSecurityDeposit(); - Coin sellerSecurityDepositAsCoin = getSellerSecurityDepositAsCoin(amount, getSellerSecurityDeposit()); + Coin sellerSecurityDepositAsCoin = getSellerSecurityDeposit(amount, getSellerSecurityDeposit()); Coin txFeeFromFeeService = getEstimatedFeeAndTxSize(amount, direction, buyerSecurityDeposit, sellerSecurityDeposit).first; + boolean isCurrencyForMakerFeeBtc = OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); List acceptedArbitratorAddresses = user.getAcceptedArbitratorAddresses(); ArrayList arbitratorNodeAddresses = acceptedArbitratorAddresses != null ? @@ -240,7 +243,7 @@ public Offer createAndGetOffer(String offerId, btcWalletService.getLastBlockSeenHeight(), txFeeFromFeeService.value, makerFeeAsCoin.value, - isCurrencyForMakerFeeBtc(amount), + isCurrencyForMakerFeeBtc, buyerSecurityDepositAsCoin.value, sellerSecurityDepositAsCoin.value, maxTradeLimit, @@ -286,8 +289,8 @@ public Coin getSecurityDeposit(OfferPayload.Direction direction, double buyerSecurityDeposit, double sellerSecurityDeposit) { return isBuyOffer(direction) ? - getBuyerSecurityDepositAsCoin(amount, buyerSecurityDeposit) : - getSellerSecurityDepositAsCoin(amount, sellerSecurityDeposit); + getBuyerSecurityDeposit(amount, buyerSecurityDeposit) : + getSellerSecurityDeposit(amount, sellerSecurityDeposit); } public double getSellerSecurityDeposit() { @@ -317,18 +320,6 @@ public boolean isBuyOffer(OfferPayload.Direction direction) { // Private /////////////////////////////////////////////////////////////////////////////////////////// - private boolean isCurrencyForMakerFeeBtc(Coin amount) { - return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); - } - - private boolean isUseMarketBasedPriceValue(boolean useMarketBasedPrice, - String currencyCode, - PaymentAccount paymentAccount) { - return useMarketBasedPrice && - isMarketPriceAvailable(currencyCode) && - !isHalCashAccount(paymentAccount); - } - private boolean isMarketPriceAvailable(String currencyCode) { MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode); return marketPrice != null && marketPrice.isExternallyProvidedPrice(); @@ -338,27 +329,27 @@ private boolean isHalCashAccount(PaymentAccount paymentAccount) { return paymentAccount instanceof HalCashAccount; } - private Coin getBuyerSecurityDepositAsCoin(Coin amount, double buyerSecurityDeposit) { + private Coin getBuyerSecurityDeposit(Coin amount, double buyerSecurityDeposit) { Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(buyerSecurityDeposit, amount); - return getBoundedBuyerSecurityDepositAsCoin(percentOfAmountAsCoin); + return getBoundedBuyerSecurityDeposit(percentOfAmountAsCoin); } - private Coin getSellerSecurityDepositAsCoin(Coin amount, double sellerSecurityDeposit) { + private Coin getSellerSecurityDeposit(Coin amount, double sellerSecurityDeposit) { Coin amountAsCoin = amount; if (amountAsCoin == null) amountAsCoin = Coin.ZERO; Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(sellerSecurityDeposit, amountAsCoin); - return getBoundedSellerSecurityDepositAsCoin(percentOfAmountAsCoin); + return getBoundedSellerSecurityDeposit(percentOfAmountAsCoin); } - private Coin getBoundedBuyerSecurityDepositAsCoin(Coin value) { + private Coin getBoundedBuyerSecurityDeposit(Coin value) { // We need to ensure that for small amount values we don't get a too low BTC amount. We limit it with using the // MinBuyerSecurityDepositAsCoin from Restrictions. return Coin.valueOf(Math.max(Restrictions.getMinBuyerSecurityDepositAsCoin().value, value.value)); } - private Coin getBoundedSellerSecurityDepositAsCoin(Coin value) { + private Coin getBoundedSellerSecurityDeposit(Coin value) { // We need to ensure that for small amount values we don't get a too low BTC amount. We limit it with using the // MinSellerSecurityDepositAsCoin from Restrictions. return Coin.valueOf(Math.max(Restrictions.getMinSellerSecurityDepositAsCoin().value, value.value)); From 84b49eda141e9188228572c1bcc8be641b39bc12 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:33:11 -0500 Subject: [PATCH 25/30] Sort params for offer as they are used --- .../bisq/core/offer/CreateOfferService.java | 53 ++++++++----------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 675abd0e3e2..1ced158e129 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -156,26 +156,37 @@ public Offer createAndGetOffer(String offerId, offerId, currencyCode, direction.name(), price.getValue(), useMarketBasedPrice, marketPriceMargin, amount.value, minAmount.value, buyerSecurityDeposit, paymentAccount.getId()); + long creationTime = new Date().getTime(); + NodeAddress makerAddress = p2PService.getAddress(); boolean useMarketBasedPriceValue = useMarketBasedPrice && isMarketPriceAvailable(currencyCode) && !isHalCashAccount(paymentAccount); long priceAsLong = price != null && !useMarketBasedPriceValue ? price.getValue() : 0L; - - boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode); - String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode(); - String counterCurrencyCode = isCryptoCurrency ? Res.getBaseCurrencyCode() : currencyCode; - double marketPriceMarginParam = useMarketBasedPriceValue ? marketPriceMargin : 0; - long amountAsLong = amount != null ? amount.getValue() : 0L; long minAmountAsLong = minAmount != null ? minAmount.getValue() : 0L; - + boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode); + String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode(); + String counterCurrencyCode = isCryptoCurrency ? Res.getBaseCurrencyCode() : currencyCode; + List acceptedArbitratorAddresses = user.getAcceptedArbitratorAddresses(); + ArrayList arbitratorNodeAddresses = acceptedArbitratorAddresses != null ? + Lists.newArrayList(acceptedArbitratorAddresses) : + new ArrayList<>(); + List acceptedMediatorAddresses = user.getAcceptedMediatorAddresses(); + ArrayList mediatorNodeAddresses = acceptedMediatorAddresses != null ? + Lists.newArrayList(acceptedMediatorAddresses) : + new ArrayList<>(); + String countryCode = PaymentAccountUtil.getCountryCode(paymentAccount); List acceptedCountryCodes = PaymentAccountUtil.getAcceptedCountryCodes(paymentAccount); - List acceptedBanks = PaymentAccountUtil.getAcceptedBanks(paymentAccount); String bankId = PaymentAccountUtil.getBankId(paymentAccount); - String countryCode = PaymentAccountUtil.getCountryCode(paymentAccount); - + List acceptedBanks = PaymentAccountUtil.getAcceptedBanks(paymentAccount); + double sellerSecurityDeposit = getSellerSecurityDeposit(); + Coin txFeeFromFeeService = getEstimatedFeeAndTxSize(amount, direction, buyerSecurityDeposit, sellerSecurityDeposit).first; + Coin makerFeeAsCoin = getMakerFee(amount); + boolean isCurrencyForMakerFeeBtc = OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); + Coin buyerSecurityDepositAsCoin = getBuyerSecurityDeposit(amount, buyerSecurityDeposit); + Coin sellerSecurityDepositAsCoin = getSellerSecurityDeposit(amount, getSellerSecurityDeposit()); long maxTradeLimit = getMaxTradeLimit(paymentAccount, currencyCode, direction); long maxTradePeriod = paymentAccount.getMaxTradePeriod(); @@ -187,9 +198,6 @@ public Offer createAndGetOffer(String offerId, long lowerClosePrice = 0; long upperClosePrice = 0; String hashOfChallenge = null; - - Coin makerFeeAsCoin = getMakerFee(amount); - Map extraDataMap = OfferUtil.getExtraDataMap(accountAgeWitnessService, referralIdService, paymentAccount, @@ -203,24 +211,9 @@ public Offer createAndGetOffer(String offerId, currencyCode, makerFeeAsCoin); - Coin buyerSecurityDepositAsCoin = getBuyerSecurityDeposit(amount, buyerSecurityDeposit); - double sellerSecurityDeposit = getSellerSecurityDeposit(); - Coin sellerSecurityDepositAsCoin = getSellerSecurityDeposit(amount, getSellerSecurityDeposit()); - Coin txFeeFromFeeService = getEstimatedFeeAndTxSize(amount, direction, buyerSecurityDeposit, sellerSecurityDeposit).first; - boolean isCurrencyForMakerFeeBtc = OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); - - List acceptedArbitratorAddresses = user.getAcceptedArbitratorAddresses(); - ArrayList arbitratorNodeAddresses = acceptedArbitratorAddresses != null ? - Lists.newArrayList(acceptedArbitratorAddresses) : - new ArrayList<>(); - List acceptedMediatorAddresses = user.getAcceptedMediatorAddresses(); - ArrayList mediatorNodeAddresses = acceptedMediatorAddresses != null ? - Lists.newArrayList(acceptedMediatorAddresses) : - new ArrayList<>(); - OfferPayload offerPayload = new OfferPayload(offerId, - new Date().getTime(), - p2PService.getAddress(), + creationTime, + makerAddress, pubKeyRing, OfferPayload.Direction.valueOf(direction.name()), priceAsLong, From 9c279f023f234a1f2402041009b94a899cd9e6a2 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:40:36 -0500 Subject: [PATCH 26/30] Use getReservedFundsForOffer from createOfferService --- .../bisq/desktop/main/offer/MutableOfferDataModel.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 3d29bc14414..5f1005f00f0 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -298,12 +298,12 @@ public void updateEstimatedFeeAndTxSize() { } void onPlaceOffer(Offer offer, TransactionResultHandler resultHandler) { - checkNotNull(getMakerFee(), "makerFee must not be null"); - - Coin reservedFundsForOffer = getSecurityDeposit(); - if (!isBuyOffer()) - reservedFundsForOffer = reservedFundsForOffer.add(amount.get()); + checkNotNull(offer.getMakerFee(), "makerFee must not be null"); + Coin reservedFundsForOffer = createOfferService.getReservedFundsForOffer(direction, + amount.get(), + buyerSecurityDeposit.get(), + sellerSecurityDeposit.get()); openOfferManager.placeOffer(offer, reservedFundsForOffer, useSavingsWallet, From 41535fb7d431764947b7bb8f9209f7658c394ba4 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:56:11 -0500 Subject: [PATCH 27/30] Add MakerFeeProvider --- .../bisq/core/offer/MakerFeeProvider.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 core/src/main/java/bisq/core/offer/MakerFeeProvider.java diff --git a/core/src/main/java/bisq/core/offer/MakerFeeProvider.java b/core/src/main/java/bisq/core/offer/MakerFeeProvider.java new file mode 100644 index 00000000000..dc2d0fbd7f2 --- /dev/null +++ b/core/src/main/java/bisq/core/offer/MakerFeeProvider.java @@ -0,0 +1,29 @@ +/* + * 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.offer; + +import bisq.core.btc.wallet.BsqWalletService; +import bisq.core.user.Preferences; + +import org.bitcoinj.core.Coin; + +public class MakerFeeProvider { + public Coin getMakerFee(BsqWalletService bsqWalletService, Preferences preferences, Coin amount) { + return OfferUtil.getMakerFee(bsqWalletService, preferences, amount); + } +} From 44781e1fbac205251cfdc8ed7a4a178937760f60 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:57:12 -0500 Subject: [PATCH 28/30] Adjust to new super class params --- .../offer/createoffer/CreateOfferDataModel.java | 14 +------------- .../portfolio/editoffer/EditOfferDataModel.java | 13 +------------ 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java index a01b457cddb..361ee6694cb 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java @@ -26,22 +26,18 @@ import bisq.desktop.main.offer.MutableOfferDataModel; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.btc.TxFeeEstimationService; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; -import bisq.core.filter.FilterManager; +import bisq.core.offer.CreateOfferService; import bisq.core.offer.OpenOfferManager; import bisq.core.provider.fee.FeeService; import bisq.core.provider.price.PriceFeedService; -import bisq.core.trade.statistics.ReferralIdService; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.BSFormatter; import bisq.network.p2p.P2PService; -import bisq.common.crypto.KeyRing; - import com.google.inject.Inject; /** @@ -58,14 +54,10 @@ public CreateOfferDataModel(CreateOfferService createOfferService, BsqWalletService bsqWalletService, Preferences preferences, User user, - KeyRing keyRing, P2PService p2PService, PriceFeedService priceFeedService, - FilterManager filterManager, AccountAgeWitnessService accountAgeWitnessService, FeeService feeService, - TxFeeEstimationService txFeeEstimationService, - ReferralIdService referralIdService, BSFormatter btcFormatter, MakerFeeProvider makerFeeProvider, Navigation navigation) { @@ -75,14 +67,10 @@ public CreateOfferDataModel(CreateOfferService createOfferService, bsqWalletService, preferences, user, - keyRing, p2PService, priceFeedService, - filterManager, accountAgeWitnessService, feeService, - txFeeEstimationService, - referralIdService, btcFormatter, makerFeeProvider, navigation); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java index 73fd0f80522..388dd13a9e6 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java @@ -23,13 +23,12 @@ import bisq.desktop.main.offer.MutableOfferDataModel; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.btc.TxFeeEstimationService; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.Restrictions; -import bisq.core.filter.FilterManager; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; +import bisq.core.offer.CreateOfferService; import bisq.core.offer.Offer; import bisq.core.offer.OfferPayload; import bisq.core.offer.OpenOffer; @@ -38,7 +37,6 @@ import bisq.core.proto.persistable.CorePersistenceProtoResolver; import bisq.core.provider.fee.FeeService; import bisq.core.provider.price.PriceFeedService; -import bisq.core.trade.statistics.ReferralIdService; import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.BSFormatter; @@ -46,7 +44,6 @@ import bisq.network.p2p.P2PService; -import bisq.common.crypto.KeyRing; import bisq.common.handlers.ErrorMessageHandler; import bisq.common.handlers.ResultHandler; @@ -67,14 +64,10 @@ class EditOfferDataModel extends MutableOfferDataModel { BsqWalletService bsqWalletService, Preferences preferences, User user, - KeyRing keyRing, P2PService p2PService, PriceFeedService priceFeedService, - FilterManager filterManager, AccountAgeWitnessService accountAgeWitnessService, FeeService feeService, - TxFeeEstimationService txFeeEstimationService, - ReferralIdService referralIdService, BSFormatter btcFormatter, CorePersistenceProtoResolver corePersistenceProtoResolver, MakerFeeProvider makerFeeProvider, @@ -85,14 +78,10 @@ class EditOfferDataModel extends MutableOfferDataModel { bsqWalletService, preferences, user, - keyRing, p2PService, priceFeedService, - filterManager, accountAgeWitnessService, feeService, - txFeeEstimationService, - referralIdService, btcFormatter, makerFeeProvider, navigation); From 50fc1393e086349229a653077d7e55c74f0145cd Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 14 Nov 2019 23:58:31 -0500 Subject: [PATCH 29/30] Remove sellerSecurityDeposit field, refactor placeOffer --- .../bisq/core/offer/CreateOfferService.java | 20 +++++++++---------- .../bisq/core/offer/OpenOfferManager.java | 14 +++++++++++-- .../main/offer/MutableOfferDataModel.java | 16 ++++----------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 1ced158e129..35475e4d77e 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -123,10 +123,10 @@ public Offer createAndGetOffer(String offerId, String currencyCode, Coin amount, Coin minAmount, - boolean useMarketBasedPrice, Price price, + boolean useMarketBasedPrice, double marketPriceMargin, - double buyerSecurityDeposit, + double buyerSecurityDepositAsDouble, PaymentAccount paymentAccount) { log.info("offerId={}, \n" + @@ -140,7 +140,7 @@ public Offer createAndGetOffer(String offerId, "buyerSecurityDeposit={}, \n" + "paymentAccount={}, \n", offerId, currencyCode, direction, price.getValue(), useMarketBasedPrice, marketPriceMargin, - amount.value, minAmount.value, buyerSecurityDeposit, paymentAccount); + amount.value, minAmount.value, buyerSecurityDepositAsDouble, paymentAccount); // prints our param list for dev testing api log.info("{} " + @@ -154,7 +154,7 @@ public Offer createAndGetOffer(String offerId, "{} " + "{}", offerId, currencyCode, direction.name(), price.getValue(), useMarketBasedPrice, marketPriceMargin, - amount.value, minAmount.value, buyerSecurityDeposit, paymentAccount.getId()); + amount.value, minAmount.value, buyerSecurityDepositAsDouble, paymentAccount.getId()); long creationTime = new Date().getTime(); NodeAddress makerAddress = p2PService.getAddress(); @@ -181,12 +181,12 @@ public Offer createAndGetOffer(String offerId, List acceptedCountryCodes = PaymentAccountUtil.getAcceptedCountryCodes(paymentAccount); String bankId = PaymentAccountUtil.getBankId(paymentAccount); List acceptedBanks = PaymentAccountUtil.getAcceptedBanks(paymentAccount); - double sellerSecurityDeposit = getSellerSecurityDeposit(); - Coin txFeeFromFeeService = getEstimatedFeeAndTxSize(amount, direction, buyerSecurityDeposit, sellerSecurityDeposit).first; + double sellerSecurityDeposit = getSellerSecurityDepositAsDouble(); + Coin txFeeFromFeeService = getEstimatedFeeAndTxSize(amount, direction, buyerSecurityDepositAsDouble, sellerSecurityDeposit).first; Coin makerFeeAsCoin = getMakerFee(amount); boolean isCurrencyForMakerFeeBtc = OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); - Coin buyerSecurityDepositAsCoin = getBuyerSecurityDeposit(amount, buyerSecurityDeposit); - Coin sellerSecurityDepositAsCoin = getSellerSecurityDeposit(amount, getSellerSecurityDeposit()); + Coin buyerSecurityDepositAsCoin = getBuyerSecurityDeposit(amount, buyerSecurityDepositAsDouble); + Coin sellerSecurityDepositAsCoin = getSellerSecurityDeposit(amount, sellerSecurityDeposit); long maxTradeLimit = getMaxTradeLimit(paymentAccount, currencyCode, direction); long maxTradePeriod = paymentAccount.getMaxTradePeriod(); @@ -206,7 +206,7 @@ public Offer createAndGetOffer(String offerId, OfferUtil.validateOfferData(filterManager, p2PService, - buyerSecurityDeposit, + buyerSecurityDepositAsDouble, paymentAccount, currencyCode, makerFeeAsCoin); @@ -286,7 +286,7 @@ public Coin getSecurityDeposit(OfferPayload.Direction direction, getSellerSecurityDeposit(amount, sellerSecurityDeposit); } - public double getSellerSecurityDeposit() { + public double getSellerSecurityDepositAsDouble() { return Restrictions.getSellerSecurityDepositAsPercent(); } diff --git a/core/src/main/java/bisq/core/offer/OpenOfferManager.java b/core/src/main/java/bisq/core/offer/OpenOfferManager.java index 1212a7313e2..bc0c3c8fb0e 100644 --- a/core/src/main/java/bisq/core/offer/OpenOfferManager.java +++ b/core/src/main/java/bisq/core/offer/OpenOfferManager.java @@ -94,6 +94,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe private static final long REPUBLISH_INTERVAL_MS = TimeUnit.MINUTES.toMillis(40); private static final long REFRESH_INTERVAL_MS = TimeUnit.MINUTES.toMillis(6); + private final CreateOfferService createOfferService; private final KeyRing keyRing; private final User user; private final P2PService p2PService; @@ -121,7 +122,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public OpenOfferManager(KeyRing keyRing, + public OpenOfferManager(CreateOfferService createOfferService, + KeyRing keyRing, User user, P2PService p2PService, BtcWalletService btcWalletService, @@ -137,6 +139,7 @@ public OpenOfferManager(KeyRing keyRing, RefundAgentManager refundAgentManager, DaoFacade daoFacade, Storage> storage) { + this.createOfferService = createOfferService; this.keyRing = keyRing; this.user = user; this.p2PService = p2PService; @@ -335,10 +338,17 @@ public void onAwakeFromStandby() { /////////////////////////////////////////////////////////////////////////////////////////// public void placeOffer(Offer offer, - Coin reservedFundsForOffer, + double buyerSecurityDeposit, boolean useSavingsWallet, TransactionResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) { + checkNotNull(offer.getMakerFee(), "makerFee must not be null"); + + Coin reservedFundsForOffer = createOfferService.getReservedFundsForOffer(offer.getDirection(), + offer.getAmount(), + buyerSecurityDeposit, + createOfferService.getSellerSecurityDepositAsDouble()); + PlaceOfferModel model = new PlaceOfferModel(offer, reservedFundsForOffer, useSavingsWallet, diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 5f1005f00f0..f28fc1f38fd 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -113,7 +113,6 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs // Percentage value of buyer security deposit. E.g. 0.01 means 1% of trade amount protected final DoubleProperty buyerSecurityDeposit = new SimpleDoubleProperty(); - private final DoubleProperty sellerSecurityDeposit = new SimpleDoubleProperty(); protected final ObservableList paymentAccounts = FXCollections.observableArrayList(); @@ -165,7 +164,6 @@ public MutableOfferDataModel(CreateOfferService createOfferService, useMarketBasedPrice.set(preferences.isUsePercentageBasedPrice()); buyerSecurityDeposit.set(preferences.getBuyerSecurityDepositAsPercent(null)); - sellerSecurityDeposit.set(createOfferService.getSellerSecurityDeposit()); btcBalanceListener = new BalanceListener(getAddressEntry().getAddress()) { @Override @@ -280,8 +278,8 @@ Offer createAndGetOffer() { tradeCurrencyCode.get(), amount.get(), minAmount.get(), - useMarketBasedPrice.get(), price.get(), + useMarketBasedPrice.get(), marketPriceMargin, buyerSecurityDeposit.get(), paymentAccount); @@ -292,20 +290,14 @@ public void updateEstimatedFeeAndTxSize() { Tuple2 estimatedFeeAndTxSize = createOfferService.getEstimatedFeeAndTxSize(amount.get(), direction, buyerSecurityDeposit.get(), - sellerSecurityDeposit.get()); + createOfferService.getSellerSecurityDepositAsDouble()); txFeeFromFeeService = estimatedFeeAndTxSize.first; feeTxSize = estimatedFeeAndTxSize.second; } void onPlaceOffer(Offer offer, TransactionResultHandler resultHandler) { - checkNotNull(offer.getMakerFee(), "makerFee must not be null"); - - Coin reservedFundsForOffer = createOfferService.getReservedFundsForOffer(direction, - amount.get(), - buyerSecurityDeposit.get(), - sellerSecurityDeposit.get()); openOfferManager.placeOffer(offer, - reservedFundsForOffer, + buyerSecurityDeposit.get(), useSavingsWallet, resultHandler, log::error); @@ -654,7 +646,7 @@ private Coin getSellerSecurityDepositAsCoin() { if (amountAsCoin == null) amountAsCoin = Coin.ZERO; - Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(sellerSecurityDeposit.get(), amountAsCoin); + Coin percentOfAmountAsCoin = CoinUtil.getPercentOfAmountAsCoin(createOfferService.getSellerSecurityDepositAsDouble(), amountAsCoin); return getBoundedSellerSecurityDepositAsCoin(percentOfAmountAsCoin); } From 909216070083f2f2e08a80eba949129d78933b34 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Fri, 15 Nov 2019 00:03:52 -0500 Subject: [PATCH 30/30] Adjust tests to new params --- .../bisq/core/offer/OpenOfferManagerTest.java | 6 +++--- .../createoffer/CreateOfferDataModelTest.java | 13 +++++++------ .../createoffer/CreateOfferViewModelTest.java | 15 +++++++++------ .../editoffer/EditOfferDataModelTest.java | 11 ++++++++--- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java b/core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java index c80ea13e0e1..db2f334ded6 100644 --- a/core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java +++ b/core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java @@ -37,7 +37,7 @@ public void testStartEditOfferForActiveOffer() { when(p2PService.getPeerManager()).thenReturn(mock(PeerManager.class)); - final OpenOfferManager manager = new OpenOfferManager(null, null, p2PService, + final OpenOfferManager manager = new OpenOfferManager(null, null, null, p2PService, null, null, null, offerBookService, null, null, null, null, null, null, null, null, @@ -73,7 +73,7 @@ public void testStartEditOfferForDeactivatedOffer() { when(p2PService.getPeerManager()).thenReturn(mock(PeerManager.class)); - final OpenOfferManager manager = new OpenOfferManager(null, null, p2PService, + final OpenOfferManager manager = new OpenOfferManager(null, null, null, p2PService, null, null, null, offerBookService, null, null, null, null, null, null, null, null, @@ -101,7 +101,7 @@ public void testStartEditOfferForOfferThatIsCurrentlyEdited() { when(p2PService.getPeerManager()).thenReturn(mock(PeerManager.class)); - final OpenOfferManager manager = new OpenOfferManager(null, null, p2PService, + final OpenOfferManager manager = new OpenOfferManager(null, null, null, p2PService, null, null, null, offerBookService, null, null, null, null, null, null, null, null, diff --git a/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModelTest.java index e588735a914..4d58655dcc9 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModelTest.java @@ -2,13 +2,13 @@ import bisq.desktop.main.offer.MakerFeeProvider; -import bisq.core.btc.TxFeeEstimationService; import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.locale.CryptoCurrency; import bisq.core.locale.FiatCurrency; import bisq.core.locale.GlobalSettings; import bisq.core.locale.Res; +import bisq.core.offer.CreateOfferService; import bisq.core.offer.OfferPayload; import bisq.core.payment.ClearXchangeAccount; import bisq.core.payment.PaymentAccount; @@ -21,6 +21,7 @@ import org.bitcoinj.core.Coin; import java.util.HashSet; +import java.util.UUID; import org.junit.Before; import org.junit.Test; @@ -48,20 +49,20 @@ public void setUp() { BtcWalletService btcWalletService = mock(BtcWalletService.class); PriceFeedService priceFeedService = mock(PriceFeedService.class); FeeService feeService = mock(FeeService.class); - TxFeeEstimationService feeEstimationService = mock(TxFeeEstimationService.class); + CreateOfferService createOfferService = mock(CreateOfferService.class); preferences = mock(Preferences.class); user = mock(User.class); when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry); when(preferences.isUsePercentageBasedPrice()).thenReturn(true); when(preferences.getBuyerSecurityDepositAsPercent(null)).thenReturn(0.01); + when(createOfferService.getRandomOfferId()).thenReturn(UUID.randomUUID().toString()); makerFeeProvider = mock(MakerFeeProvider.class); - model = new CreateOfferDataModel(null, btcWalletService, + model = new CreateOfferDataModel(createOfferService, null, btcWalletService, null, preferences, user, null, - null, priceFeedService, null, - null, feeService, feeEstimationService, - null, null, makerFeeProvider, null); + priceFeedService, null, + feeService, null, makerFeeProvider, null); } @Test diff --git a/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java index 515126304ca..149f39a892b 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java @@ -24,7 +24,6 @@ import bisq.desktop.util.validation.SecurityDepositValidator; import bisq.core.account.witness.AccountAgeWitnessService; -import bisq.core.btc.TxFeeEstimationService; import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; @@ -32,6 +31,7 @@ import bisq.core.locale.CryptoCurrency; import bisq.core.locale.GlobalSettings; import bisq.core.locale.Res; +import bisq.core.offer.CreateOfferService; import bisq.core.offer.OfferPayload; import bisq.core.payment.PaymentAccount; import bisq.core.provider.fee.FeeService; @@ -51,6 +51,8 @@ import java.time.Instant; +import java.util.UUID; + import org.junit.Before; import org.junit.Test; @@ -89,7 +91,7 @@ public void setUp() { BsqWalletService bsqWalletService = mock(BsqWalletService.class); SecurityDepositValidator securityDepositValidator = mock(SecurityDepositValidator.class); AccountAgeWitnessService accountAgeWitnessService = mock(AccountAgeWitnessService.class); - TxFeeEstimationService txFeeEstimationService = mock(TxFeeEstimationService.class); + CreateOfferService createOfferService = mock(CreateOfferService.class); when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry); when(btcWalletService.getBalanceForAddress(any())).thenReturn(Coin.valueOf(1000L)); @@ -103,11 +105,12 @@ public void setUp() { when(preferences.getUserCountry()).thenReturn(new Country("ES", "Spain", null)); when(bsqFormatter.formatCoin(any())).thenReturn("0"); when(bsqWalletService.getAvailableConfirmedBalance()).thenReturn(Coin.ZERO); + when(createOfferService.getRandomOfferId()).thenReturn(UUID.randomUUID().toString()); - CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, - bsqWalletService, empty, user, null, null, priceFeedService, null, - accountAgeWitnessService, feeService, txFeeEstimationService, - null, bsFormatter, mock(MakerFeeProvider.class), null); + CreateOfferDataModel dataModel = new CreateOfferDataModel(createOfferService, null, btcWalletService, + bsqWalletService, empty, user, null, priceFeedService, + accountAgeWitnessService, feeService, + bsFormatter, mock(MakerFeeProvider.class), null); dataModel.initWithData(OfferPayload.Direction.BUY, new CryptoCurrency("BTC", "bitcoin")); dataModel.activate(); diff --git a/desktop/src/test/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModelTest.java b/desktop/src/test/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModelTest.java index d95ba36bc70..2ee6a5bfde4 100644 --- a/desktop/src/test/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModelTest.java @@ -11,6 +11,7 @@ import bisq.core.locale.CryptoCurrency; import bisq.core.locale.GlobalSettings; import bisq.core.locale.Res; +import bisq.core.offer.CreateOfferService; import bisq.core.offer.OfferPayload; import bisq.core.offer.OpenOffer; import bisq.core.payment.CryptoCurrencyAccount; @@ -32,6 +33,8 @@ import java.time.Instant; +import java.util.UUID; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -75,6 +78,7 @@ public void setUp() { BsqWalletService bsqWalletService = mock(BsqWalletService.class); SecurityDepositValidator securityDepositValidator = mock(SecurityDepositValidator.class); AccountAgeWitnessService accountAgeWitnessService = mock(AccountAgeWitnessService.class); + CreateOfferService createOfferService = mock(CreateOfferService.class); when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry); when(btcWalletService.getBalanceForAddress(any())).thenReturn(Coin.valueOf(1000L)); @@ -88,12 +92,13 @@ public void setUp() { when(preferences.getUserCountry()).thenReturn(new Country("US", "United States", null)); when(bsqFormatter.formatCoin(any())).thenReturn("0"); when(bsqWalletService.getAvailableConfirmedBalance()).thenReturn(Coin.ZERO); + when(createOfferService.getRandomOfferId()).thenReturn(UUID.randomUUID().toString()); - model = new EditOfferDataModel(null, + model = new EditOfferDataModel(createOfferService, null, btcWalletService, bsqWalletService, empty, user, - null, null, priceFeedService, null, + null, priceFeedService, accountAgeWitnessService, feeService, null, null, - null, null, mock(MakerFeeProvider.class), null); + mock(MakerFeeProvider.class), null); } @Test