Skip to content

Commit

Permalink
Merge pull request #6086 from ghubstan/move-cli-crypto-offer-filter-t…
Browse files Browse the repository at this point in the history
…o-server

Move get (cryptocurrency) offer filter to daemon [No. 1]
  • Loading branch information
ripcurlx authored Mar 8, 2022
2 parents 18f8e79 + d913022 commit ae17da9
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() {
@Test
@Order(5)
public void testGetAllMyBsqOffers() {
List<OfferInfo> offers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(BSQ);
List<OfferInfo> 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()));
Expand All @@ -269,7 +269,7 @@ public void testGetAllMyBsqOffers() {
@Test
@Order(6)
public void testGetAvailableBsqOffers() {
List<OfferInfo> offers = bobClient.getCryptoCurrencyOffersSortedByDate(BSQ);
List<OfferInfo> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() {
@Test
@Order(5)
public void testGetAllMyXMROffers() {
List<OfferInfo> offers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(XMR);
List<OfferInfo> 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()));
Expand All @@ -266,7 +266,7 @@ public void testGetAllMyXMROffers() {
@Test
@Order(6)
public void testGetAvailableXMROffers() {
List<OfferInfo> offers = bobClient.getCryptoCurrencyOffersSortedByDate(XMR);
List<OfferInfo> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
45 changes: 2 additions & 43 deletions cli/src/main/java/bisq/cli/GrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -289,10 +284,6 @@ public List<OfferInfo> getOffers(String direction, String currencyCode) {
return offersServiceRequest.getOffers(direction, currencyCode);
}

public List<OfferInfo> getCryptoCurrencyOffers(String direction, String currencyCode) {
return offersServiceRequest.getCryptoCurrencyOffers(direction, currencyCode);
}

public List<OfferInfo> getOffersSortedByDate(String currencyCode) {
return offersServiceRequest.getOffersSortedByDate(currencyCode);
}
Expand All @@ -301,58 +292,26 @@ public List<OfferInfo> getOffersSortedByDate(String direction, String currencyCo
return offersServiceRequest.getOffersSortedByDate(direction, currencyCode);
}

public List<OfferInfo> getCryptoCurrencyOffersSortedByDate(String currencyCode) {
return offersServiceRequest.getCryptoCurrencyOffersSortedByDate(currencyCode);
}

public List<OfferInfo> getBsqSwapOffersSortedByDate() {
return offersServiceRequest.getBsqSwapOffersSortedByDate();
}

public List<OfferInfo> getMyBsqSwapOffers(String direction) {
return offersServiceRequest.getMyBsqSwapOffers(direction);
}

public List<OfferInfo> getMyOffers(String direction, String currencyCode) {
return offersServiceRequest.getMyOffers(direction, currencyCode);
}

public List<OfferInfo> getMyCryptoCurrencyOffers(String direction, String currencyCode) {
return offersServiceRequest.getMyCryptoCurrencyOffers(direction, currencyCode);
}

public List<OfferInfo> getMyOffersSortedByDate(String direction, String currencyCode) {
return offersServiceRequest.getMyOffersSortedByDate(direction, currencyCode);
}

public List<OfferInfo> getMyOffersSortedByDate(String currencyCode) {
return offersServiceRequest.getMyOffersSortedByDate(currencyCode);
}

public List<OfferInfo> getMyCryptoCurrencyOffersSortedByDate(String currencyCode) {
return offersServiceRequest.getMyCryptoCurrencyOffersSortedByDate(currencyCode);
public List<OfferInfo> getMyOffersSortedByDate(String direction, String currencyCode) {
return offersServiceRequest.getMyOffersSortedByDate(direction, currencyCode);
}

public List<OfferInfo> getMyBsqSwapBsqOffersSortedByDate() {
return offersServiceRequest.getMyBsqSwapOffersSortedByDate();
}

public OfferInfo getMostRecentOffer(String direction, String currencyCode) {
return offersServiceRequest.getMostRecentOffer(direction, currencyCode);
}

public List<OfferInfo> sortBsqSwapOffersByDate(List<OfferInfo> offers) {
return offersServiceRequest.sortOffersByDate(offers);
}

public List<OfferInfo> sortOffersByDate(List<OfferInfo> 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);
}
Expand Down
72 changes: 15 additions & 57 deletions cli/src/main/java/bisq/cli/request/OffersServiceRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -240,42 +232,25 @@ public List<OfferInfo> getBsqSwapOffers(String direction) {
}

public List<OfferInfo> 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<OfferInfo> 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<OfferInfo> getOffersSortedByDate(String currencyCode) {
ArrayList<OfferInfo> 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<OfferInfo> getOffersSortedByDate(String direction, String currencyCode) {
var offers = getOffers(direction, currencyCode);
return offers.isEmpty() ? offers : sortOffersByDate(offers);
}

public List<OfferInfo> getCryptoCurrencyOffersSortedByDate(String currencyCode) {
ArrayList<OfferInfo> offers = new ArrayList<>();
offers.addAll(getCryptoCurrencyOffers(BUY.name(), currencyCode));
offers.addAll(getCryptoCurrencyOffers(SELL.name(), currencyCode));
return sortOffersByDate(offers);
}

public List<OfferInfo> getBsqSwapOffersSortedByDate() {
ArrayList<OfferInfo> offers = new ArrayList<>();
offers.addAll(getBsqSwapOffers(BUY.name()));
Expand All @@ -291,40 +266,23 @@ public List<OfferInfo> getMyBsqSwapOffers(String direction) {
}

public List<OfferInfo> 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<OfferInfo> getMyCryptoCurrencyOffers(String direction, String currencyCode) {
return getMyOffers(direction, "BTC").stream()
.filter(o -> o.getBaseCurrencyCode().equalsIgnoreCase(currencyCode))
.collect(toList());
}

public List<OfferInfo> 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<OfferInfo> getMyOffersSortedByDate(String currencyCode) {
ArrayList<OfferInfo> 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<OfferInfo> getMyCryptoCurrencyOffersSortedByDate(String currencyCode) {
ArrayList<OfferInfo> offers = new ArrayList<>();
offers.addAll(getMyCryptoCurrencyOffers(BUY.name(), currencyCode));
offers.addAll(getMyCryptoCurrencyOffers(SELL.name(), currencyCode));
return sortOffersByDate(offers);
public List<OfferInfo> getMyOffersSortedByDate(String direction, String currencyCode) {
var offers = getMyOffers(direction, currencyCode);
return offers.isEmpty() ? offers : sortOffersByDate(offers);
}

public List<OfferInfo> getMyBsqSwapOffersSortedByDate() {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/test/java/bisq/cli/AbstractCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected List<OfferInfo> getMyAltcoinOffers(String currencyCode) {
CliMain.main(args);
out.println("<<<<<");

return aliceClient.getMyCryptoCurrencyOffersSortedByDate(currencyCode);
return aliceClient.getMyOffersSortedByDate(currencyCode);
}

protected String[] getMyOffersCommand(String direction, String currencyCode) {
Expand Down
Loading

0 comments on commit ae17da9

Please sign in to comment.