use of org.bitcoinj.core.PrefixedChecksummedBytes 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();
}
}
use of org.bitcoinj.core.PrefixedChecksummedBytes 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.PrefixedChecksummedBytes in project bitcoin-wallet by bitcoin-wallet.
the class SweepWalletFragment method maybeDecodeKey.
private void maybeDecodeKey() {
checkState(viewModel.state == SweepWalletViewModel.State.DECODE_KEY);
final PrefixedChecksummedBytes privateKeyToSweep = viewModel.privateKeyToSweep.getValue();
checkState(privateKeyToSweep != null);
if (privateKeyToSweep instanceof DumpedPrivateKey) {
final ECKey key = ((DumpedPrivateKey) privateKeyToSweep).getKey();
askConfirmSweep(key);
} else if (privateKeyToSweep instanceof BIP38PrivateKey) {
badPasswordView.setVisibility(View.INVISIBLE);
final String password = passwordView.getText().toString().trim();
// get rid of it asap
passwordView.setText(null);
if (!password.isEmpty()) {
viewModel.progress.setValue(getString(R.string.sweep_wallet_fragment_decrypt_progress));
new DecodePrivateKeyTask(backgroundHandler) {
@Override
protected void onSuccess(ECKey decryptedKey) {
log.info("successfully decoded BIP38 private key");
viewModel.progress.setValue(null);
askConfirmSweep(decryptedKey);
}
@Override
protected void onBadPassphrase() {
log.info("failed decoding BIP38 private key (bad password)");
viewModel.progress.setValue(null);
badPasswordView.setVisibility(View.VISIBLE);
passwordView.requestFocus();
}
}.decodePrivateKey((BIP38PrivateKey) privateKeyToSweep, password);
}
} else {
throw new IllegalStateException("cannot handle type: " + privateKeyToSweep.getClass().getName());
}
}
use of org.bitcoinj.core.PrefixedChecksummedBytes 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);
}
}
}
use of org.bitcoinj.core.PrefixedChecksummedBytes in project bitcoin-wallet by bitcoin-wallet.
the class SweepWalletFragment method updateView.
private void updateView() {
final PrefixedChecksummedBytes privateKeyToSweep = viewModel.privateKeyToSweep.getValue();
final Wallet wallet = walletActivityViewModel.wallet.getValue();
final Map<FeeCategory, Coin> fees = viewModel.getDynamicFees().getValue();
final MonetaryFormat btcFormat = config.getFormat();
if (viewModel.state == SweepWalletViewModel.State.DECODE_KEY && privateKeyToSweep == null) {
messageView.setVisibility(View.VISIBLE);
messageView.setText(R.string.sweep_wallet_fragment_wallet_unknown);
} else if (viewModel.state == SweepWalletViewModel.State.DECODE_KEY && privateKeyToSweep != null) {
messageView.setVisibility(View.VISIBLE);
messageView.setText(R.string.sweep_wallet_fragment_encrypted);
} else if (privateKeyToSweep != null) {
messageView.setVisibility(View.GONE);
}
passwordViewGroup.setVisibility(viewModel.state == SweepWalletViewModel.State.DECODE_KEY && privateKeyToSweep != null ? View.VISIBLE : View.GONE);
hintView.setVisibility(viewModel.state == SweepWalletViewModel.State.DECODE_KEY && privateKeyToSweep == null ? View.VISIBLE : View.GONE);
final Transaction sentTransaction = viewModel.sentTransaction.getValue();
if (sentTransaction != null) {
sweepTransactionView.setVisibility(View.VISIBLE);
sweepTransactionViewHolder.fullBind(new TransactionsAdapter.ListItem.TransactionItem(activity, sentTransaction, wallet, null, btcFormat, application.maxConnectedPeers()));
} else {
sweepTransactionView.setVisibility(View.GONE);
}
final Wallet walletToSweep = viewModel.walletToSweep.getValue();
if (viewModel.state == SweepWalletViewModel.State.DECODE_KEY) {
viewCancel.setText(R.string.button_cancel);
viewGo.setText(R.string.sweep_wallet_fragment_button_decrypt);
viewGo.setEnabled(privateKeyToSweep != null);
} else if (viewModel.state == SweepWalletViewModel.State.CONFIRM_SWEEP) {
viewCancel.setText(R.string.button_cancel);
viewGo.setText(R.string.sweep_wallet_fragment_button_sweep);
viewGo.setEnabled(wallet != null && walletToSweep != null && walletToSweep.getBalance(BalanceType.ESTIMATED).signum() > 0 && fees != null);
} else if (viewModel.state == SweepWalletViewModel.State.PREPARATION) {
viewCancel.setText(R.string.button_cancel);
viewGo.setText(R.string.send_coins_preparation_msg);
viewGo.setEnabled(false);
} else if (viewModel.state == SweepWalletViewModel.State.SENDING) {
viewCancel.setText(R.string.send_coins_fragment_button_back);
viewGo.setText(R.string.send_coins_sending_msg);
viewGo.setEnabled(false);
} else if (viewModel.state == SweepWalletViewModel.State.SENT) {
viewCancel.setText(R.string.send_coins_fragment_button_back);
viewGo.setText(R.string.send_coins_sent_msg);
viewGo.setEnabled(false);
} else if (viewModel.state == SweepWalletViewModel.State.FAILED) {
viewCancel.setText(R.string.send_coins_fragment_button_back);
viewGo.setText(R.string.send_coins_failed_msg);
viewGo.setEnabled(false);
}
viewCancel.setEnabled(viewModel.state != SweepWalletViewModel.State.PREPARATION);
// enable actions
if (reloadAction != null)
reloadAction.setEnabled(viewModel.state == SweepWalletViewModel.State.CONFIRM_SWEEP && walletToSweep != null);
if (scanAction != null)
scanAction.setEnabled(viewModel.state == SweepWalletViewModel.State.DECODE_KEY || viewModel.state == SweepWalletViewModel.State.CONFIRM_SWEEP);
}
Aggregations