Search in sources :

Example 1 with Trade

use of io.bisq.core.trade.Trade 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 Trade

use of io.bisq.core.trade.Trade 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)

Example 3 with Trade

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

the class BisqProxy method moveFundsToBisqWallet.

public void moveFundsToBisqWallet(String tradeId) {
    final Trade trade = getTrade(tradeId);
    btcWalletService.swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT);
    // TODO do we need to handle this ui stuff? --> handleTradeCompleted();
    tradeManager.addTradeToClosedTrades(trade);
}
Also used : SellerAsMakerTrade(io.bisq.core.trade.SellerAsMakerTrade) Trade(io.bisq.core.trade.Trade) BuyerAsMakerTrade(io.bisq.core.trade.BuyerAsMakerTrade)

Example 4 with Trade

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

the class BisqProxy method updateLockedBalance.

// TODO copied from MainViewModel - refactor !
private Coin updateLockedBalance() {
    Stream<Trade> lockedTrades = Stream.concat(closedTradableManager.getLockedTradesStream(), failedTradesManager.getLockedTradesStream());
    lockedTrades = Stream.concat(lockedTrades, tradeManager.getLockedTradesStream());
    Coin sum = Coin.valueOf(lockedTrades.mapToLong(trade -> {
        final Optional<AddressEntry> addressEntryOptional = btcWalletService.getAddressEntry(trade.getId(), AddressEntry.Context.MULTI_SIG);
        if (addressEntryOptional.isPresent())
            return addressEntryOptional.get().getCoinLockedInMultiSig().getValue();
        else
            return 0;
    }).sum());
    return sum;
}
Also used : SellerAsMakerTrade(io.bisq.core.trade.SellerAsMakerTrade) Trade(io.bisq.core.trade.Trade) BuyerAsMakerTrade(io.bisq.core.trade.BuyerAsMakerTrade) Coin(org.bitcoinj.core.Coin) AddressEntry(io.bisq.core.btc.AddressEntry)

Example 5 with Trade

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

the class MainViewModelHeadless method onBasicServicesInitialized.

