Search in sources :

Example 1 with Coin

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

the class LockedView method initialize.

@Override
public void initialize() {
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.setPlaceholder(new Label("No funds are locked in trades"));
    setDateColumnCellFactory();
    setDetailsColumnCellFactory();
    setAddressColumnCellFactory();
    setBalanceColumnCellFactory();
    addressColumn.setComparator((o1, o2) -> o1.getAddressString().compareTo(o2.getAddressString()));
    detailsColumn.setComparator((o1, o2) -> o1.getTrade().getId().compareTo(o2.getTrade().getId()));
    balanceColumn.setComparator((o1, o2) -> o1.getBalance().compareTo(o2.getBalance()));
    dateColumn.setComparator((o1, o2) -> {
        if (getTradable(o1).isPresent() && getTradable(o2).isPresent())
            return getTradable(o2).get().getDate().compareTo(getTradable(o1).get().getDate());
        else
            return 0;
    });
    tableView.getSortOrder().add(dateColumn);
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    balanceListener = new BalanceListener() {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateList();
        }
    };
    openOfferListChangeListener = c -> updateList();
    tradeListChangeListener = c -> updateList();
}
Also used : Coin(org.bitcoinj.core.Coin) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction)

Example 2 with Coin

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

the class MainViewModel method updateAvailableBalance.

private void updateAvailableBalance() {
    Coin totalAvailableBalance = Coin.valueOf(tradeManager.getAddressEntriesForAvailableBalanceStream().mapToLong(addressEntry -> walletService.getBalanceForAddress(addressEntry.getAddress()).getValue()).sum());
    availableBalance.set(formatter.formatCoinWithCode(totalAvailableBalance));
}
Also used : Coin(org.bitcoinj.core.Coin)

Example 3 with Coin

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

the class MainViewModel method updateLockedBalance.

private void updateLockedBalance() {
    Coin sum = Coin.valueOf(tradeManager.getLockedTradeStream().mapToLong(trade -> {
        Coin lockedTradeAmount = walletService.getOrCreateAddressEntry(trade.getId(), AddressEntry.Context.MULTI_SIG).getCoinLockedInMultiSig();
        return lockedTradeAmount != null ? lockedTradeAmount.getValue() : 0;
    }).sum());
    lockedBalance.set(formatter.formatCoinWithCode(sum));
}
Also used : Coin(org.bitcoinj.core.Coin)

Example 4 with Coin

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

the class PendingTradesDataModel method tryOpenDispute.

private void tryOpenDispute(boolean isSupportTicket) {
    if (getTrade() != null) {
        Transaction depositTx = getTrade().getDepositTx();
        if (depositTx != null) {
            doOpenDispute(isSupportTicket, getTrade().getDepositTx());
        } else {
            log.info("Trade.depositTx is null. We try to find the tx in our wallet.");
            List<Transaction> candidates = new ArrayList<>();
            List<Transaction> transactions = walletService.getWallet().getRecentTransactions(100, true);
            transactions.stream().forEach(transaction -> {
                Coin valueSentFromMe = transaction.getValueSentFromMe(walletService.getWallet());
                if (!valueSentFromMe.isZero()) {
                    candidates.addAll(transaction.getOutputs().stream().filter(transactionOutput -> !transactionOutput.isMine(walletService.getWallet())).filter(transactionOutput -> transactionOutput.getScriptPubKey().isPayToScriptHash()).map(transactionOutput -> transaction).collect(Collectors.toList()));
                }
            });
            if (candidates.size() == 1)
                doOpenDispute(isSupportTicket, candidates.get(0));
            else if (candidates.size() > 1)
                new SelectDepositTxWindow().transactions(candidates).onSelect(transaction -> doOpenDispute(isSupportTicket, transaction)).closeButtonText("Cancel").show();
            else
                log.error("Trade.depositTx is null and we did not find any MultiSig transaction.");
        }
    } else {
        log.error("Trade is null");
    }
}
Also used : Popup(io.bitsquare.gui.main.overlays.popups.Popup) MainView(io.bitsquare.gui.main.MainView) Transaction(org.bitcoinj.core.Transaction) P2PService(io.bitsquare.p2p.P2PService) ErrorMessageHandler(io.bitsquare.common.handlers.ErrorMessageHandler) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Coin(org.bitcoinj.core.Coin) Inject(com.google.inject.Inject) FXCollections(javafx.collections.FXCollections) DisputeManager(io.bitsquare.arbitration.DisputeManager) Trade(io.bitsquare.trade.Trade) ArrayList(java.util.ArrayList) BuyerTrade(io.bitsquare.trade.BuyerTrade) TradeManager(io.bitsquare.trade.TradeManager) User(io.bitsquare.user.User) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) NotificationCenter(io.bitsquare.gui.main.overlays.notifications.NotificationCenter) ListChangeListener(javafx.collections.ListChangeListener) WalletService(io.bitsquare.btc.WalletService) Navigation(io.bitsquare.gui.Navigation) BlockChainListener(org.bitcoinj.core.BlockChainListener) KeyRing(io.bitsquare.common.crypto.KeyRing) TradeWalletService(io.bitsquare.btc.TradeWalletService) ResultHandler(io.bitsquare.common.handlers.ResultHandler) SelectDepositTxWindow(io.bitsquare.gui.main.overlays.windows.SelectDepositTxWindow) FeePolicy(io.bitsquare.btc.FeePolicy) KeyParameter(org.spongycastle.crypto.params.KeyParameter) Nullable(javax.annotation.Nullable) Log(io.bitsquare.app.Log) WalletPasswordWindow(io.bitsquare.gui.main.overlays.windows.WalletPasswordWindow) ActivatableDataModel(io.bitsquare.gui.common.model.ActivatableDataModel) ObjectProperty(javafx.beans.property.ObjectProperty) Arbitrator(io.bitsquare.arbitration.Arbitrator) DisputeAlreadyOpenException(io.bitsquare.arbitration.DisputeAlreadyOpenException) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) Collectors(java.util.stream.Collectors) SellerTrade(io.bitsquare.trade.SellerTrade) DisputesView(io.bitsquare.gui.main.disputes.DisputesView) Preferences(io.bitsquare.user.Preferences) Offer(io.bitsquare.trade.offer.Offer) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Dispute(io.bitsquare.arbitration.Dispute) FaultHandler(io.bitsquare.common.handlers.FaultHandler) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) ArrayList(java.util.ArrayList) SelectDepositTxWindow(io.bitsquare.gui.main.overlays.windows.SelectDepositTxWindow)

