fixed ripple wallet
This commit is contained in:
parent
f49d0b1dbd
commit
efe6daa1aa
@ -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;
|
||||
|
||||
@ -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</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://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);
|
||||
|
||||
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<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) {
|
||||
String output = "";
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user