use of bisq.core.payment.SepaInstantAccount in project bisq-desktop by bisq-network.
the class CreateOfferDataModel method createAndGetOffer.
// /////////////////////////////////////////////////////////////////////////////////////////
// UI actions
// /////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("ConstantConditions")
Offer createAndGetOffer() {
final boolean useMarketBasedPriceValue = marketPriceAvailable && useMarketBasedPrice.get();
long priceAsLong = price.get() != null && !useMarketBasedPriceValue ? price.get().getValue() : 0L;
String currencyCode = tradeCurrencyCode.get();
boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(currencyCode);
String baseCurrencyCode = isCryptoCurrency ? currencyCode : Res.getBaseCurrencyCode();
String counterCurrencyCode = isCryptoCurrency ? Res.getBaseCurrencyCode() : currencyCode;
double marketPriceMarginParam = useMarketBasedPriceValue ? marketPriceMargin : 0;
long amount = this.amount.get() != null ? this.amount.get().getValue() : 0L;
long minAmount = this.minAmount.get() != null ? this.minAmount.get().getValue() : 0L;
ArrayList<String> acceptedCountryCodes = null;
if (paymentAccount instanceof SepaAccount) {
acceptedCountryCodes = new ArrayList<>();
acceptedCountryCodes.addAll(((SepaAccount) paymentAccount).getAcceptedCountryCodes());
} else if (paymentAccount instanceof SepaInstantAccount) {
acceptedCountryCodes = new ArrayList<>();
acceptedCountryCodes.addAll(((SepaInstantAccount) paymentAccount).getAcceptedCountryCodes());
} else if (paymentAccount instanceof CountryBasedPaymentAccount) {
acceptedCountryCodes = new ArrayList<>();
acceptedCountryCodes.add(((CountryBasedPaymentAccount) paymentAccount).getCountry().code);
}
ArrayList<String> acceptedBanks = null;
if (paymentAccount instanceof SpecificBanksAccount) {
acceptedBanks = new ArrayList<>(((SpecificBanksAccount) paymentAccount).getAcceptedBanks());
} else if (paymentAccount instanceof SameBankAccount) {
acceptedBanks = new ArrayList<>();
acceptedBanks.add(((SameBankAccount) paymentAccount).getBankId());
}
String bankId = paymentAccount instanceof BankAccount ? ((BankAccount) paymentAccount).getBankId() : null;
// That is optional and set to null if not supported (AltCoins, OKPay,...)
String countryCode = paymentAccount instanceof CountryBasedPaymentAccount ? ((CountryBasedPaymentAccount) paymentAccount).getCountry().code : null;
checkNotNull(p2PService.getAddress(), "Address must not be null");
checkNotNull(getMakerFee(), "makerFee must not be null");
long maxTradeLimit = getMaxTradeLimit();
long maxTradePeriod = paymentAccount.getPaymentMethod().getMaxTradePeriod();
// reserved for future use cases
// Use null values if not set
boolean isPrivateOffer = false;
boolean useAutoClose = false;
boolean useReOpenAfterAutoClose = false;
long lowerClosePrice = 0;
long upperClosePrice = 0;
String hashOfChallenge = null;
HashMap<String, String> extraDataMap = null;
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
extraDataMap = new HashMap<>();
final String myWitnessHashAsHex = accountAgeWitnessService.getMyWitnessHashAsHex(paymentAccount.getPaymentAccountPayload());
extraDataMap.put(OfferPayload.ACCOUNT_AGE_WITNESS_HASH, myWitnessHashAsHex);
}
Coin buyerSecurityDepositAsCoin = buyerSecurityDeposit.get();
checkArgument(buyerSecurityDepositAsCoin.compareTo(Restrictions.getMaxBuyerSecurityDeposit()) <= 0, "securityDeposit must be not exceed " + Restrictions.getMaxBuyerSecurityDeposit().toFriendlyString());
checkArgument(buyerSecurityDepositAsCoin.compareTo(Restrictions.getMinBuyerSecurityDeposit()) >= 0, "securityDeposit must be not be less than " + Restrictions.getMinBuyerSecurityDeposit().toFriendlyString());
checkArgument(!filterManager.isCurrencyBanned(currencyCode), Res.get("offerbook.warning.currencyBanned"));
checkArgument(!filterManager.isPaymentMethodBanned(paymentAccount.getPaymentMethod()), Res.get("offerbook.warning.paymentMethodBanned"));
OfferPayload offerPayload = new OfferPayload(offerId, new Date().getTime(), p2PService.getAddress(), keyRing.getPubKeyRing(), OfferPayload.Direction.valueOf(direction.name()), priceAsLong, marketPriceMarginParam, useMarketBasedPriceValue, amount, minAmount, baseCurrencyCode, counterCurrencyCode, Lists.newArrayList(user.getAcceptedArbitratorAddresses()), Lists.newArrayList(user.getAcceptedMediatorAddresses()), paymentAccount.getPaymentMethod().getId(), paymentAccount.getId(), null, countryCode, acceptedCountryCodes, bankId, acceptedBanks, Version.VERSION, btcWalletService.getLastBlockSeenHeight(), txFeeFromFeeService.value, getMakerFee().value, isCurrencyForMakerFeeBtc(), buyerSecurityDepositAsCoin.value, sellerSecurityDeposit.value, maxTradeLimit, maxTradePeriod, useAutoClose, useReOpenAfterAutoClose, upperClosePrice, lowerClosePrice, isPrivateOffer, hashOfChallenge, extraDataMap, Version.TRADE_PROTOCOL_VERSION);
Offer offer = new Offer(offerPayload);
offer.setPriceFeedService(priceFeedService);
return offer;
}
use of bisq.core.payment.SepaInstantAccount in project bisq-api by mrosseel.
the class SepaInstantPaymentAccountConverter method toBusinessModel.
@Override
public SepaInstantAccount toBusinessModel(SepaInstantPaymentAccount rest) {
final SepaInstantAccount business = new SepaInstantAccount();
business.init();
business.setBic(rest.bic);
business.setIban(rest.iban);
business.setHolderName(rest.holderName);
business.setCountry(CountryUtil.findCountryByCode(rest.countryCode).get());
business.getAcceptedCountryCodes().clear();
if (null != rest.acceptedCountries)
rest.acceptedCountries.stream().forEach(business::addAcceptedCountry);
toBusinessModel(business, rest);
return business;
}
Aggregations