Search in sources :

Example 1 with ErrorMessageHandler

use of io.bisq.common.handlers.ErrorMessageHandler in project bisq-api by mrosseel.

the class BisqProxy method paymentStarted.

public CompletableFuture<Void> paymentStarted(String tradeId) {
    final CompletableFuture<Void> futureResult = new CompletableFuture<>();
    Trade trade;
    try {
        trade = getTrade(tradeId);
    } catch (NotFoundException e) {
        return failFuture(futureResult, e);
    }
    if (!Trade.State.DEPOSIT_CONFIRMED_IN_BLOCK_CHAIN.equals(trade.getState())) {
        return failFuture(futureResult, new ValidationException("Trade is not in the correct state to start payment: " + trade.getState()));
    }
    TradeProtocol tradeProtocol = trade.getTradeProtocol();
    ResultHandler resultHandler = () -> futureResult.complete(null);
    ErrorMessageHandler errorResultHandler = message -> futureResult.completeExceptionally(new RuntimeException(message));
    if (trade instanceof BuyerAsMakerTrade) {
        ((BuyerAsMakerProtocol) tradeProtocol).onFiatPaymentStarted(resultHandler, errorResultHandler);
    } else {
        ((BuyerAsTakerProtocol) tradeProtocol).onFiatPaymentStarted(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) 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) BuyerAsMakerTrade(io.bisq.core.trade.BuyerAsMakerTrade)

Example 2 with ErrorMessageHandler

use of io.bisq.common.handlers.ErrorMessageHandler 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)2 Strings (com.google.common.base.Strings)2 Injector (com.google.inject.Injector)2 io.bisq.api.model (io.bisq.api.model)2 PaymentAccountHelper (io.bisq.api.model.payment.PaymentAccountHelper)2 DevEnv (io.bisq.common.app.DevEnv)2 KeyRing (io.bisq.common.crypto.KeyRing)2 ErrorMessageHandler (io.bisq.common.handlers.ErrorMessageHandler)2 ResultHandler (io.bisq.common.handlers.ResultHandler)2 CryptoCurrency (io.bisq.common.locale.CryptoCurrency)2 CurrencyUtil (io.bisq.common.locale.CurrencyUtil)2 FiatCurrency (io.bisq.common.locale.FiatCurrency)2 TradeCurrency (io.bisq.common.locale.TradeCurrency)2 BisqEnvironment (io.bisq.core.app.BisqEnvironment)2 Arbitrator (io.bisq.core.arbitration.Arbitrator)2 ArbitratorManager (io.bisq.core.arbitration.ArbitratorManager)2 AddressEntry (io.bisq.core.btc.AddressEntry)2 Restrictions (io.bisq.core.btc.Restrictions)2 BsqWalletService (io.bisq.core.btc.wallet.BsqWalletService)2 BtcWalletService (io.bisq.core.btc.wallet.BtcWalletService)2