Search in sources :

Example 1 with AddressConfidenceListener

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

the class MakerSetupDepositTxListener method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getDepositTx() == null && processModel.getPreparedDepositTx() != null) {
            BtcWalletService walletService = processModel.getBtcWalletService();
            final NetworkParameters params = walletService.getParams();
            Transaction preparedDepositTx = new Transaction(params, processModel.getPreparedDepositTx());
            checkArgument(!preparedDepositTx.getOutputs().isEmpty(), "preparedDepositTx.getOutputs() must not be empty");
            Address depositTxAddress = preparedDepositTx.getOutput(0).getAddressFromP2SH(params);
            final TransactionConfidence confidence = walletService.getConfidenceForAddress(depositTxAddress);
            if (isInNetwork(confidence)) {
                applyConfidence(confidence);
            } else {
                confidenceListener = new AddressConfidenceListener(depositTxAddress) {

                    @Override
                    public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
                        if (isInNetwork(confidence))
                            applyConfidence(confidence);
                    }
                };
                walletService.addAddressConfidenceListener(confidenceListener);
                tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), newValue -> {
                    if (trade.isDepositPublished()) {
                        swapReservedForTradeEntry();
                        // 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) NetworkParameters(org.bitcoinj.core.NetworkParameters) Slf4j(lombok.extern.slf4j.Slf4j) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) 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) Transaction(org.bitcoinj.core.Transaction) Address(org.bitcoinj.core.Address) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) NetworkParameters(org.bitcoinj.core.NetworkParameters) TransactionConfidence(org.bitcoinj.core.TransactionConfidence)

Example 2 with AddressConfidenceListener

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

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

Example 3 with AddressConfidenceListener

use of bisq.core.btc.listeners.AddressConfidenceListener 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

AddressConfidenceListener (bisq.core.btc.listeners.AddressConfidenceListener)3 Transaction (org.bitcoinj.core.Transaction)3 TransactionConfidence (org.bitcoinj.core.TransactionConfidence)3 UserThread (bisq.common.UserThread)2 TaskRunner (bisq.common.taskrunner.TaskRunner)2 AddressEntry (bisq.core.btc.AddressEntry)2 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)2 Trade (bisq.core.trade.Trade)2 TradeTask (bisq.core.trade.protocol.tasks.TradeTask)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Address (org.bitcoinj.core.Address)2 EasyBind (org.fxmisc.easybind.EasyBind)2 Subscription (org.fxmisc.easybind.Subscription)2 BalanceListener (bisq.core.btc.listeners.BalanceListener)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Coin (org.bitcoinj.core.Coin)1 NetworkParameters (org.bitcoinj.core.NetworkParameters)1