Search in sources :

Example 26 with Trade

use of 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 : Arrays(java.util.Arrays) OpenOffer(bisq.core.offer.OpenOffer) User(bisq.core.user.User) PriceFeed(network.bisq.api.model.PriceFeed) Statistic(bisq.network.p2p.network.Statistic) ZoneOffset(java.time.ZoneOffset) KeyParameter(org.spongycastle.crypto.params.KeyParameter) ClosedTradableDetails(network.bisq.api.model.ClosedTradableDetails) CurrencyList(network.bisq.api.model.CurrencyList) WalletAddress(network.bisq.api.model.WalletAddress) AddressEntryException(bisq.core.btc.AddressEntryException) Offer(bisq.core.offer.Offer) ClosedTradableManager(bisq.core.trade.closed.ClosedTradableManager) SellerAsMakerProtocol(bisq.core.trade.protocol.SellerAsMakerProtocol) WalletTransactionList(network.bisq.api.model.WalletTransactionList) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) Set(java.util.Set) TokenRegistry(network.bisq.api.service.TokenRegistry) BlockChainExplorer(bisq.core.user.BlockChainExplorer) TradeProtocol(bisq.core.trade.protocol.TradeProtocol) ZoneId(java.time.ZoneId) ECKey(org.bitcoinj.core.ECKey) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) AddressEntry(bisq.core.btc.AddressEntry) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) CryptoCurrency(bisq.core.locale.CryptoCurrency) Currency(network.bisq.api.model.Currency) TradeManager(bisq.core.trade.TradeManager) NodeAddress(bisq.network.p2p.NodeAddress) SellerAsTakerProtocol(bisq.core.trade.protocol.SellerAsTakerProtocol) CountryUtil(bisq.core.locale.CountryUtil) BuyerAsTakerProtocol(bisq.core.trade.protocol.BuyerAsTakerProtocol) TransactionOutput(org.bitcoinj.core.TransactionOutput) FeeService(bisq.core.provider.fee.FeeService) ObservableList(javafx.collections.ObservableList) PaymentAccountHelper(network.bisq.api.model.payment.PaymentAccountHelper) Restrictions(bisq.core.btc.Restrictions) Arbitrator(bisq.core.arbitration.Arbitrator) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) Wallet(org.bitcoinj.wallet.Wallet) Peer(org.bitcoinj.core.Peer) ArrayList(java.util.ArrayList) ClosedTradableConverter(network.bisq.api.model.ClosedTradableConverter) OfferPayload(bisq.core.offer.OfferPayload) Country(bisq.core.locale.Country) BitcoinNetworkStatus(network.bisq.api.model.BitcoinNetworkStatus) WalletDetails(network.bisq.api.model.WalletDetails) Nullable(javax.annotation.Nullable) IOException(java.io.IOException) OfferBookService(bisq.core.offer.OfferBookService) Names(com.google.inject.name.Names) BisqEnvironment(bisq.core.app.BisqEnvironment) SeedWords(network.bisq.api.model.SeedWords) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) OpenOfferManager(bisq.core.offer.OpenOfferManager) InputValidator(bisq.core.util.validation.InputValidator) PriceFeedService(bisq.core.provider.price.PriceFeedService) PaymentAccountList(network.bisq.api.model.PaymentAccountList) KeyRing(bisq.common.crypto.KeyRing) PreferencesAvailableValues(network.bisq.api.model.PreferencesAvailableValues) Transaction(org.bitcoinj.core.Transaction) Preferences(network.bisq.api.model.Preferences) Date(java.util.Date) Coin(org.bitcoinj.core.Coin) Key(com.google.inject.Key) AltCoinAddressValidator(bisq.core.payment.validation.AltCoinAddressValidator) VersionDetails(network.bisq.api.model.VersionDetails) Res(bisq.core.locale.Res) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt) PaymentAccountUtil.isPaymentAccountValidForOffer(bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer) OfferUtil(bisq.core.offer.OfferUtil) P2PService(bisq.network.p2p.P2PService) Predicate(java.util.function.Predicate) ArbitratorManager(bisq.core.arbitration.ArbitratorManager) Collection(java.util.Collection) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) FileUtil(bisq.common.storage.FileUtil) List(java.util.List) PaymentAccount(bisq.core.payment.PaymentAccount) DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) DevEnv(bisq.common.app.DevEnv) MarketList(network.bisq.api.model.MarketList) AppOptionKeys(bisq.core.app.AppOptionKeys) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Address(org.bitcoinj.core.Address) NotNull(org.jetbrains.annotations.NotNull) MarketPrice(bisq.core.provider.price.MarketPrice) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) TradeCurrency(bisq.core.locale.TradeCurrency) SellerAsMakerTrade(bisq.core.trade.SellerAsMakerTrade) Getter(lombok.Getter) WalletService(bisq.core.btc.wallet.WalletService) CompletableFuture(java.util.concurrent.CompletableFuture) FiatCurrency(bisq.core.locale.FiatCurrency) WalletsManager(bisq.core.btc.wallet.WalletsManager) Tuple2(bisq.common.util.Tuple2) BuyerAsMakerProtocol(bisq.core.trade.protocol.BuyerAsMakerProtocol) P2PNetworkStatus(network.bisq.api.model.P2PNetworkStatus) Market(network.bisq.api.model.Market) CurrencyUtil(bisq.core.locale.CurrencyUtil) BitcoinNodes(bisq.core.btc.BitcoinNodes) Version(bisq.common.app.Version) CryptoCurrencyAccount(bisq.core.payment.CryptoCurrencyAccount) P2PNetworkConnection(network.bisq.api.model.P2PNetworkConnection) BuyerAsMakerTrade(bisq.core.trade.BuyerAsMakerTrade) Trade(bisq.core.trade.Trade) WalletAddressList(network.bisq.api.model.WalletAddressList) ResultHandler(bisq.common.handlers.ResultHandler) FailedTradesManager(bisq.core.trade.failed.FailedTradesManager) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FileInputStream(java.io.FileInputStream) WalletTransaction(network.bisq.api.model.WalletTransaction) Injector(com.google.inject.Injector) Collectors.toList(java.util.stream.Collectors.toList) AuthResult(network.bisq.api.model.AuthResult) ValidationException(javax.validation.ValidationException) Storage(bisq.common.storage.Storage) Comparator(java.util.Comparator) Collections(java.util.Collections) CoinUtil(bisq.core.util.CoinUtil) InputStream(java.io.InputStream) ValidationException(javax.validation.ValidationException) BuyerAsTakerProtocol(bisq.core.trade.protocol.BuyerAsTakerProtocol) FileNotFoundException(java.io.FileNotFoundException) TradeProtocol(bisq.core.trade.protocol.TradeProtocol) ResultHandler(bisq.common.handlers.ResultHandler) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) SellerAsMakerTrade(bisq.core.trade.SellerAsMakerTrade) BuyerAsMakerTrade(bisq.core.trade.BuyerAsMakerTrade) Trade(bisq.core.trade.Trade) CompletableFuture(java.util.concurrent.CompletableFuture) BuyerAsMakerProtocol(bisq.core.trade.protocol.BuyerAsMakerProtocol) BuyerAsMakerTrade(bisq.core.trade.BuyerAsMakerTrade)

