Search in sources :

Example 1 with Transaction

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

use of org.bitcoinj.core.Transaction 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 3 with Transaction

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

the class SignAndFinalizePayoutTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        Coin sellerPayoutAmount = FeePolicy.getSecurityDeposit(trade.getOffer());
        Coin buyerPayoutAmount = sellerPayoutAmount.add(trade.getTradeAmount());
        WalletService walletService = processModel.getWalletService();
        AddressEntry buyerAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
        AddressEntry multiSigAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
        Transaction transaction = processModel.getTradeWalletService().buyerSignsAndFinalizesPayoutTx(trade.getDepositTx(), processModel.tradingPeer.getSignature(), buyerPayoutAmount, sellerPayoutAmount, buyerAddressEntry.getAddressString(), processModel.tradingPeer.getPayoutAddressString(), multiSigAddressEntry.getKeyPair(), trade.getLockTimeAsBlockHeight(), multiSigAddressEntry.getPubKey(), processModel.tradingPeer.getMultiSigPubKey(), trade.getArbitratorPubKey());
        trade.setPayoutTx(transaction);
        trade.setState(Trade.State.BUYER_COMMITTED_PAYOUT_TX);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) AddressEntry(io.bitsquare.btc.AddressEntry) WalletService(io.bitsquare.btc.WalletService)

Example 4 with Transaction

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

the class ProcessDepositTxPublishedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        DepositTxPublishedMessage message = (DepositTxPublishedMessage) processModel.getTradeMessage();
        checkTradeId(processModel.getId(), message);
        checkNotNull(message);
        checkArgument(message.depositTx != null);
        // To access tx confidence we need to add that tx into our wallet.
        Transaction transactionFromSerializedTx = processModel.getWalletService().getTransactionFromSerializedTx(message.depositTx);
        // update with full tx
        trade.setDepositTx(processModel.getTradeWalletService().addTransactionToWallet(transactionFromSerializedTx));
        if (trade instanceof OffererTrade)
            processModel.getOpenOfferManager().closeOpenOffer(trade.getOffer());
        // update to the latest peer address of our peer if the message is correct
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        removeMailboxMessageAfterProcessing();
        trade.setState(Trade.State.OFFERER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) DepositTxPublishedMessage(io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage) OffererTrade(io.bitsquare.trade.OffererTrade)

Example 5 with Transaction

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

the class CreateOfferFeeTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        NodeAddress selectedArbitratorNodeAddress = ArbitrationSelectionRule.select(model.user.getAcceptedArbitratorAddresses(), model.offer);
        log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
        Arbitrator selectedArbitrator = model.user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
        checkNotNull(selectedArbitrator, "selectedArbitrator must not be null at CreateOfferFeeTx");
        WalletService walletService = model.walletService;
        String id = model.offer.getId();
        Address fundingAddress = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING).getAddress();
        Address reservedForTradeAddress = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE).getAddress();
        Address changeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
        Transaction transaction = model.tradeWalletService.createTradingFeeTx(fundingAddress, reservedForTradeAddress, changeAddress, model.reservedFundsForOffer, model.useSavingsWallet, FeePolicy.getCreateOfferFee(), selectedArbitrator.getBtcAddress());
        // We assume there will be no tx malleability. We add a check later in case the published offer has a different hash.
        // As the txId is part of the offer and therefore change the hash data we need to be sure to have no
        // tx malleability
        model.offer.setOfferFeePaymentTxID(transaction.getHashAsString());
        model.setTransaction(transaction);
        complete();
    } catch (Throwable t) {
        model.offer.setErrorMessage("An error occurred.\n" + "Error message:\n" + t.getMessage());
        failed(t);
    }
}
Also used : NodeAddress(io.bitsquare.p2p.NodeAddress) Address(org.bitcoinj.core.Address) Transaction(org.bitcoinj.core.Transaction) NodeAddress(io.bitsquare.p2p.NodeAddress) Arbitrator(io.bitsquare.arbitration.Arbitrator) WalletService(io.bitsquare.btc.WalletService)

Aggregations

Transaction (org.bitcoinj.core.Transaction)174 Coin (org.bitcoinj.core.Coin)63 TransactionInput (org.bitcoinj.core.TransactionInput)34 TransactionOutput (org.bitcoinj.core.TransactionOutput)33 Address (org.bitcoinj.core.Address)31 TransactionOutPoint (org.bitcoinj.core.TransactionOutPoint)26 ArrayList (java.util.ArrayList)25 Wallet (org.bitcoinj.wallet.Wallet)25 ECKey (org.bitcoinj.core.ECKey)22 Script (org.bitcoinj.script.Script)22 SendRequest (org.bitcoinj.wallet.SendRequest)22 List (java.util.List)19 InsufficientMoneyException (org.bitcoinj.core.InsufficientMoneyException)18 HashMap (java.util.HashMap)17 AddressFormatException (org.bitcoinj.core.AddressFormatException)17 Sha256Hash (org.bitcoinj.core.Sha256Hash)17 TransactionConfidence (org.bitcoinj.core.TransactionConfidence)17 AddressEntry (bisq.core.btc.AddressEntry)15 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)13 IOException (java.io.IOException)12