Search in sources :

Example 6 with TransactionConfidence

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

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

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

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

the class BisqProxy method convertAddressEntryToWalletAddress.

@NotNull
private static WalletAddress convertAddressEntryToWalletAddress(AddressEntry entry, BtcWalletService btcWalletService) {
    final Coin balance;
    if (AddressEntry.Context.MULTI_SIG.equals(entry.getContext())) {
        balance = entry.getCoinLockedInMultiSig();
    } else {
        balance = btcWalletService.getBalanceForAddress(entry.getAddress());
    }
    final TransactionConfidence confidence = btcWalletService.getConfidenceForAddress(entry.getAddress());
    final int confirmations = null == confidence ? 0 : confidence.getDepthInBlocks();
    return new WalletAddress(entry.getAddressString(), balance.getValue(), confirmations, entry.getContext(), entry.getOfferId());
}
Also used : Coin(org.bitcoinj.core.Coin) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) WalletAddress(network.bisq.api.model.WalletAddress) NotNull(org.jetbrains.annotations.NotNull) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull)

Example 10 with TransactionConfidence

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

the class SweepWalletFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.fragmentManager = getChildFragmentManager();
    setHasOptionsMenu(true);
    if (!Constants.ENABLE_SWEEP_WALLET)
        throw new IllegalStateException("ENABLE_SWEEP_WALLET is disabled");
    walletActivityViewModel = new ViewModelProvider(activity).get(AbstractWalletActivityViewModel.class);
    walletActivityViewModel.wallet.observe(this, wallet -> updateView());
    viewModel = new ViewModelProvider(this).get(SweepWalletViewModel.class);
    viewModel.getDynamicFees().observe(this, dynamicFees -> updateView());
    viewModel.progress.observe(this, new ProgressDialogFragment.Observer(fragmentManager));
    viewModel.privateKeyToSweep.observe(this, privateKeyToSweep -> updateView());
    viewModel.walletToSweep.observe(this, walletToSweep -> {
        if (walletToSweep != null) {
            balanceView.setVisibility(View.VISIBLE);
            final MonetaryFormat btcFormat = config.getFormat();
            final MonetarySpannable balanceSpannable = new MonetarySpannable(btcFormat, walletToSweep.getBalance(BalanceType.ESTIMATED));
            balanceSpannable.applyMarkup(null, null);
            final SpannableStringBuilder balance = new SpannableStringBuilder(balanceSpannable);
            balance.insert(0, ": ");
            balance.insert(0, getString(R.string.sweep_wallet_fragment_balance));
            balanceView.setText(balance);
        } else {
            balanceView.setVisibility(View.GONE);
        }
        updateView();
    });
    viewModel.sentTransaction.observe(this, transaction -> {
        if (viewModel.state == SweepWalletViewModel.State.SENDING) {
            final TransactionConfidence confidence = transaction.getConfidence();
            final ConfidenceType confidenceType = confidence.getConfidenceType();
            final int numBroadcastPeers = confidence.numBroadcastPeers();
            if (confidenceType == ConfidenceType.DEAD)
                setState(SweepWalletViewModel.State.FAILED);
            else if (numBroadcastPeers > 1 || confidenceType == ConfidenceType.BUILDING)
                setState(SweepWalletViewModel.State.SENT);
        }
        updateView();
    });
    viewModel.showDialog.observe(this, new DialogEvent.Observer(activity));
    viewModel.showDialogWithRetryRequestBalance.observe(this, new DialogEvent.Observer(activity) {

        @Override
        protected void onBuildButtons(final DialogBuilder dialog) {
            dialog.setPositiveButton(R.string.button_retry, (d, which) -> requestWalletBalance());
            dialog.setNegativeButton(R.string.button_dismiss, null);
        }
    });
    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());
    if (savedInstanceState == null) {
        final Intent intent = activity.getIntent();
        if (intent.hasExtra(SweepWalletActivity.INTENT_EXTRA_KEY)) {
            final PrefixedChecksummedBytes privateKeyToSweep = (PrefixedChecksummedBytes) intent.getSerializableExtra(SweepWalletActivity.INTENT_EXTRA_KEY);
            viewModel.privateKeyToSweep.setValue(privateKeyToSweep);
            // delay until fragment is resumed
            handler.post(maybeDecodeKeyRunnable);
        }
    }
}
Also used : MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) Bundle(android.os.Bundle) DumpedPrivateKey(org.bitcoinj.core.DumpedPrivateKey) Transaction(org.bitcoinj.core.Transaction) PackageManager(android.content.pm.PackageManager) Coin(org.bitcoinj.core.Coin) WalletTransaction(org.bitcoinj.wallet.WalletTransaction) LoggerFactory(org.slf4j.LoggerFactory) ScanActivity(de.schildbach.wallet.ui.scan.ScanActivity) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) Process(android.os.Process) NetworkParameters(org.bitcoinj.core.NetworkParameters) PrefixedChecksummedBytes(org.bitcoinj.core.PrefixedChecksummedBytes) SendRequest(org.bitcoinj.wallet.SendRequest) Handler(android.os.Handler) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) R(de.schildbach.wallet.R) Configuration(de.schildbach.wallet.Configuration) Constants(de.schildbach.wallet.Constants) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) BalanceType(org.bitcoinj.wallet.Wallet.BalanceType) ConfidenceType(org.bitcoinj.core.TransactionConfidence.ConfidenceType) Set(java.util.Set) ComparisonChain(com.google.common.collect.ComparisonChain) ViewGroup(android.view.ViewGroup) Preconditions.checkState(androidx.core.util.Preconditions.checkState) ECKey(org.bitcoinj.core.ECKey) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) TransactionsAdapter(de.schildbach.wallet.ui.TransactionsAdapter) TransactionOutput(org.bitcoinj.core.TransactionOutput) UTXO(org.bitcoinj.core.UTXO) Context(android.content.Context) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Wallet(org.bitcoinj.wallet.Wallet) Intent(android.content.Intent) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) ProgressDialogFragment(de.schildbach.wallet.ui.ProgressDialogFragment) SpannableStringBuilder(android.text.SpannableStringBuilder) VerificationException(org.bitcoinj.core.VerificationException) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) DialogEvent(de.schildbach.wallet.ui.DialogEvent) Sha256Hash(org.bitcoinj.core.Sha256Hash) BIP38PrivateKey(org.bitcoinj.crypto.BIP38PrivateKey) FragmentManager(androidx.fragment.app.FragmentManager) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) Logger(org.slf4j.Logger) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) Threading(org.bitcoinj.utils.Threading) AbstractWalletActivity(de.schildbach.wallet.ui.AbstractWalletActivity) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) HandlerThread(android.os.HandlerThread) TransactionInput(org.bitcoinj.core.TransactionInput) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) WalletApplication(de.schildbach.wallet.WalletApplication) Comparator(java.util.Comparator) Activity(android.app.Activity) EditText(android.widget.EditText) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) PrefixedChecksummedBytes(org.bitcoinj.core.PrefixedChecksummedBytes) ProgressDialogFragment(de.schildbach.wallet.ui.ProgressDialogFragment) Handler(android.os.Handler) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) Intent(android.content.Intent) MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) ConfidenceType(org.bitcoinj.core.TransactionConfidence.ConfidenceType) DialogEvent(de.schildbach.wallet.ui.DialogEvent) HandlerThread(android.os.HandlerThread) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) SpannableStringBuilder(android.text.SpannableStringBuilder) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

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