Exemplo n.º 1
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);
    }
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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;
  }