Search in sources :

Example 11 with TransactionConfidence

use of org.bitcoinj.core.TransactionConfidence in project bitcoin-wallet by bitcoin-wallet.

the class SendCoinsFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.fragmentManager = getChildFragmentManager();
    setHasOptionsMenu(true);
    walletActivityViewModel = new ViewModelProvider(activity).get(AbstractWalletActivityViewModel.class);
    walletActivityViewModel.wallet.observe(this, wallet -> updateView());
    viewModel = new ViewModelProvider(this).get(SendCoinsViewModel.class);
    viewModel.addressBook.observe(this, addressBook -> updateView());
    if (config.isEnableExchangeRates()) {
        viewModel.exchangeRate.observe(this, exchangeRate -> {
            final SendCoinsViewModel.State state = viewModel.state;
            if (state == null || state.compareTo(SendCoinsViewModel.State.INPUT) <= 0)
                amountCalculatorLink.setExchangeRate(exchangeRate != null ? exchangeRate.exchangeRate() : null);
        });
    }
    viewModel.dynamicFees.observe(this, dynamicFees -> {
        updateView();
        handler.post(dryrunRunnable);
    });
    application.blockchainState.observe(this, blockchainState -> updateView());
    viewModel.balance.observe(this, coin -> activity.invalidateOptionsMenu());
    viewModel.progress.observe(this, new ProgressDialogFragment.Observer(fragmentManager));
    viewModel.sentTransaction.observe(this, transaction -> {
        if (viewModel.state == SendCoinsViewModel.State.SENDING) {
            final TransactionConfidence confidence = transaction.getConfidence();
            final ConfidenceType confidenceType = confidence.getConfidenceType();
            final int numBroadcastPeers = confidence.numBroadcastPeers();
            if (confidenceType == ConfidenceType.DEAD)
                setState(SendCoinsViewModel.State.FAILED);
            else if (numBroadcastPeers > 1 || confidenceType == ConfidenceType.BUILDING)
                setState(SendCoinsViewModel.State.SENT);
        }
        updateView();
    });
    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());
    if (savedInstanceState == null) {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;
        final String mimeType = intent.getType();
        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && intentUri != null && "bitcoin".equals(scheme)) {
            initStateFromBitcoinUri(intentUri);
        } else if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(PaymentProtocol.MIMETYPE_PAYMENTREQUEST, ndefMessage);
            initStateFromPaymentRequest(mimeType, ndefMessagePayload);
        } else if ((Intent.ACTION_VIEW.equals(action)) && PaymentProtocol.MIMETYPE_PAYMENTREQUEST.equals(mimeType)) {
            final byte[] paymentRequest = BitcoinIntegration.paymentRequestFromIntent(intent);
            if (intentUri != null)
                initStateFromIntentUri(mimeType, intentUri);
            else if (paymentRequest != null)
                initStateFromPaymentRequest(mimeType, paymentRequest);
            else
                throw new IllegalArgumentException();
        } else if (intent.hasExtra(SendCoinsActivity.INTENT_EXTRA_PAYMENT_INTENT)) {
            initStateFromIntentExtras(intent.getExtras());
        } else {
            updateStateFrom(PaymentIntent.blank());
        }
    }
}
Also used : ProgressDialogFragment(de.schildbach.wallet.ui.ProgressDialogFragment) Handler(android.os.Handler) NdefMessage(android.nfc.NdefMessage) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) Intent(android.content.Intent) Uri(android.net.Uri) ConfidenceType(org.bitcoinj.core.TransactionConfidence.ConfidenceType) HandlerThread(android.os.HandlerThread) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 12 with TransactionConfidence

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

the class Trade method setupConfidenceListener.

