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);
}
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);
}
}
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);
}
}
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);
}
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);
}
}
Aggregations