From efe6daa1aa479a5547090685e9f797d5c60b3177 Mon Sep 17 00:00:00 2001
From: Radek Davidek
Date: Sat, 23 Nov 2024 17:42:14 +0100
Subject: [PATCH] fixed ripple wallet
---
src/main/java/cz/kamma/mining/Constants.java | 4 +-
.../java/cz/kamma/mining/bean/MiningBean.java | 69 +++++++++++++++----
2 files changed, 59 insertions(+), 14 deletions(-)
diff --git a/src/main/java/cz/kamma/mining/Constants.java b/src/main/java/cz/kamma/mining/Constants.java
index aaa7e68..2f42898 100644
--- a/src/main/java/cz/kamma/mining/Constants.java
+++ b/src/main/java/cz/kamma/mining/Constants.java
@@ -2,8 +2,8 @@ package cz.kamma.mining;
public interface Constants {
- public static final String APP_VERSION = "v0.9";
- public static final String COPYRIGHT = "2021";
+ public static final String APP_VERSION = "v0.9.1";
+ public static final String COPYRIGHT = "2024";
public static final int DEFAULT_HTTP_CONNECTION_TIMEOUT = 6000;
public static final int DEFAULT_HTTP_READ_TIMEOUT = 18000;
public static final int RELOAD_TIME = 25000;
diff --git a/src/main/java/cz/kamma/mining/bean/MiningBean.java b/src/main/java/cz/kamma/mining/bean/MiningBean.java
index b390d1f..413fa55 100644
--- a/src/main/java/cz/kamma/mining/bean/MiningBean.java
+++ b/src/main/java/cz/kamma/mining/bean/MiningBean.java
@@ -2,6 +2,7 @@ package cz.kamma.mining.bean;
import java.io.BufferedReader;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
@@ -84,8 +85,8 @@ public class MiningBean {
lastPrices[pos] = price;
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
resultStr = "Unknown";
KeyValue wi = new KeyValue();
@@ -108,12 +109,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
")) {
- int index = restRequest.indexOf("Final Balance
")+"Final Balance
".length();
- String text = restRequest.substring(index, index+11);
-
+ restRequest = getStringResponse("https://litecoinblockexplorer.net/address/".concat(ltcWallet));
+ if (restRequest != null && restRequest.length() > 0
+ && restRequest.contains("Final Balance
")) {
+ int index = restRequest.indexOf("Final Balance
")
+ + "Final Balance
".length();
+ String text = restRequest.substring(index, index + 11);
+
double res = Double.parseDouble(text);
if (res > 0d) {
resultStr = res + " LTC " + curSym + String.format("%.2f", (res * lastPrices[1]));
@@ -138,13 +140,19 @@ public class MiningBean {
public void run() {
try {
if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) {
- restRequest = getStringResponse(
- "https://data.ripple.com/v2/accounts/".concat(xrpWallet).concat("/balances"));
+ String request = "{\r\n" + " \"method\": \"account_info\",\r\n" + " \"params\": [\r\n"
+ + " {\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) {
JSONObject full = new JSONObject(restRequest);
- JSONArray balances = (JSONArray) full.get("balances");
- double res = balances.getJSONObject(0).getDouble("value");
+ String balance = (String) full.getJSONObject("result").getJSONObject("account_data")
+ .get("Balance");
+ double res = Double.valueOf(balance.toString());
if (res > 0d) {
+ res = res / 1000000;
resultStr = res + " XRP " + curSym + String.format("%.2f", (res * lastPrices[2]));
} else
resultStr = "Unknown";
@@ -590,6 +598,43 @@ public class MiningBean {
headers);
}
+ public String makeRequest(String urlStr, String method, int timeout, int readTimeout, Map 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 headers) {
String output = "";