Search in sources :

Example 1 with PaymentAccount

use of io.bisq.core.payment.PaymentAccount in project bisq-api by mrosseel.

the class BisqProxy method addPaymentAccount.

public PaymentAccount addPaymentAccount(PaymentAccount paymentAccount) {
    user.addPaymentAccount(paymentAccount);
    TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
    List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
    if (singleTradeCurrency != null) {
        if (singleTradeCurrency instanceof FiatCurrency)
            preferences.addFiatCurrency((FiatCurrency) singleTradeCurrency);
        else
            preferences.addCryptoCurrency((CryptoCurrency) singleTradeCurrency);
    } else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
        if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency()))
            paymentAccount.setSelectedTradeCurrency(CurrencyUtil.getDefaultTradeCurrency());
        else
            paymentAccount.setSelectedTradeCurrency(tradeCurrencies.get(0));
        tradeCurrencies.forEach(tradeCurrency -> {
            if (tradeCurrency instanceof FiatCurrency)
                preferences.addFiatCurrency((FiatCurrency) tradeCurrency);
            else
                preferences.addCryptoCurrency((CryptoCurrency) tradeCurrency);
        });
    }
    accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload());
    return paymentAccount;
}
Also used : AccountAgeWitnessService(io.bisq.core.payment.AccountAgeWitnessService) Transaction(org.bitcoinj.core.Transaction) PaymentAccount(io.bisq.core.payment.PaymentAccount) io.bisq.core.trade.protocol(io.bisq.core.trade.protocol) Coin(org.bitcoinj.core.Coin) User(io.bisq.core.user.User) BigDecimal(java.math.BigDecimal) CoinUtil(io.bisq.core.util.CoinUtil) FeeService(io.bisq.core.provider.fee.FeeService) ClosedTradableManager(io.bisq.core.trade.closed.ClosedTradableManager) ResultHandler(io.bisq.common.handlers.ResultHandler) CurrencyUtil(io.bisq.common.locale.CurrencyUtil) NodeAddress(io.bisq.network.p2p.NodeAddress) PaymentAccountHelper(io.bisq.api.model.payment.PaymentAccountHelper) Collectors(java.util.stream.Collectors) io.bisq.core.offer(io.bisq.core.offer) ECKey(org.bitcoinj.core.ECKey) Platform(javafx.application.Platform) BtcWalletService(io.bisq.core.btc.wallet.BtcWalletService) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Arbitrator(io.bisq.core.arbitration.Arbitrator) Address(org.bitcoinj.core.Address) KeyRing(io.bisq.common.crypto.KeyRing) ObservableList(javafx.collections.ObservableList) NotNull(org.jetbrains.annotations.NotNull) SellerAsMakerTrade(io.bisq.core.trade.SellerAsMakerTrade) CryptoCurrencyAccount(io.bisq.core.payment.CryptoCurrencyAccount) TradeManager(io.bisq.core.trade.TradeManager) java.util(java.util) Getter(lombok.Getter) ArbitratorManager(io.bisq.core.arbitration.ArbitratorManager) CryptoCurrency(io.bisq.common.locale.CryptoCurrency) TradeCurrency(io.bisq.common.locale.TradeCurrency) Preferences(io.bisq.core.user.Preferences) CompletableFuture(java.util.concurrent.CompletableFuture) PaymentAccountUtil.isPaymentAccountValidForOffer(io.bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer) Strings(com.google.common.base.Strings) ErrorMessageHandler(io.bisq.common.handlers.ErrorMessageHandler) Trade(io.bisq.core.trade.Trade) FailedTradesManager(io.bisq.core.trade.failed.FailedTradesManager) io.bisq.api.model(io.bisq.api.model) BuyerAsMakerTrade(io.bisq.core.trade.BuyerAsMakerTrade) Nullable(javax.annotation.Nullable) BisqEnvironment(io.bisq.core.app.BisqEnvironment) AddressEntry(io.bisq.core.btc.AddressEntry) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BsqWalletService(io.bisq.core.btc.wallet.BsqWalletService) Injector(com.google.inject.Injector) WalletsSetup(io.bisq.core.btc.wallet.WalletsSetup) Collectors.toList(java.util.stream.Collectors.toList) P2PService(io.bisq.network.p2p.P2PService) ValidationException(javax.validation.ValidationException) DevEnv(io.bisq.common.app.DevEnv) FiatCurrency(io.bisq.common.locale.FiatCurrency) Restrictions(io.bisq.core.btc.Restrictions) CryptoCurrency(io.bisq.common.locale.CryptoCurrency) TradeCurrency(io.bisq.common.locale.TradeCurrency) FiatCurrency(io.bisq.common.locale.FiatCurrency)

Example 2 with PaymentAccount

use of io.bisq.core.payment.PaymentAccount in project bisq-api by mrosseel.

the class BisqProxy method offerTake.

