From 458f50dec9a5337362f753a076c605f76aa71e20 Mon Sep 17 00:00:00 2001 From: helixx87 Date: Tue, 11 Apr 2023 12:50:00 +0200 Subject: [PATCH] Support "all" attribute in getoffers API method --- .../method/offer/CreateBSQOffersTest.java | 2 +- .../method/offer/CreateXMROffersTest.java | 2 +- .../method/trade/TakeSellBTCOfferTest.java | 2 +- cli/src/main/java/bisq/cli/CliMain.java | 3 ++- cli/src/main/java/bisq/cli/GrpcClient.java | 12 ++++++------ .../bisq/cli/opts/GetOffersOptionParser.java | 10 ++++++++++ cli/src/main/java/bisq/cli/opts/OptLabel.java | 1 + .../bisq/cli/request/OffersServiceRequest.java | 17 +++++++++-------- .../cli/table/GetOffersCliOutputDiffTest.java | 12 ++++++------ core/src/main/java/bisq/core/api/CoreApi.java | 4 ++-- .../java/bisq/core/api/CoreOffersService.java | 6 +++--- core/src/main/resources/help/getoffers-help.txt | 4 ++++ .../bisq/daemon/grpc/GrpcOffersService.java | 2 +- proto/src/main/proto/grpc.proto | 1 + 14 files changed, 48 insertions(+), 30 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 66819852bff..fb4f14bc28c 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java @@ -277,7 +277,7 @@ public void testGetAllMyBsqOffers() { @Test @Order(6) public void testGetAvailableBsqOffers() { - List offers = bobClient.getOffersSortedByDate(BSQ); + List offers = bobClient.getOffersSortedByDate(BSQ, false); 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 b9337051535..1ceb45c973d 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java @@ -274,7 +274,7 @@ public void testGetAllMyXMROffers() { @Test @Order(6) public void testGetAvailableXMROffers() { - List offers = bobClient.getOffersSortedByDate(XMR); + List offers = bobClient.getOffersSortedByDate(XMR, false); 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/TakeSellBTCOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java index cb9de760337..74a183df610 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java @@ -86,7 +86,7 @@ public void testTakeAlicesSellOffer(final TestInfo testInfo) { 0L, false); sleep(2_500); // Allow available offer to be removed from offer book. - var takeableUsdOffers = bobClient.getOffersSortedByDate(SELL.name(), USD); + var takeableUsdOffers = bobClient.getOffersSortedByDate(SELL.name(), USD, false); assertEquals(0, takeableUsdOffers.size()); trade = bobClient.getTrade(tradeId); diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index e5f94c3a981..93db258fdde 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -468,7 +468,8 @@ public static void run(String[] args) { } var direction = opts.getDirection(); var currencyCode = opts.getCurrencyCode(); - List offers = client.getOffers(direction, currencyCode); + var all = opts.getAll(); + List offers = client.getOffers(direction, currencyCode, all); if (offers.isEmpty()) out.printf("no %s %s offers found%n", direction, currencyCode); else diff --git a/cli/src/main/java/bisq/cli/GrpcClient.java b/cli/src/main/java/bisq/cli/GrpcClient.java index 2d5e4f6d99b..ad073f6e31f 100644 --- a/cli/src/main/java/bisq/cli/GrpcClient.java +++ b/cli/src/main/java/bisq/cli/GrpcClient.java @@ -293,16 +293,16 @@ public List getBsqSwapOffers(String direction) { return offersServiceRequest.getBsqSwapOffers(direction); } - public List getOffers(String direction, String currencyCode) { - return offersServiceRequest.getOffers(direction, currencyCode); + public List getOffers(String direction, String currencyCode, boolean all) { + return offersServiceRequest.getOffers(direction, currencyCode, all); } - public List getOffersSortedByDate(String currencyCode) { - return offersServiceRequest.getOffersSortedByDate(currencyCode); + public List getOffersSortedByDate(String currencyCode, boolean all) { + return offersServiceRequest.getOffersSortedByDate(currencyCode, all); } - public List getOffersSortedByDate(String direction, String currencyCode) { - return offersServiceRequest.getOffersSortedByDate(direction, currencyCode); + public List getOffersSortedByDate(String direction, String currencyCode, boolean all) { + return offersServiceRequest.getOffersSortedByDate(direction, currencyCode, all); } public List getBsqSwapOffersSortedByDate() { diff --git a/cli/src/main/java/bisq/cli/opts/GetOffersOptionParser.java b/cli/src/main/java/bisq/cli/opts/GetOffersOptionParser.java index 5f7d59eb8fc..77390e37a50 100644 --- a/cli/src/main/java/bisq/cli/opts/GetOffersOptionParser.java +++ b/cli/src/main/java/bisq/cli/opts/GetOffersOptionParser.java @@ -20,6 +20,7 @@ import joptsimple.OptionSpec; +import static bisq.cli.opts.OptLabel.OPT_ALL; import static bisq.cli.opts.OptLabel.OPT_CURRENCY_CODE; import static bisq.cli.opts.OptLabel.OPT_DIRECTION; @@ -31,6 +32,11 @@ public class GetOffersOptionParser extends AbstractMethodOptionParser implements final OptionSpec currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (bsq|xmr|eur|usd|...)") .withRequiredArg(); + final OptionSpec allOpt = parser.accepts(OPT_ALL, "get all offers") + .withOptionalArg() + .ofType(boolean.class) + .defaultsTo(Boolean.FALSE); + public GetOffersOptionParser(String[] args) { super(args); } @@ -58,4 +64,8 @@ public String getDirection() { public String getCurrencyCode() { return options.valueOf(currencyCodeOpt); } + + public boolean getAll() { + return options.valueOf(allOpt); + } } diff --git a/cli/src/main/java/bisq/cli/opts/OptLabel.java b/cli/src/main/java/bisq/cli/opts/OptLabel.java index 8ea22c23643..05265067738 100644 --- a/cli/src/main/java/bisq/cli/opts/OptLabel.java +++ b/cli/src/main/java/bisq/cli/opts/OptLabel.java @@ -26,6 +26,7 @@ public class OptLabel { public final static String OPT_AMOUNT = "amount"; public final static String OPT_CATEGORY = "category"; public final static String OPT_CURRENCY_CODE = "currency-code"; + public final static String OPT_ALL = "all"; public final static String OPT_DAYS = "days"; public final static String OPT_DIRECTION = "direction"; public final static String OPT_DISPUTE_AGENT_TYPE = "dispute-agent-type"; diff --git a/cli/src/main/java/bisq/cli/request/OffersServiceRequest.java b/cli/src/main/java/bisq/cli/request/OffersServiceRequest.java index 20f6158f2b6..e027424a0db 100644 --- a/cli/src/main/java/bisq/cli/request/OffersServiceRequest.java +++ b/cli/src/main/java/bisq/cli/request/OffersServiceRequest.java @@ -231,23 +231,24 @@ public List getBsqSwapOffers(String direction) { return grpcStubs.offersService.getBsqSwapOffers(request).getBsqSwapOffersList(); } - public List getOffers(String direction, String currencyCode) { + public List getOffers(String direction, String currencyCode, boolean all) { var request = GetOffersRequest.newBuilder() .setDirection(direction) .setCurrencyCode(currencyCode) + .setAll(all) .build(); return grpcStubs.offersService.getOffers(request).getOffersList(); } - public List getOffersSortedByDate(String currencyCode) { + public List getOffersSortedByDate(String currencyCode, boolean all) { ArrayList offers = new ArrayList<>(); - offers.addAll(getOffers(BUY.name(), currencyCode)); - offers.addAll(getOffers(SELL.name(), currencyCode)); + offers.addAll(getOffers(BUY.name(), currencyCode, all)); + offers.addAll(getOffers(SELL.name(), currencyCode, all)); return offers.isEmpty() ? offers : sortOffersByDate(offers); } - public List getOffersSortedByDate(String direction, String currencyCode) { - var offers = getOffers(direction, currencyCode); + public List getOffersSortedByDate(String direction, String currencyCode, boolean all) { + var offers = getOffers(direction, currencyCode, all); return offers.isEmpty() ? offers : sortOffersByDate(offers); } @@ -292,8 +293,8 @@ public List getMyBsqSwapOffersSortedByDate() { return sortOffersByDate(offers); } - public OfferInfo getMostRecentOffer(String direction, String currencyCode) { - List offers = getOffersSortedByDate(direction, currencyCode); + public OfferInfo getMostRecentOffer(String direction, String currencyCode, boolean all) { + List offers = getOffersSortedByDate(direction, currencyCode, all); return offers.isEmpty() ? null : offers.get(offers.size() - 1); } diff --git a/cli/src/test/java/bisq/cli/table/GetOffersCliOutputDiffTest.java b/cli/src/test/java/bisq/cli/table/GetOffersCliOutputDiffTest.java index f5b85bdc62b..2bc538d3edf 100644 --- a/cli/src/test/java/bisq/cli/table/GetOffersCliOutputDiffTest.java +++ b/cli/src/test/java/bisq/cli/table/GetOffersCliOutputDiffTest.java @@ -59,12 +59,12 @@ private void getMySellUsdOffers() { } private void getAvailableBuyUsdOffers() { - var offers = bobClient.getOffers(BUY.name(), "USD"); + var offers = bobClient.getOffers(BUY.name(), "USD", false); printAndCheckDiffs(offers, BUY.name(), "USD"); } private void getAvailableSellUsdOffers() { - var offers = bobClient.getOffers(SELL.name(), "USD"); + var offers = bobClient.getOffers(SELL.name(), "USD", false); printAndCheckDiffs(offers, SELL.name(), "USD"); } @@ -79,12 +79,12 @@ private void getMySellXmrOffers() { } private void getAvailableBuyXmrOffers() { - var offers = bobClient.getOffers(BUY.name(), "XMR"); + var offers = bobClient.getOffers(BUY.name(), "XMR", false); printAndCheckDiffs(offers, BUY.name(), "XMR"); } private void getAvailableSellXmrOffers() { - var offers = bobClient.getOffers(SELL.name(), "XMR"); + var offers = bobClient.getOffers(SELL.name(), "XMR", false); printAndCheckDiffs(offers, SELL.name(), "XMR"); } @@ -99,12 +99,12 @@ private void getMySellBsqOffers() { } private void getAvailableBuyBsqOffers() { - var offers = bobClient.getOffers(BUY.name(), "BSQ"); + var offers = bobClient.getOffers(BUY.name(), "BSQ", false); printAndCheckDiffs(offers, BUY.name(), "BSQ"); } private void getAvailableSellBsqOffers() { - var offers = bobClient.getOffers(SELL.name(), "BSQ"); + var offers = bobClient.getOffers(SELL.name(), "BSQ", false); printAndCheckDiffs(offers, SELL.name(), "BSQ"); } diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index e8e6e4832fd..9dba6f109de 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -164,8 +164,8 @@ public List getBsqSwapOffers(String direction) { return coreOffersService.getBsqSwapOffers(direction); } - public List getOffers(String direction, String currencyCode) { - return coreOffersService.getOffers(direction, currencyCode); + public List getOffers(String direction, String currencyCode, boolean all) { + return coreOffersService.getOffers(direction, currencyCode, all); } public List getMyOffers(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 633dd711af3..0405bbfe9dd 100644 --- a/core/src/main/java/bisq/core/api/CoreOffersService.java +++ b/core/src/main/java/bisq/core/api/CoreOffersService.java @@ -206,14 +206,14 @@ List getBsqSwapOffers(String direction) { .collect(Collectors.toList()); } - List getOffers(String direction, String currencyCode) { + List getOffers(String direction, String currencyCode, boolean all) { var upperCaseCurrencyCode = currencyCode.toUpperCase(); var isFiat = isFiatCurrency(upperCaseCurrencyCode); if (isFiat) { return offerBookService.getOffers().stream() .filter(o -> !o.isMyOffer(keyRing)) .filter(o -> offerMatchesDirectionAndCurrency(o, direction, upperCaseCurrencyCode)) - .filter(o -> offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid()) + .filter(o -> all || offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid()) .sorted(priceComparator(direction, true)) .collect(Collectors.toList()); } else { @@ -226,7 +226,7 @@ List getOffers(String direction, String currencyCode) { .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()) + .filter(o -> all || offerFilterService.canTakeOffer(o, coreContext.isApiUser()).isValid()) .sorted(priceComparator(direction, false)) .collect(Collectors.toList()); else diff --git a/core/src/main/resources/help/getoffers-help.txt b/core/src/main/resources/help/getoffers-help.txt index c76c2dfbda9..24712c68873 100644 --- a/core/src/main/resources/help/getoffers-help.txt +++ b/core/src/main/resources/help/getoffers-help.txt @@ -9,6 +9,7 @@ SYNOPSIS getoffers --direction= --currency-code= + --all= DESCRIPTION ----------- @@ -24,6 +25,9 @@ OPTIONS --currency-code The three letter code for the fiat used to buy or sell BTC, e.g., EUR, USD, BRL, ... +--all + Whether return all offers or only these matching my accounts + EXAMPLES -------- You have one Brazilian Real payment account with a face-to-face payment method type. diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java index cfb6cc34973..824e20a83ff 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java @@ -195,7 +195,7 @@ public void getBsqSwapOffers(GetBsqSwapOffersRequest req, public void getOffers(GetOffersRequest req, StreamObserver responseObserver) { try { - List result = coreApi.getOffers(req.getDirection(), req.getCurrencyCode()) + List result = coreApi.getOffers(req.getDirection(), req.getCurrencyCode(), req.getAll()) .stream() .map(OfferInfo::toOfferInfo) .collect(Collectors.toList()); diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 708168654fe..9363457fb66 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -148,6 +148,7 @@ message GetMyOfferReply { message GetOffersRequest { string direction = 1; // The offer's BUY (BTC) or SELL (BTC) direction. string currency_code = 2; // The offer's fiat or altcoin currency code. + bool all = 3; // Return all or only these matching my account } message GetOffersReply {