Search in sources :

Example 16 with Coin

use of org.bitcoinj.core.Coin 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 17 with Coin

use of org.bitcoinj.core.Coin 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)

Example 18 with Coin

use of org.bitcoinj.core.Coin in project bisq-api by mrosseel.

the class MainViewModelHeadless method updateLockedBalance.

private void 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());
    lockedBalance.set(formatter.formatCoinWithCode(sum));
}
Also used : Trade(io.bisq.core.trade.Trade) Coin(org.bitcoinj.core.Coin) AddressEntry(io.bisq.core.btc.AddressEntry)

Example 19 with Coin

use of org.bitcoinj.core.Coin in project bisq-api by mrosseel.

the class MainViewModelHeadless method updateReservedBalance.

private void updateReservedBalance() {
    Coin sum = Coin.valueOf(openOfferManager.getObservableList().stream().map(openOffer -> {
        final Optional<AddressEntry> addressEntryOptional = btcWalletService.getAddressEntry(openOffer.getId(), AddressEntry.Context.RESERVED_FOR_TRADE);
        if (addressEntryOptional.isPresent()) {
            Address address = addressEntryOptional.get().getAddress();
            return btcWalletService.getBalanceForAddress(address);
        } else {
            return null;
        }
    }).filter(e -> e != null).mapToLong(Coin::getValue).sum());
    reservedBalance.set(formatter.formatCoinWithCode(sum));
}
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) Coin(org.bitcoinj.core.Coin) InetSocketAddress(java.net.InetSocketAddress) Address(org.bitcoinj.core.Address) AddressEntry(io.bisq.core.btc.AddressEntry)

Example 20 with Coin

use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.

the class RestrictionsTest method testIsMinSpendableAmount.

@Test
public void testIsMinSpendableAmount() {
    Coin amount = null;
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = Coin.ZERO;
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = FeePolicy.getFixedTxFeeForTrades();
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = Transaction.MIN_NONDUST_OUTPUT;
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = FeePolicy.getFixedTxFeeForTrades().add(Transaction.MIN_NONDUST_OUTPUT);
    assertFalse("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
    amount = FeePolicy.getFixedTxFeeForTrades().add(Transaction.MIN_NONDUST_OUTPUT).add(Coin.valueOf(1));
    assertTrue("tx unfunded, pending", Restrictions.isAboveFixedTxFeeForTradesAndDust(amount));
}
Also used : Coin(org.bitcoinj.core.Coin) Test(org.junit.Test)

Aggregations

Coin (org.bitcoinj.core.Coin)64 Transaction (org.bitcoinj.core.Transaction)16 AddressEntry (io.bitsquare.btc.AddressEntry)13 WalletService (io.bitsquare.btc.WalletService)13 Address (org.bitcoinj.core.Address)10 Popup (io.bitsquare.gui.main.overlays.popups.Popup)8 Inject (com.google.inject.Inject)7 Nullable (javax.annotation.Nullable)7 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)6 Collectors (java.util.stream.Collectors)6 FXCollections (javafx.collections.FXCollections)6 ListChangeListener (javafx.collections.ListChangeListener)6 ObservableList (javafx.collections.ObservableList)6 BSFormatter (io.bitsquare.gui.util.BSFormatter)5 Offer (io.bitsquare.trade.offer.Offer)5 AddressEntry (io.bisq.core.btc.AddressEntry)4 Trade (io.bisq.core.trade.Trade)4 UserThread (io.bitsquare.common.UserThread)4 PaymentAccountUtil.isPaymentAccountValidForOffer (io.bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer)3 DevFlags (io.bitsquare.app.DevFlags)3