use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class AbstractWalletActivityViewModel method broadcastTransaction.
public ListenableFuture<Transaction> broadcastTransaction(final Transaction tx) throws VerificationException {
final SettableFuture<Transaction> future = SettableFuture.create();
wallet.observeForever(new Observer<Wallet>() {
@Override
public void onChanged(final Wallet wallet) {
blockchainService.observeForever(new Observer<BlockchainService>() {
@Override
public void onChanged(final BlockchainService blockchainService) {
if (wallet.isTransactionRelevant(tx)) {
wallet.receivePending(tx, null);
final TransactionBroadcast broadcast = blockchainService.broadcastTransaction(tx);
if (broadcast != null) {
broadcast.future().addListener(() -> {
log.info("broadcasting transaction {} complete, dropping all peers", tx.getTxId());
blockchainService.dropAllPeers();
}, Threading.SAME_THREAD);
future.setFuture(broadcast.future());
} else {
log.info("impediments; will send {} later", tx.getTxId());
future.cancel(false);
}
} else {
log.info("tx {} irrelevant", tx.getTxId());
future.cancel(false);
}
AbstractWalletActivityViewModel.this.blockchainService.removeObserver(this);
}
});
AbstractWalletActivityViewModel.this.wallet.removeObserver(this);
}
});
return future;
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class WalletActivity method onActivityResult.
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
if (requestCode == REQUEST_CODE_SCAN) {
if (resultCode == Activity.RESULT_OK) {
final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
SendCoinsActivity.start(WalletActivity.this, paymentIntent);
}
@Override
protected void handlePrivateKey(final PrefixedChecksummedBytes key) {
if (Constants.ENABLE_SWEEP_WALLET)
SweepWalletActivity.start(WalletActivity.this, key);
else
super.handlePrivateKey(key);
}
@Override
protected void handleDirectTransaction(final Transaction tx) throws VerificationException {
walletActivityViewModel.broadcastTransaction(tx);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
final DialogBuilder dialog = DialogBuilder.dialog(WalletActivity.this, R.string.button_scan, messageResId, messageArgs);
dialog.singleDismissButton(null);
dialog.show();
}
}.parse();
}
} else {
super.onActivityResult(requestCode, resultCode, intent);
}
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class ReportIssueDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final Bundle args = getArguments();
final int titleResId = args.getInt(KEY_TITLE);
final int messageResId = args.getInt(KEY_MESSAGE);
final String subject = args.getString(KEY_SUBJECT);
final Sha256Hash contextualTransactionHash = args.containsKey(KEY_CONTEXTUAL_TRANSACTION_HASH) ? Sha256Hash.wrap(args.getByteArray(KEY_CONTEXTUAL_TRANSACTION_HASH)) : null;
final ReportIssueDialogBuilder builder = new ReportIssueDialogBuilder(activity, titleResId, messageResId) {
@Override
protected String subject() {
final StringBuilder builder = new StringBuilder(subject).append(": ");
final PackageInfo pi = application.packageInfo();
builder.append(WalletApplication.versionLine(pi));
final String installer = Installer.installerPackageName(application);
if (installer != null)
builder.append(", installer ").append(installer);
builder.append(", android ").append(Build.VERSION.RELEASE);
builder.append(" (").append(Build.VERSION.SECURITY_PATCH).append(")");
builder.append(", ").append(Build.MANUFACTURER);
if (!Build.BRAND.equalsIgnoreCase(Build.MANUFACTURER))
builder.append(' ').append(Build.BRAND);
builder.append(' ').append(Build.MODEL);
return builder.toString();
}
@Override
protected CharSequence collectApplicationInfo() throws IOException {
final StringBuilder applicationInfo = new StringBuilder();
appendApplicationInfo(applicationInfo, application);
return applicationInfo;
}
@Override
protected CharSequence collectStackTrace() throws IOException {
final StringBuilder stackTrace = new StringBuilder();
CrashReporter.appendSavedCrashTrace(stackTrace);
return stackTrace.length() > 0 ? stackTrace : null;
}
@Override
protected CharSequence collectDeviceInfo() throws IOException {
final StringBuilder deviceInfo = new StringBuilder();
appendDeviceInfo(deviceInfo, activity);
return deviceInfo;
}
@Override
protected CharSequence collectContextualData() {
if (contextualTransactionHash == null)
return null;
final Wallet wallet = walletActivityViewModel.wallet.getValue();
final Transaction tx = wallet.getTransaction(contextualTransactionHash);
final StringBuilder contextualData = new StringBuilder();
try {
contextualData.append(tx.getValue(wallet).toFriendlyString()).append(" total value");
} catch (final ScriptException x) {
contextualData.append(x.getMessage());
}
contextualData.append('\n');
if (tx.hasConfidence())
contextualData.append(" confidence: ").append(tx.getConfidence()).append('\n');
final String[] blockExplorers = activity.getResources().getStringArray(R.array.preferences_block_explorer_values);
for (final String blockExplorer : blockExplorers) contextualData.append(Uri.withAppendedPath(Uri.parse(blockExplorer), "tx/" + tx.getTxId().toString())).append('\n');
contextualData.append(tx.toString()).append('\n');
contextualData.append(Constants.HEX.encode(tx.unsafeBitcoinSerialize())).append('\n');
return contextualData;
}
@Override
protected CharSequence collectWalletDump() {
return walletActivityViewModel.wallet.getValue().toString(false, false, null, true, true, null);
}
};
final AlertDialog dialog = builder.create();
dialog.setOnShowListener(d -> {
positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setEnabled(false);
walletActivityViewModel.wallet.observe(ReportIssueDialogFragment.this, wallet -> positiveButton.setEnabled(true));
});
return dialog;
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class BlockListAdapter method buildTransactionItems.
private static List<ListItem.TxItem> buildTransactionItems(final Context context, final Sha256Hash blockHash, @Nullable final Set<Transaction> transactions, @Nullable final Wallet wallet, @Nullable final Map<String, AddressBookEntry> addressBook) {
final List<ListItem.TxItem> transactionItems = new LinkedList<>();
if (transactions != null && wallet != null) {
for (final Transaction tx : transactions) {
final Map<Sha256Hash, Integer> appearsInHashes = tx.getAppearsInHashes();
if (appearsInHashes != null && appearsInHashes.containsKey(blockHash)) {
final boolean isCoinBase = tx.isCoinBase();
final boolean isInternal = tx.getPurpose() == Purpose.KEY_ROTATION;
final Coin value = tx.getValue(wallet);
final boolean sent = value.signum() < 0;
final boolean self = WalletUtils.isEntirelySelf(tx, wallet);
final Address address;
if (sent)
address = WalletUtils.getToAddressOfSent(tx, wallet);
else
address = WalletUtils.getWalletAddressOfReceived(tx, wallet);
final CharSequence fromTo;
if (isInternal || self)
fromTo = context.getString(R.string.symbol_internal);
else if (sent)
fromTo = context.getString(R.string.symbol_to);
else
fromTo = context.getString(R.string.symbol_from);
final CharSequence label;
if (isCoinBase) {
label = context.getString(R.string.wallet_transactions_fragment_coinbase);
} else if (isInternal || self) {
label = context.getString(R.string.wallet_transactions_fragment_internal);
} else if (address != null && addressBook != null) {
final AddressBookEntry entry = addressBook.get(address.toString());
if (entry != null)
label = entry.getLabel();
else
label = "?";
} else {
label = "?";
}
final CharSequence addressText = label != null ? label : address.toString();
final Typeface addressTypeface = label != null ? Typeface.DEFAULT : Typeface.MONOSPACE;
transactionItems.add(new ListItem.TxItem(fromTo, addressText, addressTypeface, label, value));
}
}
}
return transactionItems;
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsQrActivity method onActivityResult.
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
if (requestCode == REQUEST_CODE_SCAN && resultCode == Activity.RESULT_OK) {
final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
SendCoinsActivity.start(SendCoinsQrActivity.this, paymentIntent);
SendCoinsQrActivity.this.finish();
}
@Override
protected void handlePrivateKey(final PrefixedChecksummedBytes key) {
if (Constants.ENABLE_SWEEP_WALLET) {
SweepWalletActivity.start(SendCoinsQrActivity.this, key);
SendCoinsQrActivity.this.finish();
} else {
super.handlePrivateKey(key);
}
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
walletActivityViewModel.broadcastTransaction(transaction);
SendCoinsQrActivity.this.finish();
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
final DialogBuilder dialog = DialogBuilder.dialog(SendCoinsQrActivity.this, 0, messageResId, messageArgs);
dialog.singleDismissButton(dismissListener);
dialog.show();
}
private final OnClickListener dismissListener = (dialog, which) -> SendCoinsQrActivity.this.finish();
}.parse();
} else {
finish();
}
}
Aggregations