Example 27 with Trade

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

the class BisqProxy method withdrawFunds.

public void withdrawFunds(Set<String> sourceAddresses, Coin amountAsCoin, boolean feeExcluded, String targetAddress) throws AddressEntryException, InsufficientFundsException, AmountTooLowException {
    // get all address entries
    final List<AddressEntry> sourceAddressEntries = sourceAddresses.stream().filter(address -> null != address).map(address -> btcWalletService.getAddressEntryListAsImmutableList().stream().filter(addressEntry -> address.equals(addressEntry.getAddressString())).findFirst().orElse(null)).filter(item -> null != item).collect(Collectors.toList());
    // this filter matches all unauthorized address types
    Predicate<AddressEntry> filterNotAllowedAddressEntries = addressEntry -> !(AddressEntry.Context.AVAILABLE.equals(addressEntry.getContext()) || AddressEntry.Context.TRADE_PAYOUT.equals(addressEntry.getContext()));
    // check if there are any unauthorized address types
    if (sourceAddressEntries.stream().anyMatch(filterNotAllowedAddressEntries)) {
        throw new ValidationException("Funds can be withdrawn only from addresses with context AVAILABLE and TRADE_PAYOUT");
    }
    Coin sendersAmount;
    // We do not know sendersAmount if senderPaysFee is true. We repeat fee calculation after first attempt if senderPaysFee is true.
    Transaction feeEstimationTransaction;
    try {
        feeEstimationTransaction = btcWalletService.getFeeEstimationTransactionForMultipleAddresses(sourceAddresses, amountAsCoin);
    } catch (IllegalArgumentException e) {
        if (e.getMessage().contains("dust limit")) {
            throw new AmountTooLowException(e.getMessage());
        }
        throw e;
    }
    if (feeExcluded && feeEstimationTransaction != null) {
        sendersAmount = amountAsCoin.add(feeEstimationTransaction.getFee());
        feeEstimationTransaction = btcWalletService.getFeeEstimationTransactionForMultipleAddresses(sourceAddresses, sendersAmount);
    }
    checkNotNull(feeEstimationTransaction, "feeEstimationTransaction must not be null");
    Coin fee = feeEstimationTransaction.getFee();
    sendersAmount = feeExcluded ? amountAsCoin.add(fee) : amountAsCoin;
    Coin receiverAmount = feeExcluded ? amountAsCoin : amountAsCoin.subtract(fee);
    final Coin totalAvailableAmountOfSelectedItems = sourceAddressEntries.stream().map(address -> btcWalletService.getBalanceForAddress(address.getAddress())).reduce(Coin.ZERO, Coin::add);
    if (!sendersAmount.isPositive())
        throw new ValidationException("Senders amount must be positive");
    if (!new BtcAddressValidator().validate(targetAddress).isValid)
        throw new ValidationException("Invalid target address");
    if (sourceAddresses.isEmpty())
        throw new ValidationException("List of source addresses must not be empty");
    if (sendersAmount.compareTo(totalAvailableAmountOfSelectedItems) > 0)
        throw new InsufficientFundsException("Not enough funds in selected addresses");
    if (receiverAmount.isPositive()) {
        try {
            // TODO return completable future
            btcWalletService.sendFundsForMultipleAddresses(sourceAddresses, targetAddress, amountAsCoin, fee, null, null, new FutureCallback<Transaction>() {

                @Override
                public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
                    if (transaction != null) {
                        log.debug("onWithdraw onSuccess tx ID:" + transaction.getHashAsString());
                    } else {
                        log.error("onWithdraw transaction is null");
                    }
                    List<Trade> trades = new ArrayList<>(tradeManager.getTradableList());
                    trades.stream().filter(Trade::isPayoutPublished).forEach(trade -> btcWalletService.getAddressEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT).ifPresent(addressEntry -> {
                        if (btcWalletService.getBalanceForAddress(addressEntry.getAddress()).isZero())
                            tradeManager.addTradeToClosedTrades(trade);
                    }));
                }

                @Override
                public void onFailure(@NotNull Throwable t) {
                    log.error("onWithdraw onFailure");
                }
            });
        } catch (org.bitcoinj.core.InsufficientMoneyException e) {
            throw new InsufficientFundsException(e.getMessage());
        }
    } else {
        throw new AmountTooLowException(Res.get("portfolio.pending.step5_buyer.amountTooLow"));
    }
}
Also used : Arrays(java.util.Arrays) OpenOffer(bisq.core.offer.OpenOffer) User(bisq.core.user.User) PriceFeed(network.bisq.api.model.PriceFeed) Statistic(bisq.network.p2p.network.Statistic) ZoneOffset(java.time.ZoneOffset) KeyParameter(org.spongycastle.crypto.params.KeyParameter) ClosedTradableDetails(network.bisq.api.model.ClosedTradableDetails) CurrencyList(network.bisq.api.model.CurrencyList) WalletAddress(network.bisq.api.model.WalletAddress) AddressEntryException(bisq.core.btc.AddressEntryException) Offer(bisq.core.offer.Offer) ClosedTradableManager(bisq.core.trade.closed.ClosedTradableManager) SellerAsMakerProtocol(bisq.core.trade.protocol.SellerAsMakerProtocol) WalletTransactionList(network.bisq.api.model.WalletTransactionList) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) Set(java.util.Set) TokenRegistry(network.bisq.api.service.TokenRegistry) BlockChainExplorer(bisq.core.user.BlockChainExplorer) TradeProtocol(bisq.core.trade.protocol.TradeProtocol) ZoneId(java.time.ZoneId) ECKey(org.bitcoinj.core.ECKey) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) AddressEntry(bisq.core.btc.AddressEntry) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) CryptoCurrency(bisq.core.locale.CryptoCurrency) Currency(network.bisq.api.model.Currency) TradeManager(bisq.core.trade.TradeManager) NodeAddress(bisq.network.p2p.NodeAddress) SellerAsTakerProtocol(bisq.core.trade.protocol.SellerAsTakerProtocol) CountryUtil(bisq.core.locale.CountryUtil) BuyerAsTakerProtocol(bisq.core.trade.protocol.BuyerAsTakerProtocol) TransactionOutput(org.bitcoinj.core.TransactionOutput) FeeService(bisq.core.provider.fee.FeeService) ObservableList(javafx.collections.ObservableList) PaymentAccountHelper(network.bisq.api.model.payment.PaymentAccountHelper) Restrictions(bisq.core.btc.Restrictions) Arbitrator(bisq.core.arbitration.Arbitrator) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) Wallet(org.bitcoinj.wallet.Wallet) Peer(org.bitcoinj.core.Peer) ArrayList(java.util.ArrayList) ClosedTradableConverter(network.bisq.api.model.ClosedTradableConverter) OfferPayload(bisq.core.offer.OfferPayload) Country(bisq.core.locale.Country) BitcoinNetworkStatus(network.bisq.api.model.BitcoinNetworkStatus) WalletDetails(network.bisq.api.model.WalletDetails) Nullable(javax.annotation.Nullable) IOException(java.io.IOException) OfferBookService(bisq.core.offer.OfferBookService) Names(com.google.inject.name.Names) BisqEnvironment(bisq.core.app.BisqEnvironment) SeedWords(network.bisq.api.model.SeedWords) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) OpenOfferManager(bisq.core.offer.OpenOfferManager) InputValidator(bisq.core.util.validation.InputValidator) PriceFeedService(bisq.core.provider.price.PriceFeedService) PaymentAccountList(network.bisq.api.model.PaymentAccountList) KeyRing(bisq.common.crypto.KeyRing) PreferencesAvailableValues(network.bisq.api.model.PreferencesAvailableValues) Transaction(org.bitcoinj.core.Transaction) Preferences(network.bisq.api.model.Preferences) Date(java.util.Date) Coin(org.bitcoinj.core.Coin) Key(com.google.inject.Key) AltCoinAddressValidator(bisq.core.payment.validation.AltCoinAddressValidator) VersionDetails(network.bisq.api.model.VersionDetails) Res(bisq.core.locale.Res) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt) PaymentAccountUtil.isPaymentAccountValidForOffer(bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer) OfferUtil(bisq.core.offer.OfferUtil) P2PService(bisq.network.p2p.P2PService) Predicate(java.util.function.Predicate) ArbitratorManager(bisq.core.arbitration.ArbitratorManager) Collection(java.util.Collection) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) FileUtil(bisq.common.storage.FileUtil) List(java.util.List) PaymentAccount(bisq.core.payment.PaymentAccount) DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) DevEnv(bisq.common.app.DevEnv) MarketList(network.bisq.api.model.MarketList) AppOptionKeys(bisq.core.app.AppOptionKeys) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Address(org.bitcoinj.core.Address) NotNull(org.jetbrains.annotations.NotNull) MarketPrice(bisq.core.provider.price.MarketPrice) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) TradeCurrency(bisq.core.locale.TradeCurrency) SellerAsMakerTrade(bisq.core.trade.SellerAsMakerTrade) Getter(lombok.Getter) WalletService(bisq.core.btc.wallet.WalletService) CompletableFuture(java.util.concurrent.CompletableFuture) FiatCurrency(bisq.core.locale.FiatCurrency) WalletsManager(bisq.core.btc.wallet.WalletsManager) Tuple2(bisq.common.util.Tuple2) BuyerAsMakerProtocol(bisq.core.trade.protocol.BuyerAsMakerProtocol) P2PNetworkStatus(network.bisq.api.model.P2PNetworkStatus) Market(network.bisq.api.model.Market) CurrencyUtil(bisq.core.locale.CurrencyUtil) BitcoinNodes(bisq.core.btc.BitcoinNodes) Version(bisq.common.app.Version) CryptoCurrencyAccount(bisq.core.payment.CryptoCurrencyAccount) P2PNetworkConnection(network.bisq.api.model.P2PNetworkConnection) BuyerAsMakerTrade(bisq.core.trade.BuyerAsMakerTrade) Trade(bisq.core.trade.Trade) WalletAddressList(network.bisq.api.model.WalletAddressList) ResultHandler(bisq.common.handlers.ResultHandler) FailedTradesManager(bisq.core.trade.failed.FailedTradesManager) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FileInputStream(java.io.FileInputStream) WalletTransaction(network.bisq.api.model.WalletTransaction) Injector(com.google.inject.Injector) Collectors.toList(java.util.stream.Collectors.toList) AuthResult(network.bisq.api.model.AuthResult) ValidationException(javax.validation.ValidationException) Storage(bisq.common.storage.Storage) Comparator(java.util.Comparator) Collections(java.util.Collections) CoinUtil(bisq.core.util.CoinUtil) InputStream(java.io.InputStream) ValidationException(javax.validation.ValidationException) AddressEntry(bisq.core.btc.AddressEntry) Coin(org.bitcoinj.core.Coin) SellerAsMakerTrade(bisq.core.trade.SellerAsMakerTrade) BuyerAsMakerTrade(bisq.core.trade.BuyerAsMakerTrade) Trade(bisq.core.trade.Trade) Transaction(org.bitcoinj.core.Transaction) WalletTransaction(network.bisq.api.model.WalletTransaction) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) CurrencyList(network.bisq.api.model.CurrencyList) WalletTransactionList(network.bisq.api.model.WalletTransactionList) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) PaymentAccountList(network.bisq.api.model.PaymentAccountList) List(java.util.List) MarketList(network.bisq.api.model.MarketList) WalletAddressList(network.bisq.api.model.WalletAddressList) Collectors.toList(java.util.stream.Collectors.toList)

