use of org.bitcoinj.wallet.SendRequest in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method signAndSendPayment.
private void signAndSendPayment(final KeyParameter encryptionKey) {
setState(State.SIGNING);
// final payment intent
final PaymentIntent finalPaymentIntent = paymentIntent.mergeWithEditedValues(amountCalculatorLink.getAmount(), validatedAddress != null ? validatedAddress.address : null);
final Coin finalAmount = finalPaymentIntent.getAmount();
// prepare send request
final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
sendRequest.emptyWallet = paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE));
sendRequest.feePerKb = fees.get(feeCategory);
sendRequest.memo = paymentIntent.memo;
sendRequest.exchangeRate = amountCalculatorLink.getExchangeRate();
sendRequest.aesKey = encryptionKey;
final Coin fee = dryrunTransaction.getFee();
if (fee.isGreaterThan(finalAmount)) {
setState(State.INPUT);
final MonetaryFormat btcFormat = config.getFormat();
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_significant_fee_title);
dialog.setMessage(getString(R.string.send_coins_fragment_significant_fee_message, btcFormat.format(fee), btcFormat.format(finalAmount)));
dialog.setPositiveButton(R.string.send_coins_fragment_button_send, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
sendPayment(sendRequest, finalAmount);
}
});
dialog.setNegativeButton(R.string.button_cancel, null);
dialog.show();
} else {
sendPayment(sendRequest, finalAmount);
}
}
use of org.bitcoinj.wallet.SendRequest in project bitcoin-wallet by bitcoin-wallet.
the class RaiseFeeDialogFragment method doRaiseFee.
private void doRaiseFee(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);
wallet.commitTx(transactionToSend);
BlockchainService.broadcastTransaction(activity, transactionToSend);
state = State.DONE;
updateView();
dismiss();
} catch (final KeyCrypterException x) {
badPasswordView.setVisibility(View.VISIBLE);
state = State.INPUT;
updateView();
passwordView.requestFocus();
log.info("raise fee: bad spending password");
}
}
use of org.bitcoinj.wallet.SendRequest in project bitcoin-wallet by bitcoin-wallet.
the class SweepWalletFragment method handleSweep.
private void handleSweep() {
setState(State.PREPARATION);
final SendRequest sendRequest = SendRequest.emptyWallet(application.getWallet().freshReceiveAddress());
sendRequest.feePerKb = fees.get(FeeCategory.NORMAL);
new SendCoinsOfflineTask(walletToSweep, backgroundHandler) {
@Override
protected void onSuccess(final Transaction transaction) {
sentTransaction = transaction;
setState(State.SENDING);
sentTransaction.getConfidence().addEventListener(sentTransactionConfidenceListener);
application.processDirectTransaction(sentTransaction);
}
@Override
protected void onInsufficientMoney(@Nullable final Coin missing) {
setState(State.FAILED);
showInsufficientMoneyDialog();
}
@Override
protected void onEmptyWalletFailed() {
setState(State.FAILED);
showInsufficientMoneyDialog();
}
@Override
protected void onFailure(final Exception exception) {
setState(State.FAILED);
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_error_msg);
dialog.setMessage(exception.toString());
dialog.setNeutralButton(R.string.button_dismiss, null);
dialog.show();
}
@Override
protected void onInvalidEncryptionKey() {
// cannot happen
throw new RuntimeException();
}
private void showInsufficientMoneyDialog() {
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.sweep_wallet_fragment_insufficient_money_title);
dialog.setMessage(R.string.sweep_wallet_fragment_insufficient_money_msg);
dialog.setNeutralButton(R.string.button_dismiss, null);
dialog.show();
}
}.sendCoinsOffline(// send asynchronously
sendRequest);
}
Aggregations