Ejemplo n.º 1
0
  @Override
  public void createAddress(String label) throws Exception {
    networkDAO = new NetworkDAO();

    try {
      String apiKey = "d33a-68b8-59d4-ed27";
      // was not instantiated in this method. Will raise NullPointer. I will make it class level
      networkDAO.send(
          "https://block.io/api/v2/get_new_address/?api_key=" + apiKey + "&label=" + label);
    } catch (Exception e) {

      Log.e("ERROR:", e.getMessage());
      throw new NetworkErrorException(e);
    }
  }
Ejemplo n.º 2
0
  @Override
  public BigDecimal getBitcoinPrice() throws Exception {
    // URI that returns price
    // *******Pull api keys from database*******
    String apiKey = "3bb2-81fc-a60a-3e7c";
    String uriAddress =
        "https://block.io/api/v2/get_current_price/?api_key=" + apiKey + "&price_base=USD";

    String data = "";

    try {
      // Parse data and store balance in BigDecimal
      data = networkDAO.fetch(uriAddress);
      String lines[] = data.split("\\r?\\n");
      return new BigDecimal(lines[18].substring(19, 25));
    } catch (IndexOutOfBoundsException e) {
      Log.e("ERROR: ", "getBitcoinPrice()" + e);
      return new BigDecimal(0.0);
    }
  }
Ejemplo n.º 3
0
  @Override
  public String getAddress(String label) throws Exception {
    // URI that returns address
    // *******Pull api keys from database*******
    String apiKey = "d33a-68b8-59d4-ed27";
    String uriAddress =
        "https://block.io/api/v2/get_address_by_label/?api_key=" + apiKey + "&label=" + label;

    String data = "";
    try {
      // Fetch address data from block.io
      data = networkDAO.fetch(uriAddress);
    } catch (Exception e) {
      Log.e("ERROR:", "No network connection.");
      throw new NetworkErrorException(e);
    }

    // Parse data and store balance in BigDecimal
    String lines[] = data.split("\\r?\\n");
    String address = lines[5].substring(17, 52);
    return address;
  }
Ejemplo n.º 4
0
  @Override
  public BigDecimal getBitcoinBalance(String label) throws Exception {
    // URI that returns balance
    // *******Pull api keys from database*******
    String apiKey = "d33a-68b8-59d4-ed27";
    String uriAddress =
        "https://block.io/api/v2/get_address_balance/?api_key=" + apiKey + "&labels=" + label;

    String data = "";
    try {
      // Fetch address data from block.io
      data = networkDAO.fetch(uriAddress);
    } catch (Exception e) {
      Log.e("ERROR: ", "No network connection.");
      throw new NetworkErrorException("No network connection");
    }

    // Parse data and store balance in BigDecimal
    String lines[] = data.split("\\r?\\n");
    BigDecimal balance = new BigDecimal(lines[11].substring(31, 41));

    return balance;
  }
Ejemplo n.º 5
0
  // **************THIS METHOD IS BROKEN**************8
  @Override
  public double getNetworkFee(double amount, String to) throws Exception {
    networkDAO = new NetworkDAO();

    // URI that returns estimated network fee
    // *******Pull api keys from database*******
    String apiKey = "d33a-68b8-59d4-ed27";
    String uriAddress =
        "https://block.io/api/v2/get_network_fee_estimate/?api_key="
            + apiKey
            + "&amounts="
            + amount
            + "&to_addresses="
            + to;

    String data = "";
    double fee = 0.00001;
    try {
      // Fetch address data from block.io
      data = networkDAO.fetch(uriAddress);

      // Parse data and store balance in BigDecimal
      String lines[] = data.split("\\r?\\n");
      try {
        String feeString = lines[4].substring(31, 41);
        fee = Double.parseDouble(feeString);
        return fee;
      } catch (IndexOutOfBoundsException e) {
        Log.e("ERROR: ", "getBitcoinPrice()" + e);
      }
    } catch (HttpResponseException e) {
      Log.i("ERROR: ", "Not enough funds; AddressDAO");
      throw new NetworkErrorException("Insufficient funds.");
    }
    return fee;
  }
Ejemplo n.º 6
0
  @Override
  public void send(double amount, String fromLabel, String to, String pin) throws Exception {

    // *******Get "to" address from camera QR code scan*******
    // *******Pull api keys from database*******
    String apiKey = "d33a-68b8-59d4-ed27";
    String uriAddress =
        "https://block.io/api/v2/withdraw_from_labels/?api_key="
            + apiKey
            + "&from_labels="
            + fromLabel
            + "&to_addresses="
            + to
            + "&amounts="
            + amount
            + "&pin="
            + pin;

    try {
      networkDAO.send(uriAddress);
    } catch (NetworkErrorException e) {
      Log.e("ERROR: ", "No network connection.");
    }
  }