Skip to content

Commit

Permalink
Merge pull request #5825 from chimp1984/improve-offer-validation
Browse files Browse the repository at this point in the history
Improve offer validation
  • Loading branch information
ripcurlx authored Nov 15, 2021
2 parents 17d4d42 + 478b756 commit 83c9355
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion core/src/main/java/bisq/core/offer/Offer.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,15 @@ public long getFixedPrice() {
return offerPayloadBase.getPrice();
}

public void checkTradePriceTolerance(long takersTradePrice) throws TradePriceOutOfToleranceException,
public void verifyTakersTradePrice(long takersTradePrice) throws TradePriceOutOfToleranceException,
MarketPriceNotAvailableException, IllegalArgumentException {
if (!isUseMarketBasedPrice()) {
checkArgument(takersTradePrice == getFixedPrice(),
"Takers price does not match offer price. " +
"Takers price=" + takersTradePrice + "; offer price=" + getFixedPrice());
return;
}

Price tradePrice = Price.valueOf(getCurrencyCode(), takersTradePrice);
Price offerPrice = getPrice();
if (offerPrice == null)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ private void handleOfferAvailabilityRequest(OfferAvailabilityRequest request, No
// Check also tradePrice to avoid failures after taker fee is paid caused by a too big difference
// in trade price between the peers. Also here poor connectivity might cause market price API connection
// losses and therefore an outdated market price.
offer.checkTradePriceTolerance(request.getTakersTradePrice());
offer.verifyTakersTradePrice(request.getTakersTradePrice());
availabilityResult = AvailabilityResult.AVAILABLE;
} catch (TradePriceOutOfToleranceException e) {
log.warn("Trade price check failed because takers price is outside out tolerance.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected void run() {
Offer offer = checkNotNull(trade.getOffer(), "Offer must not be null");
try {
long takersTradePrice = request.getTradePrice();
offer.checkTradePriceTolerance(takersTradePrice);
offer.verifyTakersTradePrice(takersTradePrice);
trade.setPriceAsLong(takersTradePrice);
} catch (TradePriceOutOfToleranceException e) {
failed(e.getMessage());
Expand Down

0 comments on commit 83c9355

Please sign in to comment.