Search in sources :

Example 1 with TxConfidenceListener

use of bisq.core.btc.listeners.TxConfidenceListener in project bisq-desktop by bisq-network.

the class ProposalListItem method setupConfidence.

private void setupConfidence() {
    final Tx tx = readableBsqBlockChain.getTxMap().get(proposal.getProposalPayload().getTxId());
    if (tx != null) {
        final String txId = tx.getId();
        // We cache the walletTransaction once found
        if (walletTransaction == null) {
            final Optional<Transaction> transactionOptional = bsqWalletService.isWalletTransaction(txId);
            transactionOptional.ifPresent(transaction -> walletTransaction = transaction);
        }
        if (walletTransaction != null) {
            // It is our tx so we get confidence updates
            if (txConfidenceListener == null) {
                txConfidenceListener = new TxConfidenceListener(txId) {

                    @Override
                    public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
                        updateConfidence(confidence.getConfidenceType(), confidence.getDepthInBlocks(), confidence.numBroadcastPeers());
                    }
                };
                bsqWalletService.addTxConfidenceListener(txConfidenceListener);
            }
        } else {
            // tx from other users, we dont get confidence updates but as we have the bsq tx we can calculate it
            // we get setupConfidence called at each new block from above listener so no need to register a new listener
            int depth = bsqWalletService.getChainHeightProperty().get() - tx.getBlockHeight() + 1;
            if (depth > 0)
                updateConfidence(TransactionConfidence.ConfidenceType.BUILDING, depth, -1);
        // log.error("name={}, id ={}, depth={}", compensationRequest.getPayload().getName(), compensationRequest.getPayload().getUid(), depth);
        }
        final TransactionConfidence confidence = bsqWalletService.getConfidenceForTxId(txId);
        if (confidence != null)
            updateConfidence(confidence, confidence.getDepthInBlocks());
    }
}
Also used : Tx(bisq.core.dao.blockchain.vo.Tx) Transaction(org.bitcoinj.core.Transaction) TxConfidenceListener(bisq.core.btc.listeners.TxConfidenceListener) ToString(lombok.ToString) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 2 with TxConfidenceListener

use of bisq.core.btc.listeners.TxConfidenceListener in project bisq-desktop by bisq-network.

the class VoteListItem method setupConfidence.

private void setupConfidence() {
    calculateStake();
    final Tx tx = readableBsqBlockChain.getTxMap().get(myVote.getBlindVote().getTxId());
    if (tx != null) {
        final String txId = tx.getId();
        // We cache the walletTransaction once found
        if (walletTransaction == null) {
            final Optional<Transaction> transactionOptional = bsqWalletService.isWalletTransaction(txId);
            transactionOptional.ifPresent(transaction -> walletTransaction = transaction);
        }
        if (walletTransaction != null) {
            // It is our tx so we get confidence updates
            if (txConfidenceListener == null) {
                txConfidenceListener = new TxConfidenceListener(txId) {

                    @Override
                    public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
                        updateConfidence(confidence.getConfidenceType(), confidence.getDepthInBlocks(), confidence.numBroadcastPeers());
                    }
                };
                bsqWalletService.addTxConfidenceListener(txConfidenceListener);
            }
        } else {
            // tx from other users, we dont get confidence updates but as we have the bsq tx we can calculate it
            // we get setupConfidence called at each new block from above listener so no need to register a new listener
            int depth = bsqWalletService.getChainHeightProperty().get() - tx.getBlockHeight() + 1;
            if (depth > 0)
                updateConfidence(TransactionConfidence.ConfidenceType.BUILDING, depth, -1);
        // log.error("name={}, id ={}, depth={}", compensationRequest.getPayload().getName(), compensationRequest.getPayload().getUid(), depth);
        }
        final TransactionConfidence confidence = bsqWalletService.getConfidenceForTxId(txId);
        if (confidence != null)
            updateConfidence(confidence, confidence.getDepthInBlocks());
    }
}
Also used : Tx(bisq.core.dao.blockchain.vo.Tx) Transaction(org.bitcoinj.core.Transaction) TxConfidenceListener(bisq.core.btc.listeners.TxConfidenceListener) ToString(lombok.ToString) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 3 with TxConfidenceListener

use of bisq.core.btc.listeners.TxConfidenceListener in project bisq-desktop by bisq-network.

the class BsqTxListItem method setupConfidence.

private void setupConfidence(BsqWalletService bsqWalletService) {
    txConfidenceIndicator = new TxConfidenceIndicator();
    txConfidenceIndicator.setId("funds-confidence");
    Tooltip tooltip = new Tooltip();
    txConfidenceIndicator.setProgress(0);
    txConfidenceIndicator.setPrefSize(24, 24);
    txConfidenceIndicator.setTooltip(tooltip);
    txConfidenceListener = new TxConfidenceListener(txId) {

        @Override
        public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
            updateConfidence(confidence, tooltip);
        }
    };
    bsqWalletService.addTxConfidenceListener(txConfidenceListener);
    updateConfidence(bsqWalletService.getConfidenceForTxId(txId), tooltip);
}
Also used : TxConfidenceListener(bisq.core.btc.listeners.TxConfidenceListener) TxConfidenceIndicator(bisq.desktop.components.indicator.TxConfidenceIndicator) Tooltip(javafx.scene.control.Tooltip) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 4 with TxConfidenceListener

use of bisq.core.btc.listeners.TxConfidenceListener in project bisq-desktop by bisq-network.

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(bisq.core.btc.listeners.TxConfidenceListener) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Aggregations

TxConfidenceListener (bisq.core.btc.listeners.TxConfidenceListener)4 TransactionConfidence (org.bitcoinj.core.TransactionConfidence)4 Tx (bisq.core.dao.blockchain.vo.Tx)2 ToString (lombok.ToString)2 Transaction (org.bitcoinj.core.Transaction)2 TxConfidenceIndicator (bisq.desktop.components.indicator.TxConfidenceIndicator)1 Tooltip (javafx.scene.control.Tooltip)1