[bisq-network/bisq] Use existing timer in unlockwallet(pwd, timeout) (#4558)
chimp1984
notifications at github.com
Sun Sep 27 21:37:52 UTC 2020
@chimp1984 commented on this pull request.
> @@ -86,21 +90,53 @@ public void getOffers(GetOffersRequest req,
@Override
public void createOffer(CreateOfferRequest req,
StreamObserver<CreateOfferReply> responseObserver) {
- TransactionResultHandler resultHandler = transaction -> {
- CreateOfferReply reply = CreateOfferReply.newBuilder().setResult(true).build();
+ CountDownLatch latch = new CountDownLatch(1);
+ try {
+ TransactionResultHandler resultHandler = transaction -> {
+ latch.countDown();
Index: core/src/main/java/bisq/core/api/CoreOffersService.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/main/java/bisq/core/api/CoreOffersService.java (revision 939dba352b10d9f8049e7fea54a461ac93c777e2)
+++ core/src/main/java/bisq/core/api/CoreOffersService.java (date 1601242413000)
@@ -77,7 +77,7 @@
return offers;
}
- Offer createOffer(String currencyCode,
+ Offer getNewOffer(String currencyCode,
String directionAsString,
long priceAsLong,
boolean useMarketBasedPrice,
@@ -85,47 +85,16 @@
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
- String paymentAccountId,
- TransactionResultHandler resultHandler) {
+ String paymentAccountId) {
String offerId = createOfferService.getRandomOfferId();
OfferPayload.Direction direction = OfferPayload.Direction.valueOf(directionAsString);
Price price = Price.valueOf(currencyCode, priceAsLong);
Coin amount = Coin.valueOf(amountAsLong);
Coin minAmount = Coin.valueOf(minAmountAsLong);
PaymentAccount paymentAccount = user.getPaymentAccount(paymentAccountId);
- // We don't support atm funding from external wallet to keep it simple
- boolean useSavingsWallet = true;
- //noinspection ConstantConditions
- return createAndPlaceOffer(offerId,
- currencyCode,
- direction,
- price,
- useMarketBasedPrice,
- marketPriceMargin,
- amount,
- minAmount,
- buyerSecurityDeposit,
- paymentAccount,
- useSavingsWallet,
- resultHandler);
- }
-
- Offer createAndPlaceOffer(String offerId,
- String currencyCode,
- OfferPayload.Direction direction,
- Price price,
- boolean useMarketBasedPrice,
- double marketPriceMargin,
- Coin amount,
- Coin minAmount,
- double buyerSecurityDeposit,
- PaymentAccount paymentAccount,
- boolean useSavingsWallet,
- TransactionResultHandler resultHandler) {
Coin useDefaultTxFee = Coin.ZERO;
-
- Offer offer = createOfferService.createAndGetOffer(offerId,
+ return createOfferService.createAndGetOffer(offerId,
direction,
currencyCode,
amount,
@@ -136,18 +105,21 @@
marketPriceMargin,
buyerSecurityDeposit,
paymentAccount);
+ }
+ void placeOffer(Offer offer,
+ double buyerSecurityDeposit,
+ boolean useSavingsWallet,
+ TransactionResultHandler resultHandler) {
// TODO give user chance to examine offer before placing it (placeoffer)
openOfferManager.placeOffer(offer,
buyerSecurityDeposit,
useSavingsWallet,
resultHandler,
log::error);
-
- return offer;
}
- Offer createOffer(String offerId,
+ Offer getNewOffer(String offerId,
String currencyCode,
OfferPayload.Direction direction,
Price price,
Index: core/src/main/java/bisq/core/api/CoreApi.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/src/main/java/bisq/core/api/CoreApi.java (revision 939dba352b10d9f8049e7fea54a461ac93c777e2)
+++ core/src/main/java/bisq/core/api/CoreApi.java (date 1601242413000)
@@ -87,7 +87,7 @@
return coreOffersService.getOffers(direction, fiatCurrencyCode);
}
- public Offer createOffer(String currencyCode,
+ public Offer getNewOffer(String currencyCode,
String directionAsString,
long priceAsLong,
boolean useMarketBasedPrice,
@@ -95,9 +95,8 @@
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
- String paymentAccountId,
- TransactionResultHandler resultHandler) {
- return coreOffersService.createOffer(currencyCode,
+ String paymentAccountId) {
+ return coreOffersService.getNewOffer(currencyCode,
directionAsString,
priceAsLong,
useMarketBasedPrice,
@@ -105,11 +104,20 @@
amountAsLong,
minAmountAsLong,
buyerSecurityDeposit,
- paymentAccountId,
+ paymentAccountId);
+ }
+
+ public void placeOffer(Offer offer,
+ double buyerSecurityDeposit,
+ boolean useSavingsWallet,
+ TransactionResultHandler resultHandler) {
+ coreOffersService.placeOffer(offer,
+ buyerSecurityDeposit,
+ useSavingsWallet,
resultHandler);
}
- public Offer createOffer(String offerId,
+ public Offer getNewOffer(String offerId,
String currencyCode,
OfferPayload.Direction direction,
Price price,
@@ -121,7 +129,7 @@
PaymentAccount paymentAccount,
boolean useSavingsWallet,
TransactionResultHandler resultHandler) {
- return coreOffersService.createOffer(offerId,
+ return coreOffersService.getNewOffer(offerId,
currencyCode,
direction,
price,
Index: daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java (revision 939dba352b10d9f8049e7fea54a461ac93c777e2)
+++ daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java (date 1601242365000)
@@ -20,7 +20,6 @@
import bisq.core.api.CoreApi;
import bisq.core.api.model.OfferInfo;
import bisq.core.offer.Offer;
-import bisq.core.trade.handlers.TransactionResultHandler;
import bisq.proto.grpc.CreateOfferReply;
import bisq.proto.grpc.CreateOfferRequest;
@@ -35,7 +34,6 @@
import javax.inject.Inject;
import java.util.List;
-import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
@@ -90,12 +88,9 @@
@Override
public void createOffer(CreateOfferRequest req,
StreamObserver<CreateOfferReply> responseObserver) {
- CountDownLatch latch = new CountDownLatch(1);
try {
- TransactionResultHandler resultHandler = transaction -> {
- latch.countDown();
- };
- Offer offer = coreApi.createOffer(
+ // TODO give user chance to examine offer before placing it (placeoffer)
+ Offer offer = coreApi.getNewOffer(
req.getCurrencyCode(),
req.getDirection(),
req.getPrice(),
@@ -104,35 +99,37 @@
req.getAmount(),
req.getMinAmount(),
req.getBuyerSecurityDeposit(),
- req.getPaymentAccountId(),
- resultHandler);
- try {
- latch.await();
- } catch (InterruptedException ignored) {
- // empty
- }
+ req.getPaymentAccountId());
- OfferInfo offerInfo = new OfferInfo.OfferInfoBuilder()
- .withId(offer.getId())
- .withDirection(offer.getDirection().name())
- .withPrice(offer.getPrice().getValue())
- .withUseMarketBasedPrice(offer.isUseMarketBasedPrice())
- .withMarketPriceMargin(offer.getMarketPriceMargin())
- .withAmount(offer.getAmount().value)
- .withMinAmount(offer.getMinAmount().value)
- .withVolume(offer.getVolume().getValue())
- .withMinVolume(offer.getMinVolume().getValue())
- .withBuyerSecurityDeposit(offer.getBuyerSecurityDeposit().value)
- .withPaymentAccountId(offer.getMakerPaymentAccountId())
- .withPaymentMethodId(offer.getPaymentMethod().getId())
- .withPaymentMethodShortName(offer.getPaymentMethod().getShortName())
- .withBaseCurrencyCode(offer.getOfferPayload().getBaseCurrencyCode())
- .withCounterCurrencyCode(offer.getOfferPayload().getCounterCurrencyCode())
- .withDate(offer.getDate().getTime())
- .build();
- CreateOfferReply reply = CreateOfferReply.newBuilder().setOffer(offerInfo.toProtoMessage()).build();
- responseObserver.onNext(reply);
- responseObserver.onCompleted();
+ // We don't support atm funding from external wallet to keep it simple
+ boolean useSavingsWallet = true;
+
+ coreApi.placeOffer(offer,
+ req.getBuyerSecurityDeposit(),
+ useSavingsWallet,
+ transaction -> {
+ OfferInfo offerInfo = new OfferInfo.OfferInfoBuilder()
+ .withId(offer.getId())
+ .withDirection(offer.getDirection().name())
+ .withPrice(offer.getPrice().getValue())
+ .withUseMarketBasedPrice(offer.isUseMarketBasedPrice())
+ .withMarketPriceMargin(offer.getMarketPriceMargin())
+ .withAmount(offer.getAmount().value)
+ .withMinAmount(offer.getMinAmount().value)
+ .withVolume(offer.getVolume().getValue())
+ .withMinVolume(offer.getMinVolume().getValue())
+ .withBuyerSecurityDeposit(offer.getBuyerSecurityDeposit().value)
+ .withPaymentAccountId(offer.getMakerPaymentAccountId())
+ .withPaymentMethodId(offer.getPaymentMethod().getId())
+ .withPaymentMethodShortName(offer.getPaymentMethod().getShortName())
+ .withBaseCurrencyCode(offer.getOfferPayload().getBaseCurrencyCode())
+ .withCounterCurrencyCode(offer.getOfferPayload().getCounterCurrencyCode())
+ .withDate(offer.getDate().getTime())
+ .build();
+ CreateOfferReply reply = CreateOfferReply.newBuilder().setOffer(offerInfo.toProtoMessage()).build();
+ responseObserver.onNext(reply);
+ responseObserver.onCompleted();
+ });
} catch (IllegalStateException | IllegalArgumentException cause) {
var ex = new StatusRuntimeException(Status.UNKNOWN.withDescription(cause.getMessage()));
responseObserver.onError(ex);
--
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/4558#discussion_r495619090
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20200927/5e430617/attachment-0001.html>
More information about the bisq-github
mailing list