[bisq-network/bisq] Add protection tools (#5053)

Stan notifications at github.com
Mon Jan 4 21:28:45 CET 2021


>> @ghubstan: If the `offerFilter.canTakeOffer` call can be included in `getOffers(String direction, String currencyCode)` and `getOffer(String id)`, we can remove the `getOffersAvailableForTaker` method.

@chimp1984 If you want to back out that new core api `getOffersAvailableForTaker` method, add the two lines (commented in the snippet below as /* HERE */).  I'll test if you make the suggested change in the PR.


    // TODO should we add a check for offerFilter.canTakeOffer?
    Offer getOffer(String id) {
        return offerBookService.getOffers().stream()
                .filter(o -> o.getId().equals(id))
                .filter(o -> offerFilter.canTakeOffer(o, true).isValid())   /* HERE */
                .findAny().orElseThrow(() ->
                        new IllegalStateException(format("offer with id '%s' not found", id)));
    }

    // TODO returns all offers also those which cannot be taken. Should we use the filter from
    //  getOffersAvailableForTaker here and remove the getOffersAvailableForTaker method?
    List<Offer> getOffers(String direction, String currencyCode) {
        List<Offer> offers = offerBookService.getOffers().stream()
                .filter(o -> {
                    var offerOfWantedDirection = o.getDirection().name().equalsIgnoreCase(direction);
                    var offerInWantedCurrency = o.getOfferPayload().getCounterCurrencyCode()
                            .equalsIgnoreCase(currencyCode);
                    return offerOfWantedDirection && offerInWantedCurrency;
                })
                .filter(o -> offerFilter.canTakeOffer(o, true).isValid())	/* HERE */
                .collect(Collectors.toList());

        // A buyer probably wants to see sell orders in price ascending order.
        // A seller probably wants to see buy orders in price descending order.
        if (direction.equalsIgnoreCase(BUY.name()))
            offers.sort(Comparator.comparing(Offer::getPrice).reversed());
        else
            offers.sort(Comparator.comparing(Offer::getPrice));

        return offers;
    }

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/5053#issuecomment-754200017
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20210104/7bd5cf44/attachment-0001.htm>


More information about the bisq-github mailing list