private void onBasicServicesInitialized() {
    log.info("onBasicServicesInitialized");
    clock.start();
    PaymentMethod.onAllServicesInitialized();
    // disputeManager
    disputeManager.onAllServicesInitialized();
    disputeManager.getDisputesAsObservableList().addListener((ListChangeListener<Dispute>) change -> {
        change.next();
        onDisputesChangeListener(change.getAddedSubList(), change.getRemoved());
    });
    onDisputesChangeListener(disputeManager.getDisputesAsObservableList(), null);
    // tradeManager
    tradeManager.onAllServicesInitialized();
    tradeManager.getTradableList().addListener((ListChangeListener<Trade>) c -> updateBalance());
    tradeManager.getTradableList().addListener((ListChangeListener<Trade>) change -> onTradesChanged());
    onTradesChanged();
    // We handle the trade period here as we display a global popup if we reached dispute time
    tradesAndUIReady = EasyBind.combine(isSplashScreenRemoved, tradeManager.pendingTradesInitializedProperty(), (a, b) -> a && b);
    tradesAndUIReady.subscribe((observable, oldValue, newValue) -> {
        if (newValue)
            applyTradePeriodState();
    });
    // tradeManager.setTakeOfferRequestErrorMessageHandler(errorMessage -> new Popup<>()
    // .warning(Res.get("popup.error.takeOfferRequestFailed", errorMessage))
    // .show());
    // walletService
    btcWalletService.addBalanceListener(new BalanceListener() {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateBalance();
        }
    });
    openOfferManager.getObservableList().addListener((ListChangeListener<OpenOffer>) c -> updateBalance());
    tradeManager.getTradableList().addListener((ListChangeListener<Trade>) c -> updateBalance());
    openOfferManager.onAllServicesInitialized();
    removeOffersWithoutAccountAgeWitness();
    arbitratorManager.onAllServicesInitialized();
    alertManager.alertMessageProperty().addListener((observable, oldValue, newValue) -> displayAlertIfPresent(newValue, false));
    privateNotificationManager.privateNotificationProperty().addListener((observable, oldValue, newValue) -> displayPrivateNotification(newValue));
    displayAlertIfPresent(alertManager.alertMessageProperty().get(), false);
    p2PService.onAllServicesInitialized();
    feeService.onAllServicesInitialized();
    GUIUtil.setFeeService(feeService);
    // daoManager.onAllServicesInitialized(errorMessage -> new Popup<>().error(errorMessage).show());
    tradeStatisticsManager.onAllServicesInitialized();
    accountAgeWitnessService.onAllServicesInitialized();
    priceFeedService.setCurrencyCodeOnInit();
    filterManager.onAllServicesInitialized();
    // filterManager.addListener(filter -> {
    // if (filter != null) {
    // if (filter.getSeedNodes() != null && !filter.getSeedNodes().isEmpty())
    // new Popup<>().warning(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.seed"))).show();
    // 
    // if (filter.getPriceRelayNodes() != null && !filter.getPriceRelayNodes().isEmpty())
    // new Popup<>().warning(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.priceRelay"))).show();
    // }
    // });
    setupBtcNumPeersWatcher();
    setupP2PNumPeersWatcher();
    updateBalance();
    if (DevEnv.DEV_MODE) {
        preferences.setShowOwnOffersInOfferBook(true);
        setupDevDummyPaymentAccounts();
    }
    fillPriceFeedComboBoxItems();
    setupMarketPriceFeed();
    swapPendingOfferFundingEntries();
    showAppScreen.set(true);
    // String key = "remindPasswordAndBackup";
    // user.getPaymentAccountsAsObservable().addListener((SetChangeListener<PaymentAccount>) change -> {
    // if (!walletsManager.areWalletsEncrypted() && preferences.showAgain(key) && change.wasAdded()) {
    // new Popup<>().headLine(Res.get("popup.securityRecommendation.headline"))
    // .information(Res.get("popup.securityRecommendation.msg"))
    // .dontShowAgainId(key)
    // .show();
    // }
    // });
    checkIfOpenOffersMatchTradeProtocolVersion();
    if (walletsSetup.downloadPercentageProperty().get() == 1)
        checkForLockedUpFunds();
    allBasicServicesInitialized = true;
}
Also used : Alert(io.bisq.core.alert.Alert) AccountAgeWitnessService(io.bisq.core.payment.AccountAgeWitnessService) Transaction(org.bitcoinj.core.Transaction) NotificationCenter(io.bisq.gui.main.overlays.notifications.NotificationCenter) Coin(org.bitcoinj.core.Coin) Inject(com.google.inject.Inject) User(io.bisq.core.user.User) UserThread(io.bisq.common.UserThread) Security(java.security.Security) TimeoutException(java.util.concurrent.TimeoutException) PrivateNotificationPayload(io.bisq.core.alert.PrivateNotificationPayload) ChainFileLockedException(org.bitcoinj.store.ChainFileLockedException) ListChangeListener(javafx.collections.ListChangeListener) FeeService(io.bisq.core.provider.fee.FeeService) ClosedTradableManager(io.bisq.core.trade.closed.ClosedTradableManager) DecryptedDataTuple(io.bisq.network.crypto.DecryptedDataTuple) DisputeManager(io.bisq.core.arbitration.DisputeManager) CurrencyUtil(io.bisq.common.locale.CurrencyUtil) BlockStoreException(org.bitcoinj.store.BlockStoreException) PaymentMethod(io.bisq.core.payment.payload.PaymentMethod) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) BootstrapListener(io.bisq.network.p2p.BootstrapListener) GUIUtil(io.bisq.gui.util.GUIUtil) PrivateNotificationManager(io.bisq.core.alert.PrivateNotificationManager) Ping(io.bisq.network.p2p.peers.keepalive.messages.Ping) DaoManager(io.bisq.core.dao.DaoManager) BSFormatter(io.bisq.gui.util.BSFormatter) PriceFeedComboBoxItem(io.bisq.gui.main.PriceFeedComboBoxItem) GlobalSettings(io.bisq.common.GlobalSettings) Res(io.bisq.common.locale.Res) WalletsManager(io.bisq.core.btc.wallet.WalletsManager) Subscription(org.fxmisc.easybind.Subscription) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) BtcWalletService(io.bisq.core.btc.wallet.BtcWalletService) EncryptionService(io.bisq.network.crypto.EncryptionService) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) OpenOfferManager(io.bisq.core.offer.OpenOfferManager) Address(org.bitcoinj.core.Address) KeyRing(io.bisq.common.crypto.KeyRing) ObservableList(javafx.collections.ObservableList) PriceFeedService(io.bisq.core.provider.price.PriceFeedService) CryptoCurrencyAccount(io.bisq.core.payment.CryptoCurrencyAccount) TradeManager(io.bisq.core.trade.TradeManager) Socket(java.net.Socket) java.util(java.util) Dispute(io.bisq.core.arbitration.Dispute) ArbitratorManager(io.bisq.core.arbitration.ArbitratorManager) TradeCurrency(io.bisq.common.locale.TradeCurrency) Clock(io.bisq.common.Clock) Preferences(io.bisq.core.user.Preferences) FXCollections(javafx.collections.FXCollections) PerfectMoneyAccount(io.bisq.core.payment.PerfectMoneyAccount) TradeStatisticsManager(io.bisq.core.trade.statistics.TradeStatisticsManager) DontShowAgainLookup(io.bisq.core.user.DontShowAgainLookup) AlertManager(io.bisq.core.alert.AlertManager) FilterManager(io.bisq.core.filter.FilterManager) ConnectionListener(io.bisq.network.p2p.network.ConnectionListener) Trade(io.bisq.core.trade.Trade) FailedTradesManager(io.bisq.core.trade.failed.FailedTradesManager) MarketPrice(io.bisq.core.provider.price.MarketPrice) P2PServiceListener(io.bisq.network.p2p.P2PServiceListener) OpenOffer(io.bisq.core.offer.OpenOffer) Connection(io.bisq.network.p2p.network.Connection) Nullable(javax.annotation.Nullable) javafx.beans.property(javafx.beans.property) BisqEnvironment(io.bisq.core.app.BisqEnvironment) AddressEntry(io.bisq.core.btc.AddressEntry) SealedAndSigned(io.bisq.common.crypto.SealedAndSigned) SetupUtils(io.bisq.core.app.SetupUtils) AppOptionKeys(io.bisq.core.app.AppOptionKeys) IOException(java.io.IOException) CryptoException(io.bisq.common.crypto.CryptoException) TimeUnit(java.util.concurrent.TimeUnit) WalletsSetup(io.bisq.core.btc.wallet.WalletsSetup) CloseConnectionReason(io.bisq.network.p2p.network.CloseConnectionReason) BalanceListener(io.bisq.core.btc.listeners.BalanceListener) P2PService(io.bisq.network.p2p.P2PService) EasyBind(org.fxmisc.easybind.EasyBind) DevEnv(io.bisq.common.app.DevEnv) Timer(io.bisq.common.Timer) InetAddresses(com.google.common.net.InetAddresses) ChangeListener(javafx.beans.value.ChangeListener) Trade(io.bisq.core.trade.Trade) Coin(org.bitcoinj.core.Coin) BalanceListener(io.bisq.core.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) OpenOffer(io.bisq.core.offer.OpenOffer) Dispute(io.bisq.core.arbitration.Dispute)