// / START TODO REFACTOR OFFER TAKE DEPENDENCIES //////////////////////////
public CompletableFuture<Trade> offerTake(String offerId, String paymentAccountId, String amount, boolean useSavingsWallet) {
    final CompletableFuture<Trade> futureResult = new CompletableFuture<>();
    final Offer offer;
    try {
        offer = getOffer(offerId);
    } catch (NotFoundException e) {
        return failFuture(futureResult, e);
    }
    // check the paymentAccountId is valid
    final PaymentAccount paymentAccount = getPaymentAccount(paymentAccountId);
    if (paymentAccount == null) {
        return failFuture(futureResult, new PaymentAccountNotFoundException("Could not find payment account with id: " + paymentAccountId));
    }
    // check the paymentAccountId is compatible with the offer
    if (!isPaymentAccountValidForOffer(offer, paymentAccount)) {
        final String errorMessage = "PaymentAccount is not valid for offer, needs " + offer.getCurrencyCode();
        return failFuture(futureResult, new IncompatiblePaymentAccountException(errorMessage));
    }
    // check the amount is within the range
    Coin coinAmount = Coin.valueOf(Long.valueOf(amount));
    // workaround because TradeTask does not have an error handler to notify us that something went wrong
    if (btcWalletService.getAvailableBalance().isLessThan(coinAmount)) {
        final String errorMessage = "Available balance " + btcWalletService.getAvailableBalance() + " is less than needed amount: " + coinAmount;
        return failFuture(futureResult, new InsufficientMoneyException(errorMessage));
    }
    // check that the price is correct ??
    // check taker fee
    // check security deposit for BTC buyer
    // check security deposit for BTC seller
    Coin securityDeposit = offer.getDirection() == OfferPayload.Direction.SELL ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit();
    Coin txFeeFromFeeService = feeService.getTxFee(600);
    Coin fundsNeededForTradeTemp = securityDeposit.add(txFeeFromFeeService).add(txFeeFromFeeService);
    final Coin fundsNeededForTrade;
    if (offer.isBuyOffer())
        fundsNeededForTrade = fundsNeededForTradeTemp.add(coinAmount);
    else
        fundsNeededForTrade = fundsNeededForTradeTemp;
    Coin takerFee = getTakerFee(coinAmount);
    checkNotNull(txFeeFromFeeService, "txFeeFromFeeService must not be null");
    checkNotNull(takerFee, "takerFee must not be null");
    tradeManager.onTakeOffer(coinAmount, txFeeFromFeeService, takerFee, isCurrencyForTakerFeeBtc(coinAmount), offer.getPrice().getValue(), fundsNeededForTrade, offer, paymentAccount.getId(), useSavingsWallet, futureResult::complete, error -> futureResult.completeExceptionally(new RuntimeException(error)));
    return futureResult;
}
Also used : PaymentAccount(io.bisq.core.payment.PaymentAccount) SellerAsMakerTrade(io.bisq.core.trade.SellerAsMakerTrade) Trade(io.bisq.core.trade.Trade) BuyerAsMakerTrade(io.bisq.core.trade.BuyerAsMakerTrade) Coin(org.bitcoinj.core.Coin) CompletableFuture(java.util.concurrent.CompletableFuture) PaymentAccountUtil.isPaymentAccountValidForOffer(io.bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer)

Example 3 with PaymentAccount

use of io.bisq.core.payment.PaymentAccount in project bisq-api by mrosseel.

the class BisqProxy method removePaymentAccount.

public void removePaymentAccount(String id) {
    final PaymentAccount paymentAccount = user.getPaymentAccount(id);
    if (null == paymentAccount) {
        throw new NotFoundException("Payment account not found: " + id);
    }
    user.removePaymentAccount(paymentAccount);
}
Also used : PaymentAccount(io.bisq.core.payment.PaymentAccount)

Aggregations

PaymentAccount (io.bisq.core.payment.PaymentAccount)3 PaymentAccountUtil.isPaymentAccountValidForOffer (io.bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer)2 BuyerAsMakerTrade (io.bisq.core.trade.BuyerAsMakerTrade)2 SellerAsMakerTrade (io.bisq.core.trade.SellerAsMakerTrade)2 Trade (io.bisq.core.trade.Trade)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Strings (com.google.common.base.Strings)1 Injector (com.google.inject.Injector)1 io.bisq.api.model (io.bisq.api.model)1 PaymentAccountHelper (io.bisq.api.model.payment.PaymentAccountHelper)1 DevEnv (io.bisq.common.app.DevEnv)1 KeyRing (io.bisq.common.crypto.KeyRing)1 ErrorMessageHandler (io.bisq.common.handlers.ErrorMessageHandler)1 ResultHandler (io.bisq.common.handlers.ResultHandler)1 CryptoCurrency (io.bisq.common.locale.CryptoCurrency)1 CurrencyUtil (io.bisq.common.locale.CurrencyUtil)1 FiatCurrency (io.bisq.common.locale.FiatCurrency)1 TradeCurrency (io.bisq.common.locale.TradeCurrency)1 BisqEnvironment (io.bisq.core.app.BisqEnvironment)1 Arbitrator (io.bisq.core.arbitration.Arbitrator)1