Example 28 with Trade

use of bisq.core.trade.Trade in project bisq-core by bisq-network.

the class ClosedTradableManager method readPersisted.

@Override
public void readPersisted() {
    closedTradables = new TradableList<>(tradableListStorage, "ClosedTrades");
    closedTradables.forEach(tradable -> {
        tradable.getOffer().setPriceFeedService(priceFeedService);
        if (tradable instanceof Trade) {
            Trade trade = (Trade) tradable;
            trade.setTransientFields(tradableListStorage, btcWalletService);
        }
    });
}
Also used : Trade(bisq.core.trade.Trade)

Example 29 with Trade

use of bisq.core.trade.Trade in project bisq-core by bisq-network.

the class TradeStatisticsManager method publishTradeStatistics.

public void publishTradeStatistics(List<Trade> trades) {
    for (int i = 0; i < trades.size(); i++) {
        Trade trade = trades.get(i);
        Map<String, String> extraDataMap = null;
        if (referralIdService.getOptionalReferralId().isPresent()) {
            extraDataMap = new HashMap<>();
            extraDataMap.put(OfferPayload.REFERRAL_ID, referralIdService.getOptionalReferralId().get());
        }
        Offer offer = trade.getOffer();
        checkNotNull(offer, "offer must not ne null");
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not ne null");
        TradeStatistics2 tradeStatistics = new TradeStatistics2(offer.getOfferPayload(), trade.getTradePrice(), trade.getTradeAmount(), trade.getDate(), (trade.getDepositTx() != null ? trade.getDepositTx().getHashAsString() : ""), extraDataMap);
        addToMap(tradeStatistics, true);
        // We only republish trades from last 10 days
        if ((new Date().getTime() - trade.getDate().getTime()) < TimeUnit.DAYS.toMillis(10)) {
            long delay = 5000;
            long minDelay = (i + 1) * delay;
            long maxDelay = (i + 2) * delay;
            UserThread.runAfterRandomDelay(() -> {
                p2PService.addPersistableNetworkPayload(tradeStatistics, true);
            }, minDelay, maxDelay, TimeUnit.MILLISECONDS);
        }
    }
}
Also used : Trade(bisq.core.trade.Trade) Offer(bisq.core.offer.Offer) Date(java.util.Date)

