new LTC wallet API

This commit is contained in:
Radek Davidek 2025-05-16 13:48:45 +02:00
parent efe6daa1aa
commit 74c74744a9
2 changed files with 35 additions and 16 deletions

View File

@ -7,7 +7,6 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -109,14 +108,13 @@ public class MiningBean {
public void run() { public void run() {
try { try {
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) { if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
restRequest = getStringResponse("https://litecoinblockexplorer.net/address/".concat(ltcWallet)); restRequest = getStringResponse(
if (restRequest != null && restRequest.length() > 0 "https://api.blockcypher.com/v1/ltc/main/addrs/".concat(ltcWallet).concat("/balance"));
&& restRequest.contains("Final Balance</p><p class=\"title is-5\">")) { if (restRequest != null && restRequest.length() > 0) {
int index = restRequest.indexOf("Final Balance</p><p class=\"title is-5\">") JSONObject full = new JSONObject(restRequest);
+ "Final Balance</p><p class=\"title is-5\">".length(); String balance = (String) full.get("final_balance").toString();
String text = restRequest.substring(index, index + 11);
double res = Double.parseDouble(text); double res = Double.parseDouble(balance) / 100000000;
if (res > 0d) { if (res > 0d) {
resultStr = res + " LTC " + curSym + String.format("%.2f", (res * lastPrices[1])); resultStr = res + " LTC " + curSym + String.format("%.2f", (res * lastPrices[1]));
} else } else
@ -588,12 +586,12 @@ public class MiningBean {
return (days > 0 ? days + "d " : "") + (hours > 0 ? hours + "h " : "") + (mins > 0 ? mins + "m " : ""); 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, return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT, Constants.DEFAULT_HTTP_READ_TIMEOUT,
null); 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, return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT, Constants.DEFAULT_HTTP_READ_TIMEOUT,
headers); headers);
} }
@ -635,7 +633,7 @@ public class MiningBean {
return output; 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 = ""; String output = "";
try { try {
@ -666,11 +664,29 @@ public class MiningBean {
} }
public static void main(String[] args) { public static void main(String[] args) {
int a = 0; String ltcWallet = "LZV1HpXEWoR1MWRiXeZSbkrgPfWE3oSwgh";
a = a | 100; String restRequest = "";
a = a | 1; try {
a = a | 10; if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
System.out.println(a); 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());
}
} }
} }

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path: