use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.
the class BlockListAdapter method bindView.
public void bindView(final View row, final Transaction tx) {
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);
// receiving or sending
final TextView rowFromTo = (TextView) row.findViewById(R.id.block_row_transaction_fromto);
if (isInternal || self)
rowFromTo.setText(R.string.symbol_internal);
else if (sent)
rowFromTo.setText(R.string.symbol_to);
else
rowFromTo.setText(R.string.symbol_from);
// address
final TextView rowAddress = (TextView) row.findViewById(R.id.block_row_transaction_address);
final String label;
if (isCoinBase)
label = textCoinBase;
else if (isInternal || self)
label = textInternal;
else if (address != null)
label = AddressBookProvider.resolveLabel(context, address.toBase58());
else
label = "?";
rowAddress.setText(label != null ? label : address.toBase58());
rowAddress.setTypeface(label != null ? Typeface.DEFAULT : Typeface.MONOSPACE);
// value
final CurrencyTextView rowValue = (CurrencyTextView) row.findViewById(R.id.block_row_transaction_value);
rowValue.setAlwaysSigned(true);
rowValue.setFormat(format);
rowValue.setAmount(value);
}
use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.
the class SendingAddressesFragment method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
adapter = new SimpleCursorAdapter(activity, R.layout.address_book_row, null, new String[] { AddressBookProvider.KEY_LABEL, AddressBookProvider.KEY_ADDRESS }, new int[] { R.id.address_book_row_label, R.id.address_book_row_address }, 0);
adapter.setViewBinder(new ViewBinder() {
@Override
public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
if (!AddressBookProvider.KEY_ADDRESS.equals(cursor.getColumnName(columnIndex)))
return false;
((TextView) view).setText(WalletUtils.formatHash(cursor.getString(columnIndex), Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));
return true;
}
});
setListAdapter(adapter);
final List<ECKey> derivedKeys = wallet.getIssuedReceiveKeys();
Collections.sort(derivedKeys, DeterministicKey.CHILDNUM_ORDER);
final List<ECKey> randomKeys = wallet.getImportedKeys();
final StringBuilder builder = new StringBuilder();
for (final ECKey key : Iterables.concat(derivedKeys, randomKeys)) {
final Address address = key.toAddress(Constants.NETWORK_PARAMETERS);
builder.append(address.toBase58()).append(",");
}
if (builder.length() > 0)
builder.setLength(builder.length() - 1);
walletAddressesSelection = builder.toString();
loaderManager.initLoader(0, null, this);
}
use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.
the class SendingAddressesFragment 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) {
// workaround for "IllegalStateException: Can not perform this action after
// onSaveInstanceState"
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (paymentIntent.hasAddress()) {
final Address address = paymentIntent.getAddress();
if (!wallet.isPubKeyHashMine(address.getHash160()))
EditAddressBookEntryFragment.edit(getFragmentManager(), address);
else
dialog(activity, null, R.string.address_book_options_scan_title, R.string.address_book_options_scan_own_address);
} else {
dialog(activity, null, R.string.address_book_options_scan_title, R.string.address_book_options_scan_invalid);
}
}
}, 500);
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
cannotClassify(input);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(activity, null, R.string.address_book_options_scan_title, messageResId, messageArgs);
}
}.parse();
}
}
use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.
the class WalletAddressesAdapter method rowKey.
private View rowKey(final int position, View row) {
final ECKey key = (ECKey) getItem(position);
final Address address = key.toAddress(Constants.NETWORK_PARAMETERS);
final boolean isRotateKey = wallet.isKeyRotating(key);
if (row == null)
row = inflater.inflate(R.layout.address_book_row, null);
final TextView addressView = (TextView) row.findViewById(R.id.address_book_row_address);
addressView.setText(WalletUtils.formatAddress(address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));
addressView.setTextColor(isRotateKey ? colorInsignificant : colorSignificant);
final TextView labelView = (TextView) row.findViewById(R.id.address_book_row_label);
final String label = AddressBookProvider.resolveLabel(context, address.toBase58());
if (label != null) {
labelView.setText(label);
labelView.setTextColor(isRotateKey ? colorInsignificant : colorLessSignificant);
} else {
labelView.setText(R.string.address_unlabeled);
labelView.setTextColor(colorInsignificant);
}
final TextView messageView = (TextView) row.findViewById(R.id.address_book_row_message);
messageView.setVisibility(isRotateKey ? View.VISIBLE : View.GONE);
return row;
}
use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.
the class WalletTransactionsFragment method onTransactionMenuClick.
@Override
public void onTransactionMenuClick(final View view, final Transaction tx) {
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();
final boolean txRotation = tx.getPurpose() == Purpose.KEY_ROTATION;
final PopupMenu popupMenu = new PopupMenu(activity, view);
popupMenu.inflate(R.menu.wallet_transactions_context);
final MenuItem editAddressMenuItem = popupMenu.getMenu().findItem(R.id.wallet_transactions_context_edit_address);
if (!txRotation && txAddress != null) {
editAddressMenuItem.setVisible(true);
final boolean isAdd = AddressBookProvider.resolveLabel(activity, txAddress.toBase58()) == null;
final boolean isOwn = wallet.isPubKeyHashMine(txAddress.getHash160());
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);
}
popupMenu.getMenu().findItem(R.id.wallet_transactions_context_show_qr).setVisible(!txRotation && txSerialized.length < SHOW_QR_THRESHOLD_BYTES);
popupMenu.getMenu().findItem(R.id.wallet_transactions_context_raise_fee).setVisible(RaiseFeeDialogFragment.feeCanLikelyBeRaised(wallet, tx));
popupMenu.getMenu().findItem(R.id.wallet_transactions_context_browse).setVisible(Constants.ENABLE_BROWSE);
popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
switch(item.getItemId()) {
case R.id.wallet_transactions_context_edit_address:
handleEditAddress(tx);
return true;
case R.id.wallet_transactions_context_show_qr:
handleShowQr();
return true;
case R.id.wallet_transactions_context_raise_fee:
RaiseFeeDialogFragment.show(getFragmentManager(), tx);
return true;
case R.id.wallet_transactions_context_report_issue:
handleReportIssue(tx);
return true;
case R.id.wallet_transactions_context_browse:
if (!txRotation) {
final String txHash = tx.getHashAsString();
final Uri blockExplorerUri = config.getBlockExplorer();
log.info("Viewing transaction {} on {}", txHash, blockExplorerUri);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(blockExplorerUri, "tx/" + txHash)));
} else {
startActivity(new Intent(Intent.ACTION_VIEW, KEY_ROTATION_URI));
}
return true;
}
return false;
}
private void handleEditAddress(final Transaction tx) {
EditAddressBookEntryFragment.edit(getFragmentManager(), txAddress);
}
private void handleShowQr() {
final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(txSerialized));
BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
}
private void handleReportIssue(final Transaction tx) {
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');
contextualData.append(tx.toString());
ReportIssueDialogFragment.show(getFragmentManager(), R.string.report_issue_dialog_title_transaction, R.string.report_issue_dialog_message_issue, Constants.REPORT_SUBJECT_ISSUE, contextualData.toString());
}
});
popupMenu.show();
}
Aggregations