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());
}
}
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());
}
}
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);
}
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());
}
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);
}
}
}
Aggregations