From b7fb3df0d41ad01a42d66b87a034817f1c1ea95e Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Thu, 3 Mar 2022 16:19:00 -0300 Subject: [PATCH 1/2] Move get (cryptocurrency) offer filter to daemon Some API reference & Python bot examples exposed an API bug the Java CLI has been hiding. Due due this Bisq v1 Offer entity design: - In fiat offers, the baseCurrencyCode=BTC, counterCurrencyCode=FiatCode - In altcoin offers, baseCurrencyCode=AltcoinCode, counterCurrencyCode=BTC, new API examples were not doing what the CLI has been doing for several months, which is get (cryptocurrency) all BTC offers from the server, and filter on the altcoin code. The CLI side filtering should have been done on the server, as it is in this commit. A lot of dead gRPC client side offer filtering code is removed as well. Based on `master`. --- .../method/offer/CreateBSQOffersTest.java | 4 +- .../method/offer/CreateXMROffersTest.java | 4 +- .../method/trade/FailUnfailTradeTest.java | 12 ++-- .../method/trade/TakeBuyBSQOfferTest.java | 4 +- .../method/trade/TakeBuyXMROfferTest.java | 4 +- .../method/trade/TakeSellBSQOfferTest.java | 4 +- .../method/trade/TakeSellXMROfferTest.java | 4 +- cli/src/main/java/bisq/cli/GrpcClient.java | 45 +----------- .../cli/request/OffersServiceRequest.java | 72 ++++--------------- .../test/java/bisq/cli/AbstractCliTest.java | 2 +- .../java/bisq/core/api/CoreOffersService.java | 61 +++++++++++++--- .../core/api/CorePaymentAccountsService.java | 7 +- .../java/bisq/core/locale/CurrencyUtil.java | 13 ++++ 13 files changed, 101 insertions(+), 135 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java index 1807d1000b5..efa832b9a2a 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java @@ -260,7 +260,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() { @Test @Order(5) public void testGetAllMyBsqOffers() { - List offers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(BSQ); + List offers = aliceClient.getMyOffersSortedByDate(BSQ); log.debug("All Alice's BSQ Offers:\n{}", toOffersTable.apply(offers)); assertEquals(4, offers.size()); log.debug("ALICE'S BALANCES\n{}", formatBalancesTbls(aliceClient.getBalances())); @@ -269,7 +269,7 @@ public void testGetAllMyBsqOffers() { @Test @Order(6) public void testGetAvailableBsqOffers() { - List offers = bobClient.getCryptoCurrencyOffersSortedByDate(BSQ); + List offers = bobClient.getOffersSortedByDate(BSQ); log.debug("All Bob's Available BSQ Offers:\n{}", toOffersTable.apply(offers)); assertEquals(4, offers.size()); log.debug("BOB'S BALANCES\n{}", formatBalancesTbls(bobClient.getBalances())); diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java index cb9db33a145..615eda0d160 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java @@ -257,7 +257,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() { @Test @Order(5) public void testGetAllMyXMROffers() { - List offers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(XMR); + List offers = aliceClient.getMyOffersSortedByDate(XMR); log.debug("All of Alice's XMR offers:\n{}", toOffersTable.apply(offers)); assertEquals(4, offers.size()); log.debug("Alice's balances\n{}", formatBalancesTbls(aliceClient.getBalances())); @@ -266,7 +266,7 @@ public void testGetAllMyXMROffers() { @Test @Order(6) public void testGetAvailableXMROffers() { - List offers = bobClient.getCryptoCurrencyOffersSortedByDate(XMR); + List offers = bobClient.getOffersSortedByDate(XMR); log.debug("All of Bob's available XMR offers:\n{}", toOffersTable.apply(offers)); assertEquals(4, offers.size()); log.debug("Bob's balances\n{}", formatBalancesTbls(bobClient.getBalances())); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/FailUnfailTradeTest.java b/apitest/src/test/java/bisq/apitest/method/trade/FailUnfailTradeTest.java index 5985ea81285..6d6105ab22e 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/FailUnfailTradeTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/FailUnfailTradeTest.java @@ -61,7 +61,7 @@ public void testFailAndUnFailBuyBTCTrade(final TestInfo testInfo) { TakeBuyBTCOfferTest test = new TakeBuyBTCOfferTest(); test.testTakeAlicesBuyOffer(testInfo); - var tradeId = test.getTradeId(); + var tradeId = AbstractTradeTest.getTradeId(); aliceClient.failTrade(tradeId); Throwable exception = assertThrows(StatusRuntimeException.class, () -> aliceClient.getTrade(tradeId)); @@ -82,7 +82,7 @@ public void testFailAndUnFailSellBTCTrade(final TestInfo testInfo) { TakeSellBTCOfferTest test = new TakeSellBTCOfferTest(); test.testTakeAlicesSellOffer(testInfo); - var tradeId = test.getTradeId(); + var tradeId = AbstractTradeTest.getTradeId(); aliceClient.failTrade(tradeId); Throwable exception = assertThrows(StatusRuntimeException.class, () -> aliceClient.getTrade(tradeId)); @@ -101,10 +101,10 @@ public void testFailAndUnFailSellBTCTrade(final TestInfo testInfo) { @Order(3) public void testFailAndUnFailBuyXmrTrade(final TestInfo testInfo) { TakeBuyXMROfferTest test = new TakeBuyXMROfferTest(); - test.createXmrPaymentAccounts(); + createXmrPaymentAccounts(); test.testTakeAlicesSellBTCForXMROffer(testInfo); - var tradeId = test.getTradeId(); + var tradeId = AbstractTradeTest.getTradeId(); aliceClient.failTrade(tradeId); Throwable exception = assertThrows(StatusRuntimeException.class, () -> aliceClient.getTrade(tradeId)); @@ -123,10 +123,10 @@ public void testFailAndUnFailBuyXmrTrade(final TestInfo testInfo) { @Order(4) public void testFailAndUnFailTakeSellXMRTrade(final TestInfo testInfo) { TakeSellXMROfferTest test = new TakeSellXMROfferTest(); - test.createXmrPaymentAccounts(); + createXmrPaymentAccounts(); test.testTakeAlicesBuyBTCForXMROffer(testInfo); - var tradeId = test.getTradeId(); + var tradeId = AbstractTradeTest.getTradeId(); aliceClient.failTrade(tradeId); Throwable exception = assertThrows(StatusRuntimeException.class, () -> aliceClient.getTrade(tradeId)); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java index a2ae7eda575..1425e7182cd 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java @@ -83,7 +83,7 @@ public void testTakeAlicesSellBTCForBSQOffer(final TestInfo testInfo) { var offerId = alicesOffer.getId(); assertFalse(alicesOffer.getIsCurrencyForMakerFeeBtc()); - var alicesBsqOffers = aliceClient.getMyCryptoCurrencyOffers(btcTradeDirection, BSQ); + var alicesBsqOffers = aliceClient.getMyOffers(btcTradeDirection, BSQ); assertEquals(1, alicesBsqOffers.size()); var trade = takeAlicesOffer(offerId, @@ -97,7 +97,7 @@ public void testTakeAlicesSellBTCForBSQOffer(final TestInfo testInfo) { tradeId = trade.getTradeId(); genBtcBlocksThenWait(1, 2_500); - alicesBsqOffers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(BSQ); + alicesBsqOffers = aliceClient.getMyOffersSortedByDate(BSQ); assertEquals(0, alicesBsqOffers.size()); waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java index 65bb62be7fc..da7d448c773 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java @@ -84,10 +84,10 @@ public void testTakeAlicesSellBTCForXMROffer(final TestInfo testInfo) { var offerId = alicesOffer.getId(); assertFalse(alicesOffer.getIsCurrencyForMakerFeeBtc()); - var alicesXmrOffers = aliceClient.getMyCryptoCurrencyOffers(btcTradeDirection, XMR); + var alicesXmrOffers = aliceClient.getMyOffers(btcTradeDirection, XMR); assertEquals(1, alicesXmrOffers.size()); var trade = takeAlicesOffer(offerId, bobsXmrAcct.getId(), TRADE_FEE_CURRENCY_CODE); - alicesXmrOffers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(XMR); + alicesXmrOffers = aliceClient.getMyOffersSortedByDate(XMR); assertEquals(0, alicesXmrOffers.size()); genBtcBlocksThenWait(1, 2_500); waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java index 71e89e36402..f7cf59cc899 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java @@ -84,14 +84,14 @@ public void testTakeAlicesBuyBTCForBSQOffer(final TestInfo testInfo) { genBtcBlocksThenWait(1, 4_000); var offerId = alicesOffer.getId(); assertTrue(alicesOffer.getIsCurrencyForMakerFeeBtc()); - var alicesBsqOffers = aliceClient.getMyCryptoCurrencyOffers(btcTradeDirection, BSQ); + var alicesBsqOffers = aliceClient.getMyOffers(btcTradeDirection, BSQ); assertEquals(1, alicesBsqOffers.size()); var trade = takeAlicesOffer(offerId, bobsLegacyBsqAcct.getId(), TRADE_FEE_CURRENCY_CODE, false); sleep(2_500); // Allow available offer to be removed from offer book. - alicesBsqOffers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(BSQ); + alicesBsqOffers = aliceClient.getMyOffersSortedByDate(BSQ); assertEquals(0, alicesBsqOffers.size()); genBtcBlocksThenWait(1, 2_500); waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java index 49b03395eb1..6b884f5bff4 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java @@ -88,10 +88,10 @@ public void testTakeAlicesBuyBTCForXMROffer(final TestInfo testInfo) { var offerId = alicesOffer.getId(); assertTrue(alicesOffer.getIsCurrencyForMakerFeeBtc()); - var alicesXmrOffers = aliceClient.getMyCryptoCurrencyOffers(btcTradeDirection, XMR); + var alicesXmrOffers = aliceClient.getMyOffers(btcTradeDirection, XMR); assertEquals(1, alicesXmrOffers.size()); var trade = takeAlicesOffer(offerId, bobsXmrAcct.getId(), TRADE_FEE_CURRENCY_CODE); - alicesXmrOffers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(XMR); + alicesXmrOffers = aliceClient.getMyOffersSortedByDate(XMR); assertEquals(0, alicesXmrOffers.size()); genBtcBlocksThenWait(1, 2_500); diff --git a/cli/src/main/java/bisq/cli/GrpcClient.java b/cli/src/main/java/bisq/cli/GrpcClient.java index bf9b20888da..ab9484f350a 100644 --- a/cli/src/main/java/bisq/cli/GrpcClient.java +++ b/cli/src/main/java/bisq/cli/GrpcClient.java @@ -27,7 +27,6 @@ import bisq.proto.grpc.OfferInfo; import bisq.proto.grpc.RegisterDisputeAgentRequest; import bisq.proto.grpc.StopRequest; -import bisq.proto.grpc.TakeOfferReply; import bisq.proto.grpc.TradeInfo; import bisq.proto.grpc.TxFeeRateInfo; import bisq.proto.grpc.TxInfo; @@ -271,10 +270,6 @@ public OfferInfo getOffer(String offerId) { return offersServiceRequest.getOffer(offerId); } - public OfferInfo getMyBsqSwapOffer(String offerId) { - return offersServiceRequest.getMyBsqSwapOffer(offerId); - } - @Deprecated // Since 5-Dec-2021. // Endpoint to be removed from future version. Use getOffer service method instead. public OfferInfo getMyOffer(String offerId) { @@ -289,10 +284,6 @@ public List getOffers(String direction, String currencyCode) { return offersServiceRequest.getOffers(direction, currencyCode); } - public List getCryptoCurrencyOffers(String direction, String currencyCode) { - return offersServiceRequest.getCryptoCurrencyOffers(direction, currencyCode); - } - public List getOffersSortedByDate(String currencyCode) { return offersServiceRequest.getOffersSortedByDate(currencyCode); } @@ -301,58 +292,26 @@ public List getOffersSortedByDate(String direction, String currencyCo return offersServiceRequest.getOffersSortedByDate(direction, currencyCode); } - public List getCryptoCurrencyOffersSortedByDate(String currencyCode) { - return offersServiceRequest.getCryptoCurrencyOffersSortedByDate(currencyCode); - } - public List getBsqSwapOffersSortedByDate() { return offersServiceRequest.getBsqSwapOffersSortedByDate(); } - public List getMyBsqSwapOffers(String direction) { - return offersServiceRequest.getMyBsqSwapOffers(direction); - } - public List getMyOffers(String direction, String currencyCode) { return offersServiceRequest.getMyOffers(direction, currencyCode); } - public List getMyCryptoCurrencyOffers(String direction, String currencyCode) { - return offersServiceRequest.getMyCryptoCurrencyOffers(direction, currencyCode); - } - - public List getMyOffersSortedByDate(String direction, String currencyCode) { - return offersServiceRequest.getMyOffersSortedByDate(direction, currencyCode); - } - public List getMyOffersSortedByDate(String currencyCode) { return offersServiceRequest.getMyOffersSortedByDate(currencyCode); } - public List getMyCryptoCurrencyOffersSortedByDate(String currencyCode) { - return offersServiceRequest.getMyCryptoCurrencyOffersSortedByDate(currencyCode); + public List getMyOffersSortedByDate(String direction, String currencyCode) { + return offersServiceRequest.getMyOffersSortedByDate(direction, currencyCode); } public List getMyBsqSwapBsqOffersSortedByDate() { return offersServiceRequest.getMyBsqSwapOffersSortedByDate(); } - public OfferInfo getMostRecentOffer(String direction, String currencyCode) { - return offersServiceRequest.getMostRecentOffer(direction, currencyCode); - } - - public List sortBsqSwapOffersByDate(List offers) { - return offersServiceRequest.sortOffersByDate(offers); - } - - public List sortOffersByDate(List offers) { - return offersServiceRequest.sortOffersByDate(offers); - } - - public TakeOfferReply getTakeOfferReply(String offerId, String paymentAccountId, String takerFeeCurrencyCode) { - return tradesServiceRequest.getTakeOfferReply(offerId, paymentAccountId, takerFeeCurrencyCode); - } - public TradeInfo takeBsqSwapOffer(String offerId) { return tradesServiceRequest.takeBsqSwapOffer(offerId); } diff --git a/cli/src/main/java/bisq/cli/request/OffersServiceRequest.java b/cli/src/main/java/bisq/cli/request/OffersServiceRequest.java index 65b62f05838..20f6158f2b6 100644 --- a/cli/src/main/java/bisq/cli/request/OffersServiceRequest.java +++ b/cli/src/main/java/bisq/cli/request/OffersServiceRequest.java @@ -32,7 +32,6 @@ import java.util.ArrayList; import java.util.List; -import static bisq.cli.CryptoCurrencyUtil.apiDoesSupportCryptoCurrency; import static bisq.proto.grpc.EditOfferRequest.EditType.ACTIVATION_STATE_ONLY; import static bisq.proto.grpc.EditOfferRequest.EditType.FIXED_PRICE_ONLY; import static bisq.proto.grpc.EditOfferRequest.EditType.MKT_PRICE_MARGIN_ONLY; @@ -217,13 +216,6 @@ public OfferInfo getOffer(String offerId) { return grpcStubs.offersService.getOffer(request).getOffer(); } - public OfferInfo getMyBsqSwapOffer(String offerId) { - var request = GetMyOfferRequest.newBuilder() - .setId(offerId) - .build(); - return grpcStubs.offersService.getMyBsqSwapOffer(request).getBsqSwapOffer(); - } - public OfferInfo getMyOffer(String offerId) { var request = GetMyOfferRequest.newBuilder() .setId(offerId) @@ -240,28 +232,18 @@ public List getBsqSwapOffers(String direction) { } public List getOffers(String direction, String currencyCode) { - if (apiDoesSupportCryptoCurrency(currencyCode)) { - return getCryptoCurrencyOffers(direction, currencyCode); - } else { - var request = GetOffersRequest.newBuilder() - .setDirection(direction) - .setCurrencyCode(currencyCode) - .build(); - return grpcStubs.offersService.getOffers(request).getOffersList(); - } - } - - public List getCryptoCurrencyOffers(String direction, String currencyCode) { - return getOffers(direction, "BTC").stream() - .filter(o -> o.getBaseCurrencyCode().equalsIgnoreCase(currencyCode)) - .collect(toList()); + var request = GetOffersRequest.newBuilder() + .setDirection(direction) + .setCurrencyCode(currencyCode) + .build(); + return grpcStubs.offersService.getOffers(request).getOffersList(); } public List getOffersSortedByDate(String currencyCode) { ArrayList offers = new ArrayList<>(); offers.addAll(getOffers(BUY.name(), currencyCode)); offers.addAll(getOffers(SELL.name(), currencyCode)); - return sortOffersByDate(offers); + return offers.isEmpty() ? offers : sortOffersByDate(offers); } public List getOffersSortedByDate(String direction, String currencyCode) { @@ -269,13 +251,6 @@ public List getOffersSortedByDate(String direction, String currencyCo return offers.isEmpty() ? offers : sortOffersByDate(offers); } - public List getCryptoCurrencyOffersSortedByDate(String currencyCode) { - ArrayList offers = new ArrayList<>(); - offers.addAll(getCryptoCurrencyOffers(BUY.name(), currencyCode)); - offers.addAll(getCryptoCurrencyOffers(SELL.name(), currencyCode)); - return sortOffersByDate(offers); - } - public List getBsqSwapOffersSortedByDate() { ArrayList offers = new ArrayList<>(); offers.addAll(getBsqSwapOffers(BUY.name())); @@ -291,40 +266,23 @@ public List getMyBsqSwapOffers(String direction) { } public List getMyOffers(String direction, String currencyCode) { - if (apiDoesSupportCryptoCurrency(currencyCode)) { - return getMyCryptoCurrencyOffers(direction, currencyCode); - } else { - var request = GetMyOffersRequest.newBuilder() - .setDirection(direction) - .setCurrencyCode(currencyCode) - .build(); - return grpcStubs.offersService.getMyOffers(request).getOffersList(); - } - } - - public List getMyCryptoCurrencyOffers(String direction, String currencyCode) { - return getMyOffers(direction, "BTC").stream() - .filter(o -> o.getBaseCurrencyCode().equalsIgnoreCase(currencyCode)) - .collect(toList()); - } - - public List getMyOffersSortedByDate(String direction, String currencyCode) { - var offers = getMyOffers(direction, currencyCode); - return offers.isEmpty() ? offers : sortOffersByDate(offers); + var request = GetMyOffersRequest.newBuilder() + .setDirection(direction) + .setCurrencyCode(currencyCode) + .build(); + return grpcStubs.offersService.getMyOffers(request).getOffersList(); } public List getMyOffersSortedByDate(String currencyCode) { ArrayList offers = new ArrayList<>(); offers.addAll(getMyOffers(BUY.name(), currencyCode)); offers.addAll(getMyOffers(SELL.name(), currencyCode)); - return sortOffersByDate(offers); + return offers.isEmpty() ? offers : sortOffersByDate(offers); } - public List getMyCryptoCurrencyOffersSortedByDate(String currencyCode) { - ArrayList offers = new ArrayList<>(); - offers.addAll(getMyCryptoCurrencyOffers(BUY.name(), currencyCode)); - offers.addAll(getMyCryptoCurrencyOffers(SELL.name(), currencyCode)); - return sortOffersByDate(offers); + public List getMyOffersSortedByDate(String direction, String currencyCode) { + var offers = getMyOffers(direction, currencyCode); + return offers.isEmpty() ? offers : sortOffersByDate(offers); } public List getMyBsqSwapOffersSortedByDate() { diff --git a/cli/src/test/java/bisq/cli/AbstractCliTest.java b/cli/src/test/java/bisq/cli/AbstractCliTest.java index a0367ed2602..8fc279295fb 100644 --- a/cli/src/test/java/bisq/cli/AbstractCliTest.java +++ b/cli/src/test/java/bisq/cli/AbstractCliTest.java @@ -135,7 +135,7 @@ protected List getMyAltcoinOffers(String currencyCode) { CliMain.main(args); out.println("<<<<<"); - return aliceClient.getMyCryptoCurrencyOffersSortedByDate(currencyCode); + return aliceClient.getMyOffersSortedByDate(currencyCode); } protected String[] getMyOffersCommand(String direction, String currencyCode) { diff --git a/core/src/main/java/bisq/core/api/CoreOffersService.java b/core/src/main/java/bisq/core/api/CoreOffersService.java index 4fdd8495738..e4c640da117 100644 --- a/core/src/main/java/bisq/core/api/CoreOffersService.java +++ b/core/src/main/java/bisq/core/api/CoreOffersService.java @@ -59,7 +59,9 @@ import static bisq.common.util.MathUtils.exactMultiply; import static bisq.common.util.MathUtils.roundDoubleToLong; import static bisq.common.util.MathUtils.scaleUpByPowerOf10; +import static bisq.core.locale.CurrencyUtil.apiSupportsCryptoCurrency; import static bisq.core.locale.CurrencyUtil.isCryptoCurrency; +import static bisq.core.locale.CurrencyUtil.isFiatCurrency; import static bisq.core.offer.Offer.State; import static bisq.core.offer.OfferDirection.BUY; import static bisq.core.offer.OfferUtil.getRandomOfferId; @@ -203,20 +205,57 @@ List getBsqSwapOffers(String direction) { } List getOffers(String direction, String currencyCode) { - return offerBookService.getOffers().stream() - .filter(o -> !o.isMyOffer(keyRing)) - .filter(o -> offerMatchesDirectionAndCurrency(o, direction, currencyCode)) - .filter(o -> offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid()) - .sorted(priceComparator(direction)) - .collect(Collectors.toList()); + var upperCaseCurrencyCode = currencyCode.toUpperCase(); + if (isFiatCurrency(upperCaseCurrencyCode)) { + return offerBookService.getOffers().stream() + .filter(o -> !o.isMyOffer(keyRing)) + .filter(o -> offerMatchesDirectionAndCurrency(o, direction, upperCaseCurrencyCode)) + .filter(o -> offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid()) + .sorted(priceComparator(direction)) + .collect(Collectors.toList()); + } else { + // In fiat offers, the baseCurrencyCode=BTC, counterCurrencyCode=FiatCode. + // In altcoin offers, baseCurrencyCode=AltcoinCode, counterCurrencyCode=BTC. + // This forces an extra filtering step below: get all BTC offers, + // then filter on the currencyCode param (the altcoin code). + if (apiSupportsCryptoCurrency(upperCaseCurrencyCode)) + return offerBookService.getOffers().stream() + .filter(o -> !o.isMyOffer(keyRing)) + .filter(o -> offerMatchesDirectionAndCurrency(o, direction, "BTC")) + .filter(o -> o.getBaseCurrencyCode().equalsIgnoreCase(upperCaseCurrencyCode)) + .filter(o -> offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid()) + .sorted(priceComparator(direction)) + .collect(Collectors.toList()); + else + throw new IllegalArgumentException( + format("api does not support the '%s' crypto currency", upperCaseCurrencyCode)); + } } List getMyOffers(String direction, String currencyCode) { - return openOfferManager.getObservableList().stream() - .filter(o -> o.getOffer().isMyOffer(keyRing)) - .filter(o -> offerMatchesDirectionAndCurrency(o.getOffer(), direction, currencyCode)) - .sorted(openOfferPriceComparator(direction)) - .collect(Collectors.toList()); + var upperCaseCurrencyCode = currencyCode.toUpperCase(); + if (isFiatCurrency(upperCaseCurrencyCode)) { + return openOfferManager.getObservableList().stream() + .filter(o -> o.getOffer().isMyOffer(keyRing)) + .filter(o -> offerMatchesDirectionAndCurrency(o.getOffer(), direction, upperCaseCurrencyCode)) + .sorted(openOfferPriceComparator(direction)) + .collect(Collectors.toList()); + } else { + // In fiat offers, the baseCurrencyCode=BTC, counterCurrencyCode=FiatCode. + // In altcoin offers, baseCurrencyCode=AltcoinCode, counterCurrencyCode=BTC. + // This forces an extra filtering step below: get all BTC offers, + // then filter on the currencyCode param (the altcoin code). + if (apiSupportsCryptoCurrency(upperCaseCurrencyCode)) + return openOfferManager.getObservableList().stream() + .filter(o -> o.getOffer().isMyOffer(keyRing)) + .filter(o -> offerMatchesDirectionAndCurrency(o.getOffer(), direction, "BTC")) + .filter(o -> o.getOffer().getBaseCurrencyCode().equalsIgnoreCase(upperCaseCurrencyCode)) + .sorted(openOfferPriceComparator(direction)) + .collect(Collectors.toList()); + else + throw new IllegalArgumentException( + format("api does not support the '%s' crypto currency", upperCaseCurrencyCode)); + } } List getMyBsqSwapOffers(String direction) { diff --git a/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java b/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java index de053847384..05e34852d3e 100644 --- a/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java +++ b/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java @@ -40,13 +40,13 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.function.Predicate; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import static bisq.common.app.DevEnv.isDaoTradingActivated; import static bisq.common.config.Config.baseCurrencyNetwork; +import static bisq.core.locale.CurrencyUtil.apiSupportsCryptoCurrency; import static bisq.core.locale.CurrencyUtil.findAsset; import static bisq.core.locale.CurrencyUtil.getCryptoCurrency; import static java.lang.String.format; @@ -55,9 +55,6 @@ @Slf4j class CorePaymentAccountsService { - private final Predicate apiDoesSupportCryptoCurrencyAccount = (c) -> - c.equals("BSQ") || c.equals("XMR"); - private final CoreWalletsService coreWalletsService; private final AccountAgeWitnessService accountAgeWitnessService; private final PaymentAccountForm paymentAccountForm; @@ -159,7 +156,7 @@ private void verifyCryptoCurrencyAddress(String cryptoCurrencyCode, String addre } private void verifyApiDoesSupportCryptoCurrencyAccount(String cryptoCurrencyCode) { - if (!apiDoesSupportCryptoCurrencyAccount.test(cryptoCurrencyCode)) + if (!apiSupportsCryptoCurrency(cryptoCurrencyCode)) throw new IllegalArgumentException( format("api does not currently support %s accounts", cryptoCurrencyCode.toLowerCase())); diff --git a/core/src/main/java/bisq/core/locale/CurrencyUtil.java b/core/src/main/java/bisq/core/locale/CurrencyUtil.java index 7a572fc79f8..47b7afaa1fb 100644 --- a/core/src/main/java/bisq/core/locale/CurrencyUtil.java +++ b/core/src/main/java/bisq/core/locale/CurrencyUtil.java @@ -793,4 +793,17 @@ public static String getPriceWithCurrencyCode(String currencyCode, String transl public static String getOfferVolumeCode(String currencyCode) { return Res.get("shared.offerVolumeCode", currencyCode); } + + public static boolean apiSupportsCryptoCurrency(String currencyCode) { + // Although this method is only used by the core.api package, its + // presence here avoids creating a new util class just for this method. + if (isCryptoCurrency(currencyCode)) + return currencyCode.equals("BTC") + || currencyCode.equals("BSQ") + || currencyCode.equals("XMR"); + else + throw new IllegalArgumentException( + format("Method requires a crypto currency code, but was given '%s'.", + currencyCode)); + } } From d913022506123909e7febf5c7757c8b9a616d540 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Thu, 3 Mar 2022 16:32:03 -0300 Subject: [PATCH 2/2] Force rebuild after github action ECONNRESET