Skip to content

Commit

Permalink
Merge pull request #6068 from ghubstan/7-more-grpcproto-comments
Browse files Browse the repository at this point in the history
Continue documenting grpc.proto for API reference site [#7]
  • Loading branch information
ripcurlx authored Feb 28, 2022
2 parents a73ee03 + 3d33aa2 commit d301b0d
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testCreateFixedPriceBuy1BTCFor200KXMROffer() {
XMR,
100_000_000L,
75_000_000L,
"0.005", // FIXED PRICE IN BTC (satoshis) FOR 1 XMR
"0.005", // FIXED PRICE IN BTC FOR 1 XMR
defaultBuyerSecurityDepositPct.get(),
alicesXmrAcct.getId(),
MAKER_FEE_CURRENCY_CODE);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void createAndPlaceOffer(String currencyCode,
Consumer<Offer> resultHandler) {
coreOffersService.createAndPlaceOffer(currencyCode,
directionAsString,
price,
useMarketBasedPrice ? "0" : price,
useMarketBasedPrice,
marketPriceMargin,
amountAsLong,
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/api/CoreOffersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void createAndPlaceBsqSwapOffer(String directionAsString,
String offerId = getRandomOfferId();
OfferDirection direction = OfferDirection.valueOf(directionAsString.toUpperCase());
Coin amount = Coin.valueOf(amountAsLong);
Coin minAmount = Coin.valueOf(minAmountAsLong);
Coin minAmount = minAmountAsLong == 0 ? amount : Coin.valueOf(minAmountAsLong);
Price price = Price.valueOf(currencyCode, priceStringToLong(priceAsString, currencyCode));
openBsqSwapOfferService.requestNewOffer(offerId,
direction,
Expand Down Expand Up @@ -294,7 +294,7 @@ void createAndPlaceOffer(String currencyCode,
OfferDirection direction = OfferDirection.valueOf(directionAsString.toUpperCase());
Price price = Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode));
Coin amount = Coin.valueOf(amountAsLong);
Coin minAmount = Coin.valueOf(minAmountAsLong);
Coin minAmount = minAmountAsLong == 0 ? amount : Coin.valueOf(minAmountAsLong);
Coin useDefaultTxFee = Coin.ZERO;

// Almost ready to call createOfferService.createAndGetOffer(), but first:
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/bisq/core/api/EditOfferValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class EditOfferValidator {
int newEnable,
EditOfferRequest.EditType editType) {
this.currentlyOpenOffer = currentlyOpenOffer;
this.newPrice = newPrice;
this.newPrice = newPrice.isBlank() ? "0" : newPrice;
// The client cannot determine what offer.isUseMarketBasedPrice should be
// when editType = ACTIVATION_STATE_ONLY. Override newIsUseMarketBasedPrice
// param for the ACTIVATION_STATE_ONLY case.
Expand All @@ -78,12 +78,12 @@ class EditOfferValidator {
? currentlyOpenOffer.getOffer().isUseMarketBasedPrice()
: newIsUseMarketBasedPrice;
this.newMarketPriceMargin = newMarketPriceMargin;
this.newTriggerPrice = newTriggerPrice;
this.newTriggerPrice = newTriggerPrice.isBlank() ? "0" : newTriggerPrice;
this.newEnable = newEnable;
this.editType = editType;

this.isZeroEditedFixedPriceString = new BigDecimal(newPrice).doubleValue() == 0;
this.isZeroEditedTriggerPrice = new BigDecimal(newTriggerPrice).equals(ZERO);
this.isZeroEditedFixedPriceString = new BigDecimal(this.newPrice).doubleValue() == 0;
this.isZeroEditedTriggerPrice = new BigDecimal(this.newTriggerPrice).equals(ZERO);
}

EditOfferValidator validate() {
Expand Down
57 changes: 32 additions & 25 deletions daemon/src/main/java/bisq/daemon/grpc/GrpcTradesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import bisq.core.api.CoreApi;
import bisq.core.api.model.CanceledTradeInfo;
import bisq.core.api.model.TradeInfo;
import bisq.core.offer.Offer;
import bisq.core.offer.OpenOffer;
import bisq.core.trade.model.TradeModel;
import bisq.core.trade.model.bisq_v1.Trade;
Expand Down Expand Up @@ -93,31 +94,37 @@ public void takeOffer(TakeOfferRequest req,
responseObserver,
exceptionHandler,
log);

if (coreApi.isBsqSwapOffer(req.getOfferId(), false)) {
coreApi.takeBsqSwapOffer(req.getOfferId(),
bsqSwapTrade -> {
var reply = buildTakeOfferReply(bsqSwapTrade);
responseObserver.onNext(reply);
responseObserver.onCompleted();
},
errorMessage -> {
if (!errorMessageHandler.isErrorHandled())
errorMessageHandler.handleErrorMessage(errorMessage);
});
} else {
coreApi.takeOffer(req.getOfferId(),
req.getPaymentAccountId(),
req.getTakerFeeCurrencyCode(),
trade -> {
var reply = buildTakeOfferReply(trade);
responseObserver.onNext(reply);
responseObserver.onCompleted();
},
errorMessage -> {
if (!errorMessageHandler.isErrorHandled())
errorMessageHandler.handleErrorMessage(errorMessage);
});
try {
// Make sure the offer exists before trying to take it.
Offer offer = coreApi.getOffer(req.getOfferId());

if (offer.isBsqSwapOffer()) {
coreApi.takeBsqSwapOffer(offer.getId(),
bsqSwapTrade -> {
var reply = buildTakeOfferReply(bsqSwapTrade);
responseObserver.onNext(reply);
responseObserver.onCompleted();
},
errorMessage -> {
if (!errorMessageHandler.isErrorHandled())
errorMessageHandler.handleErrorMessage(errorMessage);
});
} else {
coreApi.takeOffer(offer.getId(),
req.getPaymentAccountId(),
req.getTakerFeeCurrencyCode(),
trade -> {
var reply = buildTakeOfferReply(trade);
responseObserver.onNext(reply);
responseObserver.onCompleted();
},
errorMessage -> {
if (!errorMessageHandler.isErrorHandled())
errorMessageHandler.handleErrorMessage(errorMessage);
});
}
} catch (Throwable cause) {
exceptionHandler.handleException(log, cause, responseObserver);
}
}

Expand Down
Loading

0 comments on commit d301b0d

Please sign in to comment.