fixed ripple wallet

This commit is contained in:
Radek Davidek 2024-11-23 17:42:14 +01:00
parent f49d0b1dbd
commit efe6daa1aa
2 changed files with 59 additions and 14 deletions

View File

@ -2,8 +2,8 @@ package cz.kamma.mining;
public interface Constants { public interface Constants {
public static final String APP_VERSION = "v0.9"; public static final String APP_VERSION = "v0.9.1";
public static final String COPYRIGHT = "2021"; public static final String COPYRIGHT = "2024";
public static final int DEFAULT_HTTP_CONNECTION_TIMEOUT = 6000; public static final int DEFAULT_HTTP_CONNECTION_TIMEOUT = 6000;
public static final int DEFAULT_HTTP_READ_TIMEOUT = 18000; public static final int DEFAULT_HTTP_READ_TIMEOUT = 18000;
public static final int RELOAD_TIME = 25000; public static final int RELOAD_TIME = 25000;

View File

@ -2,6 +2,7 @@ package cz.kamma.mining.bean;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -84,8 +85,8 @@ public class MiningBean {
lastPrices[pos] = price; lastPrices[pos] = price;
if (price > 0d) if (price > 0d)
resultStr = curSym + String.format("%."+roundPrices[pos]+"f", (price)) + " (" + String.format("%.2f", (change)) resultStr = curSym + String.format("%." + roundPrices[pos] + "f", (price)) + " ("
+ "%)"; + String.format("%.2f", (change)) + "%)";
else else
resultStr = "Unknown"; resultStr = "Unknown";
KeyValue wi = new KeyValue(); KeyValue wi = new KeyValue();
@ -108,12 +109,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( restRequest = getStringResponse("https://litecoinblockexplorer.net/address/".concat(ltcWallet));
"https://litecoinblockexplorer.net/address/".concat(ltcWallet)); if (restRequest != null && restRequest.length() > 0
if (restRequest != null && restRequest.length() > 0 && restRequest.contains("Final Balance</p><p class=\"title is-5\">")) { && 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(); int index = restRequest.indexOf("Final Balance</p><p class=\"title is-5\">")
String text = restRequest.substring(index, index+11); + "Final Balance</p><p class=\"title is-5\">".length();
String text = restRequest.substring(index, index + 11);
double res = Double.parseDouble(text); double res = Double.parseDouble(text);
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]));
@ -138,13 +140,19 @@ public class MiningBean {
public void run() { public void run() {
try { try {
if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) { if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) {
restRequest = getStringResponse( String request = "{\r\n" + " \"method\": \"account_info\",\r\n" + " \"params\": [\r\n"
"https://data.ripple.com/v2/accounts/".concat(xrpWallet).concat("/balances")); + " {\r\n" + " \"account\": \"" + xrpWallet + "\",\r\n"
+ " \"ledger_index\": \"current\",\r\n" + " \"queue\": true\r\n"
+ " }\r\n" + " ]\r\n" + "}";
restRequest = makeRequest("http://s1.ripple.com:51234", "POST", 5000, 5000, null,
request.getBytes());
if (restRequest != null && restRequest.length() > 0) { if (restRequest != null && restRequest.length() > 0) {
JSONObject full = new JSONObject(restRequest); JSONObject full = new JSONObject(restRequest);
JSONArray balances = (JSONArray) full.get("balances"); String balance = (String) full.getJSONObject("result").getJSONObject("account_data")
double res = balances.getJSONObject(0).getDouble("value"); .get("Balance");
double res = Double.valueOf(balance.toString());
if (res > 0d) { if (res > 0d) {
res = res / 1000000;
resultStr = res + " XRP " + curSym + String.format("%.2f", (res * lastPrices[2])); resultStr = res + " XRP " + curSym + String.format("%.2f", (res * lastPrices[2]));
} else } else
resultStr = "Unknown"; resultStr = "Unknown";
@ -590,6 +598,43 @@ public class MiningBean {
headers); headers);
} }
public String makeRequest(String urlStr, String method, int timeout, int readTimeout, Map<String, String> headers,
byte[] data) {
String output = "";
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setConnectTimeout(timeout);
conn.setReadTimeout(readTimeout);
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36");
if (headers != null && !headers.isEmpty()) {
for (String key : headers.keySet()) {
conn.setRequestProperty(key, headers.get(key));
}
}
conn.setRequestMethod(method);
conn.connect();
OutputStream out = conn.getOutputStream();
out.write(data);
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
output += inputLine;
in.close();
conn.disconnect();
} catch (Exception e) {
System.out.println("Error while getting HTTP response from " + urlStr + ". Ex:" + e);
}
return output;
}
public String getStringResponse(String urlStr, int timeout, int readTimeout, Map<String, String> headers) { public String getStringResponse(String urlStr, int timeout, int readTimeout, Map<String, String> headers) {
String output = ""; String output = "";