Exemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_view_address);

    Intent intent = getIntent();
    mAddress = intent.getExtras().getString("address");
    mAmount = intent.getExtras().getLong("amount");

    BigInteger amt = mAmount == 0 ? null : BigInteger.valueOf(mAmount);

    mURI = BitcoinURI.convertToBitcoinURI(mAddress, amt, null, null);

    mLogger.info("view address uri=" + mURI);

    final int size = (int) (240 * getResources().getDisplayMetrics().density);

    Bitmap bm = createBitmap(mURI, size);
    if (bm != null) {
      ImageView iv = (ImageView) findViewById(R.id.address_qr_view);
      iv.setImageBitmap(bm);
    }

    TextView idtv = (TextView) findViewById(R.id.address);
    idtv.setText(mAddress);

    updateAmount();

    mLogger.info("ViewAddressActivity created");
  }
Exemplo n.º 2
0
    @Override
    public void parse() {
      if (input.startsWith("bitcoin:")) {
        try {
          final BitcoinURI bitcoinUri = new BitcoinURI(null, input);
          final Address address = bitcoinUri.getAddress();
          final String addressLabel = bitcoinUri.getLabel();
          final BigInteger amount = bitcoinUri.getAmount();
          final String bluetoothMac =
              (String) bitcoinUri.getParameterByName(Bluetooth.MAC_URI_PARAM);

          bitcoinRequest(address, addressLabel, amount, bluetoothMac);
        } catch (final BitcoinURIParseException x) {
          error(R.string.input_parser_invalid_bitcoin_uri, input);
        }
      } else if (PATTERN_BITCOIN_ADDRESS.matcher(input).matches()) {
        try {
          final Address address = new Address(Constants.NETWORK_PARAMETERS, input);

          bitcoinRequest(address, null, null, null);
        } catch (final AddressFormatException x) {
          error(R.string.input_parser_invalid_address);
        }
      } else if (PATTERN_PRIVATE_KEY.matcher(input).matches()) {
        try {
          final ECKey key = new DumpedPrivateKey(Constants.NETWORK_PARAMETERS, input).getKey();
          final Address address = new Address(Constants.NETWORK_PARAMETERS, key.getPubKeyHash());

          bitcoinRequest(address, null, null, null);
        } catch (final AddressFormatException x) {
          error(R.string.input_parser_invalid_address);
        }
      } else if (PATTERN_TRANSACTION.matcher(input).matches()) {
        try {
          final Transaction tx =
              new Transaction(Constants.NETWORK_PARAMETERS, Qr.decodeBinary(input));

          directTransaction(tx);
        } catch (final IOException x) {
          error(R.string.input_parser_invalid_transaction, x.getMessage());
        } catch (final ProtocolException x) {
          error(R.string.input_parser_invalid_transaction, x.getMessage());
        }
      } else {
        cannotClassify(input);
      }
    }
  private String determineBitcoinRequestStr(final boolean includeBluetoothMac) {
    final ECKey key = (ECKey) addressView.getSelectedItem();
    final Address address = key.toAddress(Constants.NETWORK_PARAMETERS);
    final BigInteger amount = amountCalculatorLink.getAmount();

    final StringBuilder uri =
        new StringBuilder(BitcoinURI.convertToBitcoinURI(address, amount, null, null));
    if (includeBluetoothMac && bluetoothMac != null) {
      uri.append(amount == null ? '?' : '&');
      uri.append(Bluetooth.MAC_URI_PARAM).append('=').append(bluetoothMac);
    }
    return uri.toString();
  }
