Search in sources :

Example 1 with PaymentIntent

use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.

the class SendCoinsActivity method start.

public static void start(final Context context, final PaymentIntent paymentIntent, @Nullable final FeeCategory feeCategory, final int intentFlags) {
    final Intent intent = new Intent(context, SendCoinsActivity.class);
    intent.putExtra(INTENT_EXTRA_PAYMENT_INTENT, paymentIntent);
    if (feeCategory != null)
        intent.putExtra(INTENT_EXTRA_FEE_CATEGORY, feeCategory);
    if (intentFlags != 0)
        intent.setFlags(intentFlags);
    context.startActivity(intent);
}
Also used : PaymentIntent(de.schildbach.wallet.data.PaymentIntent) Intent(android.content.Intent)

Example 2 with PaymentIntent

use of de.schildbach.wallet.data.PaymentIntent 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 3 with PaymentIntent

use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.

the class SendCoinsFragment method onActivityResultResumed.

private void onActivityResultResumed(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) {
                    setState(null);
                    updateStateFrom(paymentIntent);
                }

                @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.button_scan, messageResId, messageArgs);
                }
            }.parse();
        }
    } else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST) {
        if (paymentIntent.isBluetoothPaymentRequestUrl())
            requestPaymentRequest();
    } else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH_FOR_DIRECT_PAYMENT) {
        if (paymentIntent.isBluetoothPaymentUrl())
            directPaymentEnableView.setChecked(resultCode == Activity.RESULT_OK);
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent)

Example 4 with PaymentIntent

use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.

the class InputParser method parseAndHandlePaymentRequest.

protected final void parseAndHandlePaymentRequest(final byte[] serializedPaymentRequest) throws PaymentProtocolException {
    final PaymentIntent paymentIntent = parsePaymentRequest(serializedPaymentRequest);
    handlePaymentIntent(paymentIntent);
}
Also used : PaymentIntent(de.schildbach.wallet.data.PaymentIntent)

Example 5 with PaymentIntent

use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.

the class InputParser method parsePaymentRequest.

public static PaymentIntent parsePaymentRequest(final byte[] serializedPaymentRequest) throws PaymentProtocolException {
    try {
        if (serializedPaymentRequest.length > 50000)
            throw new PaymentProtocolException("payment request too big: " + serializedPaymentRequest.length);
        final Protos.PaymentRequest paymentRequest = Protos.PaymentRequest.parseFrom(serializedPaymentRequest);
        final String pkiName;
        final String pkiCaName;
        if (!"none".equals(paymentRequest.getPkiType())) {
            final KeyStore keystore = new TrustStoreLoader.DefaultTrustStoreLoader().getKeyStore();
            final PkiVerificationData verificationData = PaymentProtocol.verifyPaymentRequestPki(paymentRequest, keystore);
            pkiName = verificationData.displayName;
            pkiCaName = verificationData.rootAuthorityName;
        } else {
            pkiName = null;
            pkiCaName = null;
        }
        final PaymentSession paymentSession = PaymentProtocol.parsePaymentRequest(paymentRequest);
        if (paymentSession.isExpired())
            throw new PaymentProtocolException.Expired("payment details expired: current time " + new Date() + " after expiry time " + paymentSession.getExpires());
        if (!paymentSession.getNetworkParameters().equals(Constants.NETWORK_PARAMETERS))
            throw new PaymentProtocolException.InvalidNetwork("cannot handle payment request network: " + paymentSession.getNetworkParameters());
        final ArrayList<PaymentIntent.Output> outputs = new ArrayList<PaymentIntent.Output>(1);
        for (final PaymentProtocol.Output output : paymentSession.getOutputs()) outputs.add(PaymentIntent.Output.valueOf(output));
        final String memo = paymentSession.getMemo();
        final String paymentUrl = paymentSession.getPaymentUrl();
        final byte[] merchantData = paymentSession.getMerchantData();
        final byte[] paymentRequestHash = Hashing.sha256().hashBytes(serializedPaymentRequest).asBytes();
        final PaymentIntent paymentIntent = new PaymentIntent(PaymentIntent.Standard.BIP70, pkiName, pkiCaName, outputs.toArray(new PaymentIntent.Output[0]), memo, paymentUrl, merchantData, null, paymentRequestHash);
        if (paymentIntent.hasPaymentUrl() && !paymentIntent.isSupportedPaymentUrl())
            throw new PaymentProtocolException.InvalidPaymentURL("cannot handle payment url: " + paymentIntent.paymentUrl);
        return paymentIntent;
    } catch (final InvalidProtocolBufferException x) {
        throw new PaymentProtocolException(x);
    } catch (final UninitializedMessageException x) {
        throw new PaymentProtocolException(x);
    } catch (final FileNotFoundException x) {
        throw new RuntimeException(x);
    } catch (final KeyStoreException x) {
        throw new RuntimeException(x);
    }
}
Also used : PaymentProtocol(org.bitcoinj.protocols.payments.PaymentProtocol) PkiVerificationData(org.bitcoinj.protocols.payments.PaymentProtocol.PkiVerificationData) TrustStoreLoader(org.bitcoinj.crypto.TrustStoreLoader) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) PaymentProtocolException(org.bitcoinj.protocols.payments.PaymentProtocolException) Protos(org.bitcoin.protocols.payments.Protos) UninitializedMessageException(com.google.protobuf.UninitializedMessageException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) PaymentSession(org.bitcoinj.protocols.payments.PaymentSession) Date(java.util.Date)

Aggregations

PaymentIntent (de.schildbach.wallet.data.PaymentIntent)15 StringInputParser (de.schildbach.wallet.ui.InputParser.StringInputParser)6 Transaction (org.bitcoinj.core.Transaction)6 VerificationException (org.bitcoinj.core.VerificationException)6 VersionedChecksummedBytes (org.bitcoinj.core.VersionedChecksummedBytes)4 DialogInterface (android.content.DialogInterface)3 Intent (android.content.Intent)2 DialogBuilder (de.schildbach.wallet.ui.DialogBuilder)2 FileNotFoundException (java.io.FileNotFoundException)2 OnClickListener (android.content.DialogInterface.OnClickListener)1 NdefMessage (android.nfc.NdefMessage)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 UninitializedMessageException (com.google.protobuf.UninitializedMessageException)1 WalletApplication (de.schildbach.wallet.WalletApplication)1 BinaryInputParser (de.schildbach.wallet.ui.InputParser.BinaryInputParser)1 StreamInputParser (de.schildbach.wallet.ui.InputParser.StreamInputParser)1 InputStream (java.io.InputStream)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 ArrayList (java.util.ArrayList)1