Search in sources :

Example 1 with TransactionConfidence

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

the class Trade method setupConfidenceListener.

///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////
private void setupConfidenceListener() {
    log.debug("setupConfidenceListener");
    if (depositTx != null) {
        TransactionConfidence transactionConfidence = depositTx.getConfidence();
        log.debug("transactionConfidence " + transactionConfidence.getDepthInBlocks());
        if (transactionConfidence.getDepthInBlocks() > 0) {
            setConfirmedState();
        } else {
            ListenableFuture<TransactionConfidence> future = transactionConfidence.getDepthFuture(1);
            Futures.addCallback(future, new FutureCallback<TransactionConfidence>() {

                @Override
                public void onSuccess(TransactionConfidence result) {
                    log.debug("transactionConfidence " + transactionConfidence.getDepthInBlocks());
                    log.debug("state " + state);
                    setConfirmedState();
                }

                @Override
                public void onFailure(@NotNull Throwable t) {
                    t.printStackTrace();
                    log.error(t.getMessage());
                    Throwables.propagate(t);
                }
            });
        }
    } else {
        log.error("depositTx == null. That must not happen.");
    }
}
Also used : TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 2 with TransactionConfidence

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

the class BalanceWithConfirmationTextField method setup.

public void setup(Address address, BSFormatter formatter) {
    this.formatter = formatter;
    confidenceListener = new AddressConfidenceListener(address) {

        @Override
        public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
            updateConfidence(confidence);
        }
    };
    walletService.addAddressConfidenceListener(confidenceListener);
    updateConfidence(walletService.getConfidenceForAddress(address));
    balanceListener = new BalanceListener(address) {

        @Override
        public void onBalanceChanged(Coin balance, Transaction tx) {
            updateBalance(balance);
        }
    };
    walletService.addBalanceListener(balanceListener);
    updateBalance(walletService.getBalanceForAddress(address));
}
Also used : Coin(org.bitcoinj.core.Coin) AddressConfidenceListener(io.bitsquare.btc.listeners.AddressConfidenceListener) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 3 with TransactionConfidence

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

the class TxIdTextField method setup.

public void setup(String txID) {
    if (txConfidenceListener != null)
        walletService.removeTxConfidenceListener(txConfidenceListener);
    txConfidenceListener = new TxConfidenceListener(txID) {

        @Override
        public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
            updateConfidence(confidence);
        }
    };
    walletService.addTxConfidenceListener(txConfidenceListener);
    updateConfidence(walletService.getConfidenceForTxId(txID));
    textField.setText(txID);
    textField.setOnMouseClicked(mouseEvent -> openBlockExplorer(txID));
    blockExplorerIcon.setOnMouseClicked(mouseEvent -> openBlockExplorer(txID));
    copyIcon.setOnMouseClicked(e -> Utilities.copyToClipboard(txID));
}
Also used : TxConfidenceListener(io.bitsquare.btc.listeners.TxConfidenceListener) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 4 with TransactionConfidence

use of org.bitcoinj.core.TransactionConfidence in project bisq-core by bisq-network.

the class BtcCompensationRequestFeeCoinSelector method isSelectable.

public boolean isSelectable(Transaction tx) {
    if (tx != null) {
        // Only pick chain-included transactions, or transactions that are ours and pending.
        TransactionConfidence confidence = tx.getConfidence();
        TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
        return type.equals(TransactionConfidence.ConfidenceType.BUILDING) || type.equals(TransactionConfidence.ConfidenceType.PENDING) && confidence.getSource().equals(TransactionConfidence.Source.SELF) && // TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0
        (confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get());
    } else {
        return true;
    }
}
Also used : TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 5 with TransactionConfidence

use of org.bitcoinj.core.TransactionConfidence in project bisq-core by bisq-network.

the class BisqDefaultCoinSelector method isTxSpendable.

// We allow spending own pending txs and if permitForeignPendingTx is set as well foreign unconfirmed txs.
protected boolean isTxSpendable(Transaction tx) {
    TransactionConfidence confidence = tx.getConfidence();
    TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
    boolean isConfirmed = type.equals(TransactionConfidence.ConfidenceType.BUILDING);
    boolean isPending = type.equals(TransactionConfidence.ConfidenceType.PENDING);
    boolean isOwnTx = confidence.getSource().equals(TransactionConfidence.Source.SELF);
    return isConfirmed || (isPending && (permitForeignPendingTx || isOwnTx));
}
Also used : TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Aggregations

TransactionConfidence (org.bitcoinj.core.TransactionConfidence)18 Transaction (org.bitcoinj.core.Transaction)8 Coin (org.bitcoinj.core.Coin)6 TxConfidenceListener (bisq.core.btc.listeners.TxConfidenceListener)4 AddressConfidenceListener (bisq.core.btc.listeners.AddressConfidenceListener)3 Intent (android.content.Intent)2 Handler (android.os.Handler)2 HandlerThread (android.os.HandlerThread)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 UserThread (bisq.common.UserThread)2 TaskRunner (bisq.common.taskrunner.TaskRunner)2 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)2 Tx (bisq.core.dao.blockchain.vo.Tx)2 Trade (bisq.core.trade.Trade)2 PaymentIntent (de.schildbach.wallet.data.PaymentIntent)2 AbstractWalletActivityViewModel (de.schildbach.wallet.ui.AbstractWalletActivityViewModel)2 ProgressDialogFragment (de.schildbach.wallet.ui.ProgressDialogFragment)2 ToString (lombok.ToString)2 NetworkParameters (org.bitcoinj.core.NetworkParameters)2 ConfidenceType (org.bitcoinj.core.TransactionConfidence.ConfidenceType)2