Aggregations

Trade (io.bisq.core.trade.Trade)8 Coin (org.bitcoinj.core.Coin)6 AddressEntry (io.bisq.core.btc.AddressEntry)5 BuyerAsMakerTrade (io.bisq.core.trade.BuyerAsMakerTrade)5 SellerAsMakerTrade (io.bisq.core.trade.SellerAsMakerTrade)5 Slf4j (lombok.extern.slf4j.Slf4j)4 io.bisq.api.model (io.bisq.api.model)3 DevEnv (io.bisq.common.app.DevEnv)3 KeyRing (io.bisq.common.crypto.KeyRing)3 CurrencyUtil (io.bisq.common.locale.CurrencyUtil)3 TradeCurrency (io.bisq.common.locale.TradeCurrency)3 BisqEnvironment (io.bisq.core.app.BisqEnvironment)3 ArbitratorManager (io.bisq.core.arbitration.ArbitratorManager)3 BtcWalletService (io.bisq.core.btc.wallet.BtcWalletService)3 WalletsSetup (io.bisq.core.btc.wallet.WalletsSetup)3 AccountAgeWitnessService (io.bisq.core.payment.AccountAgeWitnessService)3 CryptoCurrencyAccount (io.bisq.core.payment.CryptoCurrencyAccount)3 FeeService (io.bisq.core.provider.fee.FeeService)3 TradeManager (io.bisq.core.trade.TradeManager)3 ClosedTradableManager (io.bisq.core.trade.closed.ClosedTradableManager)3