new LTC wallet API
This commit is contained in:
parent
efe6daa1aa
commit
74c74744a9
@ -7,7 +7,6 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@ -109,14 +108,13 @@ public class MiningBean {
|
||||
public void run() {
|
||||
try {
|
||||
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
|
||||
restRequest = getStringResponse("https://litecoinblockexplorer.net/address/".concat(ltcWallet));
|
||||
if (restRequest != null && restRequest.length() > 0
|
||||
&& restRequest.contains("Final Balance</p><p class=\"title is-5\">")) {
|
||||
int index = restRequest.indexOf("Final Balance</p><p class=\"title is-5\">")
|
||||
+ "Final Balance</p><p class=\"title is-5\">".length();
|
||||
String text = restRequest.substring(index, index + 11);
|
||||
restRequest = getStringResponse(
|
||||
"https://api.blockcypher.com/v1/ltc/main/addrs/".concat(ltcWallet).concat("/balance"));
|
||||
if (restRequest != null && restRequest.length() > 0) {
|
||||
JSONObject full = new JSONObject(restRequest);
|
||||
String balance = (String) full.get("final_balance").toString();
|
||||
|
||||
double res = Double.parseDouble(text);
|
||||
double res = Double.parseDouble(balance) / 100000000;
|
||||
if (res > 0d) {
|
||||
resultStr = res + " LTC " + curSym + String.format("%.2f", (res * lastPrices[1]));
|
||||
} else
|
||||
@ -588,12 +586,12 @@ public class MiningBean {
|
||||
return (days > 0 ? days + "d " : "") + (hours > 0 ? hours + "h " : "") + (mins > 0 ? mins + "m " : "");
|
||||
}
|
||||
|
||||
public String getStringResponse(String urlStr) {
|
||||
public static String getStringResponse(String urlStr) {
|
||||
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT, Constants.DEFAULT_HTTP_READ_TIMEOUT,
|
||||
null);
|
||||
}
|
||||
|
||||
public String getStringResponse(String urlStr, Map<String, String> headers) {
|
||||
public static String getStringResponse(String urlStr, Map<String, String> headers) {
|
||||
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT, Constants.DEFAULT_HTTP_READ_TIMEOUT,
|
||||
headers);
|
||||
}
|
||||
@ -635,7 +633,7 @@ public class MiningBean {
|
||||
return output;
|
||||
}
|
||||
|
||||
public String getStringResponse(String urlStr, int timeout, int readTimeout, Map<String, String> headers) {
|
||||
public static String getStringResponse(String urlStr, int timeout, int readTimeout, Map<String, String> headers) {
|
||||
String output = "";
|
||||
|
||||
try {
|
||||
@ -666,11 +664,29 @@ public class MiningBean {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int a = 0;
|
||||
a = a | 100;
|
||||
a = a | 1;
|
||||
a = a | 10;
|
||||
System.out.println(a);
|
||||
String ltcWallet = "LZV1HpXEWoR1MWRiXeZSbkrgPfWE3oSwgh";
|
||||
String restRequest = "";
|
||||
try {
|
||||
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
|
||||
restRequest = getStringResponse(
|
||||
"https://api.blockcypher.com/v1/ltc/main/addrs/".concat(ltcWallet).concat("/balance"));
|
||||
if (restRequest != null && restRequest.length() > 0) {
|
||||
JSONObject full = new JSONObject(restRequest);
|
||||
String balance = (String) full.get("final_balance").toString();
|
||||
|
||||
double res = Double.parseDouble(balance) / 100000000;
|
||||
String curSym = "$";
|
||||
String resultStr = "";
|
||||
if (res > 0d) {
|
||||
resultStr = res + " LTC " + curSym;
|
||||
} else
|
||||
resultStr = "Unknown";
|
||||
System.out.println(resultStr);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
3
src/main/webapp/META-INF/MANIFEST.MF
Normal file
3
src/main/webapp/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user