Example 5 with Coin

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

the class ClosedTradesView method initialize.

@Override
public void initialize() {
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.setPlaceholder(new Label("No closed trades available"));
    setTradeIdColumnCellFactory();
    setDirectionColumnCellFactory();
    setAmountColumnCellFactory();
    setPriceColumnCellFactory();
    setVolumeColumnCellFactory();
    setDateColumnCellFactory();
    setMarketColumnCellFactory();
    setStateColumnCellFactory();
    setAvatarColumnCellFactory();
    tradeIdColumn.setComparator((o1, o2) -> o1.getTradable().getId().compareTo(o2.getTradable().getId()));
    dateColumn.setComparator((o1, o2) -> o1.getTradable().getDate().compareTo(o2.getTradable().getDate()));
    directionColumn.setComparator((o1, o2) -> o1.getTradable().getOffer().getDirection().compareTo(o2.getTradable().getOffer().getDirection()));
    marketColumn.setComparator((o1, o2) -> model.getMarketLabel(o1).compareTo(model.getMarketLabel(o2)));
    priceColumn.setComparator((o1, o2) -> {
        final Tradable tradable1 = o1.getTradable();
        final Tradable tradable2 = o2.getTradable();
        Fiat price1 = null;
        Fiat price2 = null;
        if (tradable1 != null)
            price1 = tradable1 instanceof Trade ? ((Trade) tradable1).getTradePrice() : tradable1.getOffer().getPrice();
        if (tradable2 != null)
            price2 = tradable2 instanceof Trade ? ((Trade) tradable2).getTradePrice() : tradable2.getOffer().getPrice();
        return price1 != null && price2 != null ? price1.compareTo(price2) : 0;
    });
    volumeColumn.setComparator((o1, o2) -> {
        if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
            Fiat tradeVolume1 = ((Trade) o1.getTradable()).getTradeVolume();
            Fiat tradeVolume2 = ((Trade) o2.getTradable()).getTradeVolume();
            return tradeVolume1 != null && tradeVolume2 != null ? tradeVolume1.compareTo(tradeVolume2) : 0;
        } else
            return 0;
    });
    amountColumn.setComparator((o1, o2) -> {
        if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
            Coin amount1 = ((Trade) o1.getTradable()).getTradeAmount();
            Coin amount2 = ((Trade) o2.getTradable()).getTradeAmount();
            return amount1 != null && amount2 != null ? amount1.compareTo(amount2) : 0;
        } else
            return 0;
    });
    avatarColumn.setComparator((o1, o2) -> {
        if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
            NodeAddress tradingPeerNodeAddress1 = ((Trade) o1.getTradable()).getTradingPeerNodeAddress();
            NodeAddress tradingPeerNodeAddress2 = ((Trade) o2.getTradable()).getTradingPeerNodeAddress();
            String address1 = tradingPeerNodeAddress1 != null ? tradingPeerNodeAddress1.hostName : "";
            String address2 = tradingPeerNodeAddress2 != null ? tradingPeerNodeAddress2.hostName : "";
            return address1 != null && address2 != null ? address1.compareTo(address2) : 0;
        } else
            return 0;
    });
    stateColumn.setComparator((o1, o2) -> model.getState(o1).compareTo(model.getState(o2)));
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getSortOrder().add(dateColumn);
    exportButton.setText("Export to csv");
}
Also used : Trade(io.bitsquare.trade.Trade) Coin(org.bitcoinj.core.Coin) Tradable(io.bitsquare.trade.Tradable) Fiat(org.bitcoinj.utils.Fiat) NodeAddress(io.bitsquare.p2p.NodeAddress)

Aggregations

Coin (org.bitcoinj.core.Coin)35 AddressEntry (io.bitsquare.btc.AddressEntry)13 WalletService (io.bitsquare.btc.WalletService)13 Transaction (org.bitcoinj.core.Transaction)11 Popup (io.bitsquare.gui.main.overlays.popups.Popup)9 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)8 Offer (io.bitsquare.trade.offer.Offer)7 Address (org.bitcoinj.core.Address)6 BSFormatter (io.bitsquare.gui.util.BSFormatter)5 Trade (io.bitsquare.trade.Trade)5 Inject (com.google.inject.Inject)4 Log (io.bitsquare.app.Log)4 UserThread (io.bitsquare.common.UserThread)4 DevFlags (io.bitsquare.app.DevFlags)3 Dispute (io.bitsquare.arbitration.Dispute)3 DisputeManager (io.bitsquare.arbitration.DisputeManager)3 TradeWalletService (io.bitsquare.btc.TradeWalletService)3 MarketPrice (io.bitsquare.btc.pricefeed.MarketPrice)3 PriceFeedService (io.bitsquare.btc.pricefeed.PriceFeedService)3 CurrencyUtil (io.bitsquare.locale.CurrencyUtil)3