Example 30 with Trade

use of bisq.core.trade.Trade in project bisq-core by bisq-network.

the class BisqSetup method initDomainServices.

private void initDomainServices() {
    log.info("initDomainServices");
    clock.start();
    PaymentMethod.onAllServicesInitialized();
    disputeManager.onAllServicesInitialized();
    tradeManager.onAllServicesInitialized();
    tradeManager.getTradableList().addListener((ListChangeListener<Trade>) change -> balanceModel.updateBalance());
    tradeManager.getAddressEntriesForAvailableBalanceStream().filter(addressEntry -> addressEntry.getOfferId() != null).forEach(addressEntry -> {
        log.debug("swapPendingOfferFundingEntries, offerId={}, OFFER_FUNDING", addressEntry.getOfferId());
        btcWalletService.swapTradeEntryToAvailableEntry(addressEntry.getOfferId(), AddressEntry.Context.OFFER_FUNDING);
    });
    btcWalletService.addBalanceListener(new BalanceListener() {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            balanceModel.updateBalance();
        }
    });
    if (walletsSetup.downloadPercentageProperty().get() == 1)
        checkForLockedUpFunds();
    balanceModel.updateBalance();
    openOfferManager.getObservableList().addListener((ListChangeListener<OpenOffer>) c -> balanceModel.updateBalance());
    openOfferManager.onAllServicesInitialized();
    arbitratorManager.onAllServicesInitialized();
    alertManager.alertMessageProperty().addListener((observable, oldValue, newValue) -> displayAlertIfPresent(newValue, false));
    displayAlertIfPresent(alertManager.alertMessageProperty().get(), false);
    privateNotificationManager.privateNotificationProperty().addListener((observable, oldValue, newValue) -> {
        if (displayPrivateNotificationHandler != null)
            displayPrivateNotificationHandler.accept(newValue);
    });
    p2PService.onAllServicesInitialized();
    feeService.onAllServicesInitialized();
    if (DevEnv.isDaoActivated()) {
        daoSetup.onAllServicesInitialized(errorMessage -> {
            if (daoSetupErrorHandler != null)
                daoSetupErrorHandler.accept(errorMessage);
        });
    }
    tradeStatisticsManager.onAllServicesInitialized();
    accountAgeWitnessService.onAllServicesInitialized();
    priceFeedService.setCurrencyCodeOnInit();
    filterManager.onAllServicesInitialized();
    filterManager.addListener(filter -> {
        if (filter != null && filterWarningHandler != null) {
            if (filter.getSeedNodes() != null && !filter.getSeedNodes().isEmpty())
                filterWarningHandler.accept(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.seed")));
            if (filter.getPriceRelayNodes() != null && !filter.getPriceRelayNodes().isEmpty())
                filterWarningHandler.accept(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.priceRelay")));
        }
    });
    mobileNotificationService.onAllServicesInitialized();
    myOfferTakenEvents.onAllServicesInitialized();
    tradeEvents.onAllServicesInitialized();
    disputeMsgEvents.onAllServicesInitialized();
    priceAlert.onAllServicesInitialized();
    marketAlerts.onAllServicesInitialized();
    allBasicServicesInitialized = true;
}
Also used : Transaction(org.bitcoinj.core.Transaction) OpenOffer(bisq.core.offer.OpenOffer) Utilities(bisq.common.util.Utilities) Coin(org.bitcoinj.core.Coin) Clock(bisq.common.Clock) Security(java.security.Security) MobileNotificationService(bisq.core.notifications.MobileNotificationService) DaoSetup(bisq.core.dao.DaoSetup) DisputeManager(bisq.core.arbitration.DisputeManager) User(bisq.core.user.User) ListChangeListener(javafx.collections.ListChangeListener) MyOfferTakenEvents(bisq.core.notifications.alerts.MyOfferTakenEvents) Alert(bisq.core.alert.Alert) Res(bisq.core.locale.Res) DisputeMsgEvents(bisq.core.notifications.alerts.DisputeMsgEvents) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) KeyParameter(org.spongycastle.crypto.params.KeyParameter) BalanceModel(bisq.core.btc.BalanceModel) P2PService(bisq.network.p2p.P2PService) ArbitratorManager(bisq.core.arbitration.ArbitratorManager) FilterManager(bisq.core.filter.FilterManager) PaymentMethod(bisq.core.payment.payload.PaymentMethod) InetSocketAddress(java.net.InetSocketAddress) AccountAgeWitnessService(bisq.core.payment.AccountAgeWitnessService) PaymentAccount(bisq.core.payment.PaymentAccount) BooleanProperty(javafx.beans.property.BooleanProperty) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) AddressEntry(bisq.core.btc.AddressEntry) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) DevEnv(bisq.common.app.DevEnv) TradeManager(bisq.core.trade.TradeManager) Preferences(bisq.core.user.Preferences) UserThread(bisq.common.UserThread) FeeService(bisq.core.provider.fee.FeeService) StringProperty(javafx.beans.property.StringProperty) Ping(bisq.network.p2p.peers.keepalive.messages.Ping) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) CryptoException(bisq.common.crypto.CryptoException) Socket(java.net.Socket) Setter(lombok.Setter) AlertManager(bisq.core.alert.AlertManager) Getter(lombok.Getter) SetChangeListener(javafx.collections.SetChangeListener) Timer(bisq.common.Timer) DoubleProperty(javafx.beans.property.DoubleProperty) TradeStatisticsManager(bisq.core.trade.statistics.TradeStatisticsManager) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) BalanceListener(bisq.core.btc.listeners.BalanceListener) WalletsManager(bisq.core.btc.wallet.WalletsManager) BiConsumer(java.util.function.BiConsumer) TradeEvents(bisq.core.notifications.alerts.TradeEvents) PriceAlert(bisq.core.notifications.alerts.price.PriceAlert) PrivateNotificationManager(bisq.core.alert.PrivateNotificationManager) Nullable(javax.annotation.Nullable) PrivateNotificationPayload(bisq.core.alert.PrivateNotificationPayload) Trade(bisq.core.trade.Trade) EncryptionService(bisq.network.crypto.EncryptionService) BSFormatter(bisq.core.util.BSFormatter) IOException(java.io.IOException) MarketAlerts(bisq.core.notifications.alerts.market.MarketAlerts) OpenOfferManager(bisq.core.offer.OpenOfferManager) ProtobufferException(bisq.common.proto.ProtobufferException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) PriceFeedService(bisq.core.provider.price.PriceFeedService) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) EasyBind(org.fxmisc.easybind.EasyBind) DecryptedDataTuple(bisq.network.crypto.DecryptedDataTuple) KeyRing(bisq.common.crypto.KeyRing) InetAddresses(com.google.common.net.InetAddresses) ChangeListener(javafx.beans.value.ChangeListener) SealedAndSigned(bisq.common.crypto.SealedAndSigned) Trade(bisq.core.trade.Trade) Coin(org.bitcoinj.core.Coin) BalanceListener(bisq.core.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) OpenOffer(bisq.core.offer.OpenOffer)

Aggregations

Trade (bisq.core.trade.Trade)30 Coin (org.bitcoinj.core.Coin)16 Res (bisq.core.locale.Res)13 Offer (bisq.core.offer.Offer)13 OpenOffer (bisq.core.offer.OpenOffer)13 TradeManager (bisq.core.trade.TradeManager)13 List (java.util.List)11 ObservableList (javafx.collections.ObservableList)11 Nullable (javax.annotation.Nullable)11 Transaction (org.bitcoinj.core.Transaction)11 KeyRing (bisq.common.crypto.KeyRing)10 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)10 NodeAddress (bisq.network.p2p.NodeAddress)10 P2PService (bisq.network.p2p.P2PService)10 ArrayList (java.util.ArrayList)10 AppOptionKeys (bisq.core.app.AppOptionKeys)9 AddressEntry (bisq.core.btc.AddressEntry)9 WalletsSetup (bisq.core.btc.wallet.WalletsSetup)9 OpenOfferManager (bisq.core.offer.OpenOfferManager)9 IOException (java.io.IOException)8