use of org.bitcoinj.wallet.Wallet in project bitcoin-wallet by bitcoin-wallet.
the class WalletAddressesFragment method maybeSubmitList.
private void maybeSubmitList() {
final List<Address> derivedAddresses = viewModel.issuedReceiveAddresses.getValue();
final List<Address> randomAddresses = viewModel.importedAddresses.getValue();
final Wallet wallet = walletActivityViewModel.wallet.getValue();
if (derivedAddresses != null && randomAddresses != null) {
viewGroup.setDisplayedChild(1);
adapter.submitList(AddressBookAdapter.buildListItems(activity, derivedAddresses, randomAddresses, wallet, AddressBookEntry.asMap(viewModel.addressBook.getValue())));
}
}
use of org.bitcoinj.wallet.Wallet in project bitcoin-wallet by bitcoin-wallet.
the class WalletTransactionsFragment method onInflateTransactionContextMenu.
@Override
public void onInflateTransactionContextMenu(final MenuInflater inflater, final Menu menu, final Sha256Hash transactionId) {
final Wallet wallet = viewModel.wallet.getValue();
final Transaction tx = wallet.getTransaction(transactionId);
final boolean txSent = tx.getValue(wallet).signum() < 0;
final Address txAddress = txSent ? WalletUtils.getToAddressOfSent(tx, wallet) : WalletUtils.getWalletAddressOfReceived(tx, wallet);
final byte[] txSerialized = tx.unsafeBitcoinSerialize();
inflater.inflate(R.menu.wallet_transactions_context, menu);
final MenuItem editAddressMenuItem = menu.findItem(R.id.wallet_transactions_context_edit_address);
if (txAddress != null) {
editAddressMenuItem.setVisible(true);
final boolean isAdd = addressBookDao.resolveLabel(txAddress.toString()) == null;
final boolean isOwn = wallet.isAddressMine(txAddress);
if (isOwn)
editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive : R.string.edit_address_book_entry_dialog_title_edit_receive);
else
editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add : R.string.edit_address_book_entry_dialog_title_edit);
} else {
editAddressMenuItem.setVisible(false);
}
menu.findItem(R.id.wallet_transactions_context_show_qr).setVisible(txSerialized.length < SHOW_QR_THRESHOLD_BYTES);
menu.findItem(R.id.wallet_transactions_context_raise_fee).setVisible(RaiseFeeDialogFragment.feeCanLikelyBeRaised(wallet, tx));
menu.findItem(R.id.wallet_transactions_context_browse).setVisible(Constants.ENABLE_BROWSE);
}
use of org.bitcoinj.wallet.Wallet in project bitcoin-wallet by bitcoin-wallet.
the class AcceptBluetoothService method handleTx.
private boolean handleTx(final Transaction tx) {
log.info("tx {} arrived via blueooth", tx.getTxId());
final Wallet wallet = this.wallet.getValue();
try {
if (wallet.isTransactionRelevant(tx)) {
wallet.receivePending(tx, null);
new BlockchainServiceLiveData(this).observe(this, blockchainService -> blockchainService.broadcastTransaction(tx));
} else {
log.info("tx {} irrelevant", tx.getTxId());
}
return true;
} catch (final VerificationException x) {
log.info("cannot verify tx " + tx.getTxId() + " received via bluetooth", x);
}
return false;
}
use of org.bitcoinj.wallet.Wallet 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.wallet.Wallet 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;
}
Aggregations