mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Partially adjust core api for bsq-swap support
- Add core api methods to help CLI determine which type of offer to take for a given offerId. CLI's 'takeoffer` will need to determine which gRPC/proto request type to send to server. - Add implemetations for getBsqSwapTradeRole(), for tradeId or trade.
This commit is contained in:
parent
521495c41d
commit
3dfbf3f6f0
@ -119,6 +119,18 @@ public class CoreApi {
|
||||
// Offers
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public boolean isAvailableFiatOffer(String id) {
|
||||
return coreOffersService.isAvailableFiatOffer(id);
|
||||
}
|
||||
|
||||
public boolean isAvailableAltcoinOffer(String id) {
|
||||
return coreOffersService.isAvailableAltcoinOffer(id);
|
||||
}
|
||||
|
||||
public boolean isAvailableBsqSwapOffer(String id) {
|
||||
return coreOffersService.isAvailableBsqSwapOffer(id);
|
||||
}
|
||||
|
||||
public Offer getBsqSwapOffer(String id) {
|
||||
return coreOffersService.getBsqSwapOffer(id);
|
||||
}
|
||||
@ -317,6 +329,14 @@ public class CoreApi {
|
||||
return coreTradesService.getTradeRole(tradeId);
|
||||
}
|
||||
|
||||
public String getBsqSwapTradeRole(String tradeId) {
|
||||
return coreTradesService.getBsqSwapTradeRole(tradeId);
|
||||
}
|
||||
|
||||
public String getBsqSwapTradeRole(BsqSwapTrade bsqSwapTrade) {
|
||||
return coreTradesService.getBsqSwapTradeRole(bsqSwapTrade);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Wallets
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -60,6 +60,9 @@ import static bisq.common.util.MathUtils.scaleUpByPowerOf10;
|
||||
import static bisq.core.locale.CurrencyUtil.isCryptoCurrency;
|
||||
import static bisq.core.offer.Offer.State;
|
||||
import static bisq.core.offer.OfferDirection.BUY;
|
||||
import static bisq.core.offer.OfferUtil.getRandomOfferId;
|
||||
import static bisq.core.offer.OfferUtil.isAltcoinOffer;
|
||||
import static bisq.core.offer.OfferUtil.isFiatOffer;
|
||||
import static bisq.core.offer.OpenOffer.State.AVAILABLE;
|
||||
import static bisq.core.offer.OpenOffer.State.DEACTIVATED;
|
||||
import static bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer;
|
||||
@ -118,6 +121,19 @@ class CoreOffersService {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
boolean isAvailableFiatOffer(String id) {
|
||||
return isFiatOffer(getOffer(id));
|
||||
}
|
||||
|
||||
boolean isAvailableAltcoinOffer(String id) {
|
||||
return isAltcoinOffer(getOffer(id));
|
||||
}
|
||||
|
||||
boolean isAvailableBsqSwapOffer(String id) {
|
||||
var offer = getOffer(id);
|
||||
return offer.isBsqSwapOffer();
|
||||
}
|
||||
|
||||
Offer getBsqSwapOffer(String id) {
|
||||
return offerBookService.getOffers().stream()
|
||||
.filter(o -> o.getId().equals(id))
|
||||
@ -154,7 +170,6 @@ class CoreOffersService {
|
||||
new IllegalStateException(format("offer with id '%s' not found", id)));
|
||||
}
|
||||
|
||||
|
||||
List<Offer> getBsqSwapOffers(String direction) {
|
||||
var offers = offerBookService.getOffers().stream()
|
||||
.filter(o -> !o.isMyOffer(keyRing))
|
||||
@ -208,9 +223,12 @@ class CoreOffersService {
|
||||
}
|
||||
|
||||
boolean isMyOffer(String id) {
|
||||
return openOfferManager.getOpenOfferById(id)
|
||||
boolean isMyOpenOffer = openOfferManager.getOpenOfferById(id)
|
||||
.filter(open -> open.getOffer().isMyOffer(keyRing))
|
||||
.isPresent();
|
||||
boolean wasMyOffer = offerBookService.getOffers().stream()
|
||||
.anyMatch(o -> o.getId().equals(id) && o.isMyOffer(keyRing));
|
||||
return isMyOpenOffer || wasMyOffer;
|
||||
}
|
||||
|
||||
void createAndPlaceBsqSwapOffer(String directionAsString,
|
||||
@ -222,7 +240,7 @@ class CoreOffersService {
|
||||
coreWalletsService.verifyEncryptedWalletIsUnlocked();
|
||||
|
||||
String currencyCode = "BSQ";
|
||||
String offerId = OfferUtil.getRandomOfferId();
|
||||
String offerId = getRandomOfferId();
|
||||
OfferDirection direction = OfferDirection.valueOf(directionAsString.toUpperCase());
|
||||
Coin amount = Coin.valueOf(amountAsLong);
|
||||
Coin minAmount = Coin.valueOf(minAmountAsLong);
|
||||
@ -256,7 +274,7 @@ class CoreOffersService {
|
||||
throw new IllegalArgumentException(format("payment account with id %s not found", paymentAccountId));
|
||||
|
||||
String upperCaseCurrencyCode = currencyCode.toUpperCase();
|
||||
String offerId = OfferUtil.getRandomOfferId();
|
||||
String offerId = getRandomOfferId();
|
||||
OfferDirection direction = OfferDirection.valueOf(directionAsString.toUpperCase());
|
||||
Price price = Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode));
|
||||
Coin amount = Coin.valueOf(amountAsLong);
|
||||
@ -427,10 +445,9 @@ class CoreOffersService {
|
||||
private boolean offerMatchesDirectionAndCurrency(Offer offer,
|
||||
String direction,
|
||||
String currencyCode) {
|
||||
var offerOfWantedDirection = offer.getDirection().name().equalsIgnoreCase(direction);
|
||||
var offerInWantedCurrency = offer.getCounterCurrencyCode()
|
||||
.equalsIgnoreCase(currencyCode);
|
||||
return offerOfWantedDirection && offerInWantedCurrency;
|
||||
var isDirectionMatch = offer.getDirection().name().equalsIgnoreCase(direction);
|
||||
var isCurrencyMatch = offer.getCounterCurrencyCode().equalsIgnoreCase(currencyCode);
|
||||
return isDirectionMatch && isCurrencyMatch;
|
||||
}
|
||||
|
||||
private Comparator<OpenOffer> openOfferPriceComparator(String direction) {
|
||||
|
@ -108,8 +108,10 @@ class CoreTradesService {
|
||||
log.info("Initiating take {} offer, {}",
|
||||
offer.isBuyOffer() ? "buy" : "sell",
|
||||
bsqSwapTakeOfferModel);
|
||||
|
||||
bsqSwapTakeOfferModel.onTakeOffer(tradeResultHandler, log::warn, errorMessageHandler, coreContext.isApiUser());
|
||||
bsqSwapTakeOfferModel.onTakeOffer(tradeResultHandler,
|
||||
log::warn,
|
||||
errorMessageHandler,
|
||||
coreContext.isApiUser());
|
||||
}
|
||||
|
||||
void takeOffer(Offer offer,
|
||||
@ -239,6 +241,16 @@ class CoreTradesService {
|
||||
new IllegalArgumentException(format("trade with id '%s' not found", tradeId)));
|
||||
}
|
||||
|
||||
String getBsqSwapTradeRole(String tradeId) {
|
||||
return getBsqSwapTradeRole(getBsqSwapTrade(tradeId));
|
||||
}
|
||||
|
||||
String getBsqSwapTradeRole(BsqSwapTrade bsqSwapTrade) {
|
||||
coreWalletsService.verifyWalletsAreAvailable();
|
||||
coreWalletsService.verifyEncryptedWalletIsUnlocked();
|
||||
return tradeUtil.getRole(bsqSwapTrade);
|
||||
}
|
||||
|
||||
String getTradeRole(String tradeId) {
|
||||
coreWalletsService.verifyWalletsAreAvailable();
|
||||
coreWalletsService.verifyEncryptedWalletIsUnlocked();
|
||||
|
Loading…
Reference in New Issue
Block a user