Exemplo n.º 4
0
 /**
  * Returns a future that will be notified with a PaymentSession object after it is fetched using
  * the provided uri. uri is a BIP-72-style BitcoinURI object that specifies where the {@link
  * Protos.PaymentRequest} object may be fetched in the r= parameter. If verifyPki is specified and
  * the payment request object specifies a PKI method, then the system trust store will be used to
  * verify the signature provided by the payment request. An exception is thrown by the future if
  * the signature cannot be verified. If trustStorePath is not null, the trust store used for PKI
  * verification will be loaded from the given location instead of using the system default trust
  * store location.
  */
 public static ListenableFuture<PaymentSession> createFromBitcoinUri(
     final BitcoinURI uri, final boolean verifyPki, @Nullable final String trustStorePath)
     throws PaymentRequestException {
   String url = uri.getPaymentRequestUrl();
   if (url == null)
     throw new PaymentRequestException.InvalidPaymentRequestURL(
         "No payment request URL (r= parameter) in BitcoinURI " + uri);
   try {
     return fetchPaymentRequest(new URI(url), verifyPki, trustStorePath);
   } catch (URISyntaxException e) {
     throw new PaymentRequestException.InvalidPaymentRequestURL(e);
   }
 }
  @Override
  public boolean onContextItemSelected(final MenuItem item) {
    try {
      final AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();

      final Map<String, Object> map =
          (Map<String, Object>) getListView().getAdapter().getItem(menuInfo.position);

      final String address = (String) map.get("addr");

      switch (item.getItemId()) {
        case R.id.wallet_addresses_context_archive:
          {
            MyRemoteWallet remoteWallet = application.getRemoteWallet();

            if (remoteWallet == null) return true;

            remoteWallet.setTag(address, 2);

            application.saveWallet(
                new SuccessCallback() {
                  @Override
                  public void onSuccess() {
                    EventListeners.invokeWalletDidChange();
                  }

                  @Override
                  public void onFail() {}
                });
            return true;
          }
        case R.id.wallet_addresses_context_edit:
          {
            EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString());
            return true;
          }

        case R.id.wallet_addresses_context_show_qr:
          {
            final String uri = BitcoinURI.convertToBitcoinURI(address, null, null, null);
            final int size = (int) (256 * getResources().getDisplayMetrics().density);
            new QrDialog(activity, WalletUtils.getQRCodeBitmap(uri, size)).show();
            return true;
          }

        case R.id.wallet_addresses_context_copy_to_clipboard:
          {
            AbstractWalletActivity.handleCopyToClipboard(activity, address.toString());
            return true;
          }

        case R.id.wallet_addresses_context_default:
          {
            handleDefault(address);
            return true;
          }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return false;
  }
Exemplo n.º 6
0
  @Override
  public void loadForm() {
    // get the current address, label and amount from the model
    String address =
        this.bitcoinController.getModel().getActiveWalletPreference(BitcoinModel.SEND_ADDRESS);
    String label =
        this.bitcoinController.getModel().getActiveWalletPreference(BitcoinModel.SEND_LABEL);
    String amountNotLocalised =
        this.bitcoinController.getModel().getActiveWalletPreference(BitcoinModel.SEND_AMOUNT);

    if (amountBTCTextField != null) {
      CurrencyConverterResult converterResult =
          CurrencyConverter.INSTANCE.parseToBTCNotLocalised(amountNotLocalised);

      if (converterResult.isBtcMoneyValid()) {
        parsedAmountBTC = converterResult.getBtcMoney();
        String amountLocalised =
            CurrencyConverter.INSTANCE.getBTCAsLocalisedString(converterResult.getBtcMoney());
        amountBTCTextField.setText(amountLocalised);
        if (notificationLabel != null) {
          notificationLabel.setText("");
        }
      } else {
        parsedAmountBTC = null;
        amountBTCTextField.setText("");
        if (notificationLabel != null) {
          notificationLabel.setText(converterResult.getBtcMessage());
        }
      }
    }

    if (address != null) {
      addressTextField.setText(address);
    } else {
      addressTextField.setText("");
    }
    if (label != null) {
      labelTextArea.setText(label);
    } else {
      labelTextArea.setText("");
    }

    // if there is a pending 'handleopenURI' that needs pasting into the
    // send form, do it
    String performPasteNow =
        this.bitcoinController
            .getModel()
            .getActiveWalletPreference(BitcoinModel.SEND_PERFORM_PASTE_NOW);
    if (Boolean.TRUE.toString().equalsIgnoreCase(performPasteNow)) {
      try {
        Address decodeAddress =
            new Address(this.bitcoinController.getModel().getNetworkParameters(), address);
        processDecodedString(
            com.google.bitcoin.uri.BitcoinURI.convertToBitcoinURI(
                decodeAddress, Utils.toNanoCoins(amountNotLocalised), label, null),
            null);
        this.bitcoinController
            .getModel()
            .setActiveWalletPreference(BitcoinModel.SEND_PERFORM_PASTE_NOW, "false");
        sendButton.requestFocusInWindow();

        mainFrame.bringToFront();
      } catch (AddressFormatException e) {
        throw new RuntimeException(e);
      }
    }
  }
Exemplo n.º 7
0
    @Override
    public void parse() {
      if (input.startsWith("MINTCOIN:-")) {
        try {
          final byte[] serializedPaymentRequest = Qr.decodeBinary(input.substring(9));

          parseAndHandlePaymentRequest(serializedPaymentRequest);
        } catch (final IOException x) {
          log.info("i/o error while fetching payment request", x);

          error(R.string.input_parser_io_error, x.getMessage());
        } catch (final PkiVerificationException x) {
          log.info("got unverifyable payment request", x);

          error(R.string.input_parser_unverifyable_paymentrequest, x.getMessage());
        } catch (final PaymentRequestException x) {
          log.info("got invalid payment request", x);

          error(R.string.input_parser_invalid_paymentrequest, x.getMessage());
        }
      }
      if (input.startsWith("mintcoin:")) {
        try {
          final BitcoinURI bitcoinUri = new BitcoinURI(null, input);

          final Address address = bitcoinUri.getAddress();
          if (address == null) throw new BitcoinURIParseException("missing address");

          if (address.getParameters().equals(Constants.NETWORK_PARAMETERS))
            handlePaymentIntent(PaymentIntent.fromBitcoinUri(bitcoinUri));
          else error(R.string.input_parser_invalid_address, input);
        } catch (final BitcoinURIParseException x) {
          log.info("got invalid mintcoin uri: '" + input + "'", x);

          error(R.string.input_parser_invalid_bitcoin_uri, input);
        }
      } else if (PATTERN_BITCOIN_ADDRESS.matcher(input).matches()) {
        try {
          final Address address = new Address(Constants.NETWORK_PARAMETERS, input);

          handlePaymentIntent(PaymentIntent.fromAddress(address, null));
        } catch (final AddressFormatException x) {
          log.info("got invalid address", x);

          error(R.string.input_parser_invalid_address);
        }
      } else if (PATTERN_PRIVATE_KEY.matcher(input).matches()) {
        try {
          final ECKey key = new DumpedPrivateKey(Constants.NETWORK_PARAMETERS, input).getKey();
          final Address address = new Address(Constants.NETWORK_PARAMETERS, key.getPubKeyHash());

          handlePaymentIntent(PaymentIntent.fromAddress(address, null));
        } catch (final AddressFormatException x) {
          log.info("got invalid address", x);

          error(R.string.input_parser_invalid_address);
        }
      } else if (PATTERN_TRANSACTION.matcher(input).matches()) {
        try {
          final Transaction tx =
              new Transaction(Constants.NETWORK_PARAMETERS, Qr.decodeDecompressBinary(input));

          handleDirectTransaction(tx);
        } catch (final IOException x) {
          log.info("i/o error while fetching transaction", x);

          error(R.string.input_parser_invalid_transaction, x.getMessage());
        } catch (final ProtocolException x) {
          log.info("got invalid transaction", x);

          error(R.string.input_parser_invalid_transaction, x.getMessage());
        }
      } else {
        cannotClassify(input);
      }
    }