Search in sources :

Example 1 with SellerAsMakerTrade

use of io.bisq.core.trade.SellerAsMakerTrade in project bisq-api by mrosseel.

the class BisqProxy method paymentReceived.

public CompletableFuture<Void> paymentReceived(String tradeId) {
    final CompletableFuture<Void> futureResult = new CompletableFuture<>();
    Trade trade;
    try {
        trade = getTrade(tradeId);
    } catch (NotFoundException e) {
        return failFuture(futureResult, e);
    }
    if (!Trade.State.SELLER_RECEIVED_FIAT_PAYMENT_INITIATED_MSG.equals(trade.getState())) {
        return failFuture(futureResult, new ValidationException("Trade is not in the correct state to receive payment: " + trade.getState()));
    }
    TradeProtocol tradeProtocol = trade.getTradeProtocol();
    if (!(tradeProtocol instanceof SellerAsTakerProtocol || tradeProtocol instanceof SellerAsMakerProtocol)) {
        return failFuture(futureResult, new ValidationException("Trade is not in the correct state to receive payment: " + trade.getState()));
    }
    ResultHandler resultHandler = () -> futureResult.complete(null);
    ErrorMessageHandler errorResultHandler = message -> futureResult.completeExceptionally(new RuntimeException(message));
    // TODO I think we should check instance of tradeProtocol here instead of trade
    if (trade instanceof SellerAsMakerTrade) {
        ((SellerAsMakerProtocol) tradeProtocol).onFiatPaymentReceived(resultHandler, errorResultHandler);
    } else {
        ((SellerAsTakerProtocol) tradeProtocol).onFiatPaymentReceived(resultHandler, errorResultHandler);
    }
    return futureResult;
}
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) SellerAsMakerTrade(io.bisq.core.trade.SellerAsMakerTrade) ValidationException(javax.validation.ValidationException) ResultHandler(io.bisq.common.handlers.ResultHandler) ErrorMessageHandler(io.bisq.common.handlers.ErrorMessageHandler) SellerAsMakerTrade(io.bisq.core.trade.SellerAsMakerTrade) Trade(io.bisq.core.trade.Trade) BuyerAsMakerTrade(io.bisq.core.trade.BuyerAsMakerTrade) CompletableFuture(java.util.concurrent.CompletableFuture)

Aggregations

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 ArbitratorManager (io.bisq.core.arbitration.ArbitratorManager)1 AddressEntry (io.bisq.core.btc.AddressEntry)1 Restrictions (io.bisq.core.btc.Restrictions)1 BsqWalletService (io.bisq.core.btc.wallet.BsqWalletService)1 BtcWalletService (io.bisq.core.btc.wallet.BtcWalletService)1