Search in sources :

Example 1 with SendRequest

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);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) SendRequest(org.bitcoinj.wallet.SendRequest) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) DialogInterface(android.content.DialogInterface) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder)

Example 2 with SendRequest

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");
    }
}
Also used : TransactionOutput(org.bitcoinj.core.TransactionOutput) SendRequest(org.bitcoinj.wallet.SendRequest) Transaction(org.bitcoinj.core.Transaction) KeyCrypterException(org.bitcoinj.crypto.KeyCrypterException)

Example 3 with SendRequest

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);
}
Also used : Coin(org.bitcoinj.core.Coin) SendRequest(org.bitcoinj.wallet.SendRequest) Transaction(org.bitcoinj.core.Transaction) WalletTransaction(org.bitcoinj.wallet.WalletTransaction) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) VerificationException(org.bitcoinj.core.VerificationException)

Aggregations

SendRequest (org.bitcoinj.wallet.SendRequest)3 DialogBuilder (de.schildbach.wallet.ui.DialogBuilder)2 Coin (org.bitcoinj.core.Coin)2 Transaction (org.bitcoinj.core.Transaction)2 DialogInterface (android.content.DialogInterface)1 PaymentIntent (de.schildbach.wallet.data.PaymentIntent)1 TransactionOutput (org.bitcoinj.core.TransactionOutput)1 VerificationException (org.bitcoinj.core.VerificationException)1 KeyCrypterException (org.bitcoinj.crypto.KeyCrypterException)1 MonetaryFormat (org.bitcoinj.utils.MonetaryFormat)1 WalletTransaction (org.bitcoinj.wallet.WalletTransaction)1