Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing timer in unlockwallet(pwd, timeout) #4558

Closed
wants to merge 15 commits into from
Closed
48 changes: 24 additions & 24 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ public List<Offer> getOffers(String direction, String fiatCurrencyCode) {
return coreOffersService.getOffers(direction, fiatCurrencyCode);
}

public void createOffer(String currencyCode,
String directionAsString,
long priceAsLong,
boolean useMarketBasedPrice,
double marketPriceMargin,
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
String paymentAccountId,
TransactionResultHandler resultHandler) {
coreOffersService.createOffer(currencyCode,
public Offer createOffer(String currencyCode,
String directionAsString,
long priceAsLong,
boolean useMarketBasedPrice,
double marketPriceMargin,
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
String paymentAccountId,
TransactionResultHandler resultHandler) {
return coreOffersService.createOffer(currencyCode,
directionAsString,
priceAsLong,
useMarketBasedPrice,
Expand All @@ -109,19 +109,19 @@ public void createOffer(String currencyCode,
resultHandler);
}

public void createOffer(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) {
coreOffersService.createOffer(offerId,
public Offer createOffer(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) {
return coreOffersService.createOffer(offerId,
currencyCode,
direction,
price,
Expand Down
85 changes: 62 additions & 23 deletions core/src/main/java/bisq/core/api/CoreOffersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ List<Offer> getOffers(String direction, String fiatCurrencyCode) {
return offers;
}

void createOffer(String currencyCode,
String directionAsString,
long priceAsLong,
boolean useMarketBasedPrice,
double marketPriceMargin,
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
String paymentAccountId,
TransactionResultHandler resultHandler) {
Offer createOffer(String currencyCode,
String directionAsString,
long priceAsLong,
boolean useMarketBasedPrice,
double marketPriceMargin,
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
String paymentAccountId,
TransactionResultHandler resultHandler) {
String offerId = createOfferService.getRandomOfferId();
OfferPayload.Direction direction = OfferPayload.Direction.valueOf(directionAsString);
Price price = Price.valueOf(currencyCode, priceAsLong);
Expand All @@ -97,7 +97,7 @@ void createOffer(String currencyCode,
boolean useSavingsWallet = true;

//noinspection ConstantConditions
createOffer(offerId,
return createAndPlaceOffer(offerId,
currencyCode,
direction,
price,
Expand All @@ -111,19 +111,56 @@ void createOffer(String currencyCode,
resultHandler);
}

void createOffer(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) {
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,
direction,
currencyCode,
amount,
minAmount,
price,
useDefaultTxFee,
useMarketBasedPrice,
marketPriceMargin,
buyerSecurityDeposit,
paymentAccount);

// 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,
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,
direction,
currencyCode,
Expand All @@ -141,5 +178,7 @@ void createOffer(String offerId,
useSavingsWallet,
resultHandler,
log::error);

return offer;
}
}
64 changes: 50 additions & 14 deletions daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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;
Expand All @@ -27,11 +28,14 @@
import bisq.proto.grpc.GetOffersRequest;
import bisq.proto.grpc.OffersGrpc;

import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.stub.StreamObserver;

import javax.inject.Inject;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -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();
ghubstan marked this conversation as resolved.
Show resolved Hide resolved
};
Offer offer = coreApi.createOffer(
req.getCurrencyCode(),
req.getDirection(),
req.getPrice(),
req.getUseMarketBasedPrice(),
req.getMarketPriceMargin(),
req.getAmount(),
req.getMinAmount(),
req.getBuyerSecurityDeposit(),
req.getPaymentAccountId(),
resultHandler);
try {
latch.await();
} catch (InterruptedException ignored) {
// empty
}

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();
};
coreApi.createOffer(
req.getCurrencyCode(),
req.getDirection(),
req.getPrice(),
req.getUseMarketBasedPrice(),
req.getMarketPriceMargin(),
req.getAmount(),
req.getMinAmount(),
req.getBuyerSecurityDeposit(),
req.getPaymentAccountId(),
resultHandler);
} catch (IllegalStateException | IllegalArgumentException cause) {
var ex = new StatusRuntimeException(Status.UNKNOWN.withDescription(cause.getMessage()));
responseObserver.onError(ex);
throw ex;
}
}
}
2 changes: 1 addition & 1 deletion proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ message CreateOfferRequest {
}

message CreateOfferReply {
bool result = 1;
OfferInfo offer = 1;
}

message OfferInfo {
Expand Down