private void setupConfidenceListener() {
    if (getDepositTx() != null) {
        TransactionConfidence transactionConfidence = getDepositTx().getConfidence();
        if (transactionConfidence.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING) {
            setConfirmedState();
        } else {
            ListenableFuture<TransactionConfidence> future = transactionConfidence.getDepthFuture(1);
            Futures.addCallback(future, new FutureCallback<TransactionConfidence>() {

                @Override
                public void onSuccess(TransactionConfidence result) {
                    setConfirmedState();
                }

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

Example 13 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)

Example 14 with TransactionConfidence

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

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

the class TransactionsView method setRevertTxColumnCellFactory.

private void setRevertTxColumnCellFactory() {
    revertTxColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
    revertTxColumn.setCellFactory(new Callback<TableColumn<TransactionsListItem, TransactionsListItem>, TableCell<TransactionsListItem, TransactionsListItem>>() {

        @Override
        public TableCell<TransactionsListItem, TransactionsListItem> call(TableColumn<TransactionsListItem, TransactionsListItem> column) {
            return new TableCell<TransactionsListItem, TransactionsListItem>() {

                Button button;

                @Override
                public void updateItem(final TransactionsListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        TransactionConfidence confidence = btcWalletService.getConfidenceForTxId(item.getTxId());
                        if (confidence != null) {
                            if (confidence.getConfidenceType() == TransactionConfidence.ConfidenceType.PENDING) {
                                if (button == null) {
                                    button = new AutoTooltipButton(Res.get("funds.tx.revert"));
                                    setGraphic(button);
                                }
                                button.setOnAction(e -> revertTransaction(item.getTxId(), item.getTradable()));
                            } else {
                                setGraphic(null);
                                if (button != null) {
                                    button.setOnAction(null);
                                    button = null;
                                }
                            }
                        }
                    } else {
                        setGraphic(null);
                        if (button != null) {
                            button.setOnAction(null);
                            button = null;
                        }
                    }
                }
            };
        }
    });
}
Also used : Button(javafx.scene.control.Button) EventHandler(javafx.event.EventHandler) Transaction(org.bitcoinj.core.Transaction) OpenOffer(bisq.core.offer.OpenOffer) Utilities(bisq.common.util.Utilities) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Coin(org.bitcoinj.core.Coin) Date(java.util.Date) CSVEntryConverter(com.googlecode.jcsv.writer.CSVEntryConverter) VBox(javafx.scene.layout.VBox) BSFormatter(bisq.desktop.util.BSFormatter) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) Res(bisq.core.locale.Res) Locale(java.util.Locale) Map(java.util.Map) TableView(javafx.scene.control.TableView) DateFormat(java.text.DateFormat) SortedList(javafx.collections.transformation.SortedList) Popup(bisq.desktop.main.overlays.popups.Popup) P2PService(bisq.network.p2p.P2PService) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) KeyEvent(javafx.scene.input.KeyEvent) Collectors(java.util.stream.Collectors) ECKey(org.bitcoinj.core.ECKey) FXML(javafx.fxml.FXML) List(java.util.List) Script(org.bitcoinj.script.Script) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Preferences(bisq.core.user.Preferences) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) GUIUtil(bisq.desktop.util.GUIUtil) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Scene(javafx.scene.Scene) WalletEventListener(org.bitcoinj.wallet.listeners.WalletEventListener) ActivatableView(bisq.desktop.common.view.ActivatableView) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) OfferDetailsWindow(bisq.desktop.main.overlays.windows.OfferDetailsWindow) Wallet(org.bitcoinj.wallet.Wallet) HashMap(java.util.HashMap) Tradable(bisq.core.trade.Tradable) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) Tuple4(bisq.common.util.Tuple4) Inject(javax.inject.Inject) Tuple2(bisq.common.util.Tuple2) TableCell(javafx.scene.control.TableCell) AddressWithIconAndDirection(bisq.desktop.components.AddressWithIconAndDirection) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) Nullable(javax.annotation.Nullable) KeyCode(javafx.scene.input.KeyCode) TradeDetailsWindow(bisq.desktop.main.overlays.windows.TradeDetailsWindow) Trade(bisq.core.trade.Trade) Stage(javafx.stage.Stage) Comparator(java.util.Comparator) TableColumn(javafx.scene.control.TableColumn) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) TableCell(javafx.scene.control.TableCell) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) 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