Search in sources :

Example 16 with TransactionConfidence

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

Example 17 with TransactionConfidence

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

the class BisqProxy method toWalletTransaction.

@NotNull
private WalletTransaction toWalletTransaction(Wallet wallet, Transaction transaction) {
    final Coin valueSentFromMe = transaction.getValueSentFromMe(wallet);
    final Coin valueSentToMe = transaction.getValueSentToMe(wallet);
    boolean received = false;
    String addressString = null;
    if (valueSentToMe.isZero()) {
        for (TransactionOutput output : transaction.getOutputs()) {
            if (!btcWalletService.isTransactionOutputMine(output)) {
                received = false;
                if (WalletService.isOutputScriptConvertibleToAddress(output)) {
                    addressString = WalletService.getAddressStringFromOutput(output);
                    break;
                }
            }
        }
    } else if (valueSentFromMe.isZero()) {
        received = true;
        for (TransactionOutput output : transaction.getOutputs()) {
            if (btcWalletService.isTransactionOutputMine(output) && WalletService.isOutputScriptConvertibleToAddress(output)) {
                addressString = WalletService.getAddressStringFromOutput(output);
                break;
            }
        }
    } else {
        boolean outgoing = false;
        for (TransactionOutput output : transaction.getOutputs()) {
            if (!btcWalletService.isTransactionOutputMine(output)) {
                if (WalletService.isOutputScriptConvertibleToAddress(output)) {
                    addressString = WalletService.getAddressStringFromOutput(output);
                    outgoing = !(BisqEnvironment.isBaseCurrencySupportingBsq() && bsqWalletService.isTransactionOutputMine(output));
                    break;
                }
            }
        }
        if (outgoing) {
            received = false;
        }
    }
    final TransactionConfidence confidence = transaction.getConfidence();
    int confirmations = null == confidence ? 0 : confidence.getDepthInBlocks();
    final WalletTransaction walletTransaction = new WalletTransaction();
    walletTransaction.updateTime = transaction.getUpdateTime().getTime();
    walletTransaction.hash = transaction.getHashAsString();
    walletTransaction.fee = (transaction.getFee() == null) ? -1 : transaction.getFee().value;
    walletTransaction.value = transaction.getValue(wallet).value;
    walletTransaction.valueSentFromMe = valueSentFromMe.value;
    walletTransaction.valueSentToMe = valueSentToMe.value;
    walletTransaction.confirmations = confirmations;
    walletTransaction.inbound = received;
    walletTransaction.address = addressString;
    return walletTransaction;
}
Also used : Coin(org.bitcoinj.core.Coin) TransactionOutput(org.bitcoinj.core.TransactionOutput) WalletTransaction(network.bisq.api.model.WalletTransaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) NotNull(org.jetbrains.annotations.NotNull) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull)

Example 18 with TransactionConfidence

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

the class BuyerSetupPayoutTxListener method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (!trade.isPayoutPublished()) {
            BtcWalletService walletService = processModel.getBtcWalletService();
            final String id = processModel.getOffer().getId();
            Address address = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT).getAddress();
            final TransactionConfidence confidence = walletService.getConfidenceForAddress(address);
            if (isInNetwork(confidence)) {
                applyConfidence(confidence);
            } else {
                confidenceListener = new AddressConfidenceListener(address) {

                    @Override
                    public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
                        if (isInNetwork(confidence))
                            applyConfidence(confidence);
                    }
                };
                walletService.addAddressConfidenceListener(confidenceListener);
                tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), newValue -> {
                    if (trade.isPayoutPublished()) {
                        swapMultiSigEntry();
                        // hack to remove tradeStateSubscription at callback
                        UserThread.execute(this::unSubscribe);
                    }
                });
            }
        }
        // we complete immediately, our object stays alive because the balanceListener is stored in the WalletService
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) Trade(bisq.core.trade.Trade) Subscription(org.fxmisc.easybind.Subscription) Slf4j(lombok.extern.slf4j.Slf4j) TaskRunner(bisq.common.taskrunner.TaskRunner) AddressEntry(bisq.core.btc.AddressEntry) EasyBind(org.fxmisc.easybind.EasyBind) UserThread(bisq.common.UserThread) Address(org.bitcoinj.core.Address) AddressConfidenceListener(bisq.core.btc.listeners.AddressConfidenceListener) TradeTask(bisq.core.trade.protocol.tasks.TradeTask) AddressConfidenceListener(bisq.core.btc.listeners.AddressConfidenceListener) Address(org.bitcoinj.core.Address) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) 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