use of org.bitcoinj.core.Transaction 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);
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class RaiseFeeDialogFragment method doRaiseFee.
private void doRaiseFee(final Wallet wallet, final KeyParameter encryptionKey) {
// construct child-pays-for-parent
final TransactionOutput outputToSpend = checkNotNull(findSpendableOutput(wallet, transaction, feeRaise));
final Transaction transactionToSend = new Transaction(Constants.NETWORK_PARAMETERS);
transactionToSend.addInput(outputToSpend);
transactionToSend.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE));
transactionToSend.setPurpose(Transaction.Purpose.RAISE_FEE);
final SendRequest sendRequest = SendRequest.forTx(transactionToSend);
sendRequest.aesKey = encryptionKey;
try {
wallet.signTransaction(sendRequest);
log.info("raise fee: cpfp {}", transactionToSend);
walletActivityViewModel.broadcastTransaction(transactionToSend);
state = State.DONE;
updateView();
dismiss();
} catch (final Wallet.BadWalletEncryptionKeyException x) {
badPasswordView.setVisibility(View.VISIBLE);
state = State.INPUT;
updateView();
passwordView.requestFocus();
log.info("raise fee: bad spending password");
}
}
use of org.bitcoinj.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsOfflineTask method sendCoinsOffline.
public final void sendCoinsOffline(final SendRequest sendRequest) {
backgroundHandler.post(() -> {
org.bitcoinj.core.Context.propagate(Constants.CONTEXT);
try {
log.info("sending: {}", sendRequest);
// can take long
final Transaction transaction = wallet.sendCoinsOffline(sendRequest);
log.info("send successful, transaction committed: {}", transaction.getTxId());
callbackHandler.post(() -> onSuccess(transaction));
} catch (final InsufficientMoneyException x) {
final Coin missing = x.missing;
if (missing != null)
log.info("send failed, {} missing", missing.toFriendlyString());
else
log.info("send failed, insufficient coins");
callbackHandler.post(() -> onInsufficientMoney(x.missing));
} catch (final ECKey.KeyIsEncryptedException x) {
log.info("send failed, key is encrypted: {}", x.getMessage());
callbackHandler.post(() -> onFailure(x));
} catch (final Wallet.BadWalletEncryptionKeyException x) {
log.info("send failed, bad spending password: {}", x.getMessage());
final boolean isEncrypted = wallet.isEncrypted();
callbackHandler.post(() -> {
if (isEncrypted)
onInvalidEncryptionKey();
else
onFailure(x);
});
} catch (final CouldNotAdjustDownwards x) {
log.info("send failed, could not adjust downwards: {}", x.getMessage());
callbackHandler.post(() -> onEmptyWalletFailed());
} catch (final CompletionException x) {
log.info("send failed, cannot complete: {}", x.getMessage());
callbackHandler.post(() -> onFailure(x));
}
});
}
use of org.bitcoinj.core.Transaction 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.core.Transaction in project bitcoin-wallet by bitcoin-wallet.
the class AcceptBluetoothService method onCreate.
@Override
public void onCreate() {
serviceCreatedAt = System.currentTimeMillis();
log.debug(".onCreate()");
super.onCreate();
this.application = (WalletApplication) getApplication();
final BluetoothAdapter bluetoothAdapter = checkNotNull(BluetoothAdapter.getDefaultAdapter());
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
wakeLock.acquire();
final NotificationCompat.Builder notification = new NotificationCompat.Builder(this, Constants.NOTIFICATION_CHANNEL_ID_ONGOING);
notification.setColor(getColor(R.color.fg_network_significant));
notification.setSmallIcon(R.drawable.stat_notify_bluetooth_24dp);
notification.setContentTitle(getString(R.string.notification_bluetooth_service_listening));
notification.setWhen(System.currentTimeMillis());
notification.setOngoing(true);
notification.setPriority(NotificationCompat.PRIORITY_LOW);
startForeground(Constants.NOTIFICATION_ID_BLUETOOTH, notification.build());
registerReceiver(bluetoothStateChangeReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
try {
classicThread = new AcceptBluetoothThread.ClassicBluetoothThread(bluetoothAdapter) {
@Override
public boolean handleTx(final Transaction tx) {
return AcceptBluetoothService.this.handleTx(tx);
}
};
paymentProtocolThread = new AcceptBluetoothThread.PaymentProtocolThread(bluetoothAdapter) {
@Override
public boolean handleTx(final Transaction tx) {
return AcceptBluetoothService.this.handleTx(tx);
}
};
} catch (final IOException x) {
new Toast(this).longToast(R.string.error_bluetooth, x.getMessage());
log.warn("problem with listening, stopping service", x);
CrashReporter.saveBackgroundTrace(x, application.packageInfo());
stopSelf();
}
wallet = new WalletLiveData(application);
wallet.observe(this, wallet -> {
classicThread.start();
paymentProtocolThread.start();
});
}
Aggregations