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