refactor, new data loading

This commit is contained in:
rdavidek 2021-06-08 17:18:13 +02:00
parent 18a584f6d8
commit 05425c0d04
3 changed files with 430 additions and 389 deletions

View File

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

View File

@ -1,5 +1,9 @@
package cz.kamma.mining.bean; package cz.kamma.mining.bean;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -13,7 +17,6 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import cz.kamma.mining.Constants; import cz.kamma.mining.Constants;
import cz.kamma.mining.helper.HttpHelper;
import cz.kamma.mining.vo.KeyValue; import cz.kamma.mining.vo.KeyValue;
public class MiningBean { public class MiningBean {
@ -27,6 +30,7 @@ public class MiningBean {
String currency; String currency;
String resultStr; String resultStr;
String restRequest; String restRequest;
int finished = 0;
public String updateAll(HttpServletRequest request, HttpServletResponse response) throws Exception { public String updateAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
@ -58,8 +62,7 @@ public class MiningBean {
for (int i = 0; i < cryptoCur.length; i++) { for (int i = 0; i < cryptoCur.length; i++) {
String ccur = cryptoCur[i]; String ccur = cryptoCur[i];
restRequest = HttpHelper restRequest = getStringResponse("https://www.bitstamp.net/api/v2/ticker/".concat(ccur).concat(currency));
.getStringResponse("https://www.bitstamp.net/api/v2/ticker/".concat(ccur).concat(currency));
if (restRequest != null && restRequest.length() > 0) { if (restRequest != null && restRequest.length() > 0) {
JSONObject tmp = new JSONObject(restRequest); JSONObject tmp = new JSONObject(restRequest);
double res = tmp.getDouble("last"); double res = tmp.getDouble("last");
@ -79,211 +82,232 @@ public class MiningBean {
@Override @Override
public void run() { public void run() {
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) { try {
restRequest = HttpHelper if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
.getStringResponse("https://chain.so/api/v2/get_address_balance/LTC/".concat(ltcWallet)); restRequest = getStringResponse(
if (restRequest != null && restRequest.length() > 0) { "https://chain.so/api/v2/get_address_balance/LTC/".concat(ltcWallet));
JSONObject full = new JSONObject(restRequest); if (restRequest != null && restRequest.length() > 0) {
JSONObject data = (JSONObject) full.get("data"); JSONObject full = new JSONObject(restRequest);
String confirmedBalance = (String) data.get("confirmed_balance"); JSONObject data = (JSONObject) full.get("data");
String confirmedBalance = (String) data.get("confirmed_balance");
double res = Double.parseDouble(confirmedBalance); double res = Double.parseDouble(confirmedBalance);
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
resultStr = "Unknown"; resultStr = "Unknown";
KeyValue wi = new KeyValue(); KeyValue wi = new KeyValue();
wi.setKey("My Balance LTC"); wi.setKey("My Balance LTC");
wi.setValue(resultStr); wi.setValue(resultStr);
prices.add(wi); prices.add(wi);
}
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) {
restRequest = HttpHelper.getStringResponse(
"https://data.ripple.com/v2/accounts/".concat(xrpWallet).concat("/balances"));
if (restRequest != null && restRequest.length() > 0) {
JSONObject full = new JSONObject(restRequest);
JSONArray balances = (JSONArray) full.get("balances");
double res = balances.getJSONObject(0).getDouble("value");
if (res > 0d) {
resultStr = res + " XRP " + curSym + String.format("%.2f", (res * lastPrices[2]));
} else
resultStr = "Unknown";
KeyValue wi = new KeyValue();
wi.setKey("My Balance XRP");
wi.setValue(resultStr);
prices.add(wi);
}
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
if (ethWallet != null && !"null".equals(ethWallet) && ethWallet.length() > 0) {
restRequest = HttpHelper
.getStringResponse("https://api.etherscan.io/api?module=account&action=balance&address="
+ ethWallet + "&tag=latest&apikey=N54NVXSVSISMQ4QIM2JVKJW56KHCKMU5T4");
if (restRequest != null && restRequest.length() > 0) {
JSONObject full = new JSONObject(restRequest);
String confirmedBalance = (String) full.get("result");
double res = Double.parseDouble(confirmedBalance);
res = res * 0.000000000000000001;
if (res > 0d) {
resultStr = res + " ETH " + curSym + String.format("%.2f", (res * lastPrices[3]));
} else
resultStr = "Unknown";
KeyValue wi = new KeyValue();
wi.setKey("My Balance ETH");
wi.setValue(resultStr);
prices.add(wi);
}
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
if (ltcapikey != null && !"null".equals(ltcapikey) && ltcapikey.length() > 0) {
String miningJson = HttpHelper
.getStringResponse("https://www.litecoinpool.org/api?api_key=".concat(ltcapikey));
if (miningJson != null && miningJson.length() > 0) {
JSONObject full = new JSONObject(miningJson);
JSONObject user = (JSONObject) full.get("user");
KeyValue wi = new KeyValue();
wi.setKey("HashRate");
if (user.getInt("hash_rate") > 0)
wi.setValue((user.getInt("hash_rate") / 1000) + " MH/s");
else
wi.setValue("Unknown");
workers.add(wi);
JSONObject workersJson = (JSONObject) full.get("workers");
for (Iterator<String> keys = workersJson.keys(); keys.hasNext();) {
String key = keys.next();
JSONObject worker = (JSONObject) workersJson.get(key);
wi = new KeyValue();
wi.setKey("HashRate " + key);
wi.setValue((worker.getInt("hash_rate") / 1000) + " MH/s");
workers.add(wi);
} }
wi = new KeyValue();
wi.setKey("Paid");
if (user.getDouble("paid_rewards") > 0)
wi.setValue(user.getDouble("paid_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("paid_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Unpaid");
if (user.getDouble("unpaid_rewards") > 0)
wi.setValue(user.getDouble("unpaid_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("unpaid_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Total");
if (user.getDouble("total_rewards") > 0)
wi.setValue(user.getDouble("total_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("total_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Expected 24h");
if (user.getDouble("expected_24h_rewards") > 0)
wi.setValue(user.getDouble("expected_24h_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("expected_24h_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Past 24h");
if (user.getDouble("past_24h_rewards") > 0)
wi.setValue(user.getDouble("past_24h_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("past_24h_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
JSONObject net = (JSONObject) full.get("network");
wi = new KeyValue();
wi.setKey("Network HashRate");
if (net.getLong("hash_rate") > 0)
wi.setValue((net.getLong("hash_rate") / 1000000) + " GH/s");
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Difficulty");
if (net.getDouble("difficulty") > 0)
wi.setValue("" + net.getDouble("difficulty"));
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Next Difficulty");
if (net.getDouble("next_difficulty") > 0)
wi.setValue("" + net.getDouble("next_difficulty"));
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Retarget time");
if (net.getDouble("retarget_time") > 0)
wi.setValue(splitToComponentTimes(net.getInt("retarget_time")));
else
wi.setValue("Unknown");
network.add(wi);
JSONObject poolJson = (JSONObject) full.get("pool");
wi = new KeyValue();
wi.setKey("Pool HashRate");
if (poolJson.getLong("hash_rate") > 0)
wi.setValue((poolJson.getLong("hash_rate") / 1000000) + " GH/s");
else
wi.setValue("Unknown");
pool.add(wi);
wi = new KeyValue();
wi.setKey("Active users");
if (poolJson.getInt("active_users") > 0)
wi.setValue("" + poolJson.getInt("active_users"));
else
wi.setValue("Unknown");
pool.add(wi);
wi = new KeyValue();
wi.setKey("PPS Ratio");
if (poolJson.getDouble("pps_ratio") > 0)
wi.setValue("" + poolJson.getDouble("pps_ratio"));
else
wi.setValue("Unknown");
pool.add(wi);
} }
} catch (Exception e) {
System.out.println(e.getMessage());
} }
finished = finished | 1;
}
}).start();
new Thread(new Runnable() {
@Override
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"));
if (restRequest != null && restRequest.length() > 0) {
JSONObject full = new JSONObject(restRequest);
JSONArray balances = (JSONArray) full.get("balances");
double res = balances.getJSONObject(0).getDouble("value");
if (res > 0d) {
resultStr = res + " XRP " + curSym + String.format("%.2f", (res * lastPrices[2]));
} else
resultStr = "Unknown";
KeyValue wi = new KeyValue();
wi.setKey("My Balance XRP");
wi.setValue(resultStr);
prices.add(wi);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
finished = finished | 10;
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
if (ethWallet != null && !"null".equals(ethWallet) && ethWallet.length() > 0) {
restRequest = getStringResponse(
"https://api.etherscan.io/api?module=account&action=balance&address=" + ethWallet
+ "&tag=latest&apikey=N54NVXSVSISMQ4QIM2JVKJW56KHCKMU5T4");
if (restRequest != null && restRequest.length() > 0) {
JSONObject full = new JSONObject(restRequest);
String confirmedBalance = (String) full.get("result");
double res = Double.parseDouble(confirmedBalance);
res = res * 0.000000000000000001;
if (res > 0d) {
resultStr = res + " ETH " + curSym + String.format("%.2f", (res * lastPrices[3]));
} else
resultStr = "Unknown";
KeyValue wi = new KeyValue();
wi.setKey("My Balance ETH");
wi.setValue(resultStr);
prices.add(wi);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
finished = finished | 100;
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
if (ltcapikey != null && !"null".equals(ltcapikey) && ltcapikey.length() > 0) {
String miningJson = getStringResponse(
"https://www.litecoinpool.org/api?api_key=".concat(ltcapikey));
if (miningJson != null && miningJson.length() > 0) {
JSONObject full = new JSONObject(miningJson);
JSONObject user = (JSONObject) full.get("user");
KeyValue wi = new KeyValue();
wi.setKey("HashRate");
if (user.getInt("hash_rate") > 0)
wi.setValue((user.getInt("hash_rate") / 1000) + " MH/s");
else
wi.setValue("Unknown");
workers.add(wi);
JSONObject workersJson = (JSONObject) full.get("workers");
for (Iterator<String> keys = workersJson.keys(); keys.hasNext();) {
String key = keys.next();
JSONObject worker = (JSONObject) workersJson.get(key);
wi = new KeyValue();
wi.setKey("HashRate " + key);
wi.setValue((worker.getInt("hash_rate") / 1000) + " MH/s");
workers.add(wi);
}
wi = new KeyValue();
wi.setKey("Paid");
if (user.getDouble("paid_rewards") > 0)
wi.setValue(user.getDouble("paid_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("paid_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Unpaid");
if (user.getDouble("unpaid_rewards") > 0)
wi.setValue(user.getDouble("unpaid_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("unpaid_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Total");
if (user.getDouble("total_rewards") > 0)
wi.setValue(user.getDouble("total_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("total_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Expected 24h");
if (user.getDouble("expected_24h_rewards") > 0)
wi.setValue(user.getDouble("expected_24h_rewards") + " LTC " + curSym + String
.format("%.2f", (user.getDouble("expected_24h_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Past 24h");
if (user.getDouble("past_24h_rewards") > 0)
wi.setValue(user.getDouble("past_24h_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("past_24h_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
JSONObject net = (JSONObject) full.get("network");
wi = new KeyValue();
wi.setKey("Network HashRate");
if (net.getLong("hash_rate") > 0)
wi.setValue((net.getLong("hash_rate") / 1000000) + " GH/s");
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Difficulty");
if (net.getDouble("difficulty") > 0)
wi.setValue("" + net.getDouble("difficulty"));
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Next Difficulty");
if (net.getDouble("next_difficulty") > 0)
wi.setValue("" + net.getDouble("next_difficulty"));
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Retarget time");
if (net.getDouble("retarget_time") > 0)
wi.setValue(splitToComponentTimes(net.getInt("retarget_time")));
else
wi.setValue("Unknown");
network.add(wi);
JSONObject poolJson = (JSONObject) full.get("pool");
wi = new KeyValue();
wi.setKey("Pool HashRate");
if (poolJson.getLong("hash_rate") > 0)
wi.setValue((poolJson.getLong("hash_rate") / 1000000) + " GH/s");
else
wi.setValue("Unknown");
pool.add(wi);
wi = new KeyValue();
wi.setKey("Active users");
if (poolJson.getInt("active_users") > 0)
wi.setValue("" + poolJson.getInt("active_users"));
else
wi.setValue("Unknown");
pool.add(wi);
wi = new KeyValue();
wi.setKey("PPS Ratio");
if (poolJson.getDouble("pps_ratio") > 0)
wi.setValue("" + poolJson.getDouble("pps_ratio"));
else
wi.setValue("Unknown");
pool.add(wi);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
finished = finished | 1000;
} }
}).start(); }).start();
@ -293,155 +317,173 @@ public class MiningBean {
@Override @Override
public void run() { public void run() {
String miningJson = HttpHelper try {
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserworkers&api_key=" String miningJson = getStringResponse(
+ dogapikey + "&id=282608&_=1621333944761", 5000); "https://aikapool.com/doge/index.php?page=api&action=getuserworkers&api_key="
if (miningJson != null && miningJson.length() > 0) { + dogapikey + "&id=282608&_=1621333944761");
JSONObject full = new JSONObject(miningJson); if (miningJson != null && miningJson.length() > 0) {
JSONObject user = (JSONObject) full.get("getuserworkers"); JSONObject full = new JSONObject(miningJson);
JSONArray data = (JSONArray) user.get("data"); JSONObject user = (JSONObject) full.get("getuserworkers");
KeyValue wi = new KeyValue(); JSONArray data = (JSONArray) user.get("data");
KeyValue wi = new KeyValue();
for (Iterator<Object> it = data.iterator(); it.hasNext();) {
JSONObject workersJson = (JSONObject) it.next();
wi = new KeyValue();
wi.setKey("HashRate " + workersJson.getString("username"));
double hr = workersJson.getDouble("hashrate");
wi.setValue(String.format("%.2f", (hr / 1000)) + " MH/s");
workers.add(wi);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
finished = finished | 10000;
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
String miningJson = getStringResponse(
"https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key="
+ dogapikey + "&id=282608&_=1621333944761");
if (miningJson != null && miningJson.length() > 0) {
JSONObject full = new JSONObject(miningJson);
JSONObject user = (JSONObject) full.get("getdashboarddata");
JSONObject data = (JSONObject) user.get("data");
JSONObject net = (JSONObject) data.get("network");
JSONObject pers = (JSONObject) data.get("personal");
JSONObject poolj = (JSONObject) data.get("pool");
JSONArray blocks = (JSONArray) poolj.get("blocks");
JSONObject estimates = (JSONObject) pers.get("estimates");
JSONObject raw = (JSONObject) data.get("raw");
KeyValue wi = new KeyValue();
for (Iterator<Object> it = data.iterator(); it.hasNext();) {
JSONObject workersJson = (JSONObject) it.next();
wi = new KeyValue(); wi = new KeyValue();
wi.setKey("HashRate " + workersJson.getString("username")); wi.setKey("Next Payout");
double hr = workersJson.getDouble("hashrate"); if (estimates.getDouble("payout") > 0)
wi.setValue(String.format("%.2f", (hr / 1000)) + " MH/s"); wi.setValue(estimates.getDouble("payout") + " DOG");
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Last Block Time");
if (blocks != null && blocks.get(0) != null) {
JSONObject block = (JSONObject) blocks.get(0);
long time = block.getLong("time");
wi.setValue("" + sdf.format(new Date(time * 1000)));
} else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Last Block Finder");
if (blocks != null && blocks.get(0) != null) {
JSONObject block = (JSONObject) blocks.get(0);
String finder = block.getString("finder");
if (block.isNull("group_name"))
wi.setValue(finder);
else
wi.setValue(finder + " (SOLO)");
} else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Difficulty");
if (net.getDouble("difficulty") > 0)
wi.setValue("" + net.getDouble("difficulty"));
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Next Difficulty");
if (net.getDouble("nextdifficulty") > 0)
wi.setValue("" + net.getDouble("nextdifficulty"));
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Pool Hashrate");
if (raw.getJSONObject("pool").getDouble("hashrate") > 0)
wi.setValue((raw.getJSONObject("pool").getDouble("hashrate") / 1000000) + " GH/s");
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Network Hashrate");
if (raw.getJSONObject("network").getDouble("hashrate") > 0)
wi.setValue((raw.getJSONObject("network").getDouble("hashrate") / 1000000) + " GH/s");
else
wi.setValue("Unknown");
network.add(wi);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
finished = finished | 100000;
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
String miningJson = getStringResponse(
"https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key="
+ dogapikey + "&id=282608&_=1621333944761");
if (miningJson != null && miningJson.length() > 0) {
JSONObject full = new JSONObject(miningJson);
JSONObject user = (JSONObject) full.get("getuserbalance");
JSONObject data = (JSONObject) user.get("data");
KeyValue wi = new KeyValue();
wi = new KeyValue();
wi.setKey("Paid");
if (data.getDouble("paid") >= 0)
wi.setValue(data.getDouble("paid") + " DOG");
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Confirmed");
if (data.getDouble("confirmed") >= 0)
wi.setValue(data.getDouble("confirmed") + " DOG");
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Unconfirmed");
if (data.getDouble("unconfirmed") >= 0)
wi.setValue(data.getDouble("unconfirmed") + " DOG");
else
wi.setValue("Unknown");
workers.add(wi); workers.add(wi);
} }
} catch (Exception e) {
System.out.println(e.getMessage());
} }
} finished = finished | 1000000;
}).start();
new Thread(new Runnable() {
@Override
public void run() {
String miningJson = HttpHelper
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key="
+ dogapikey + "&id=282608&_=1621333944761", 5000);
if (miningJson != null && miningJson.length() > 0) {
JSONObject full = new JSONObject(miningJson);
JSONObject user = (JSONObject) full.get("getdashboarddata");
JSONObject data = (JSONObject) user.get("data");
JSONObject net = (JSONObject) data.get("network");
JSONObject pers = (JSONObject) data.get("personal");
JSONObject poolj = (JSONObject) data.get("pool");
JSONArray blocks = (JSONArray) poolj.get("blocks");
JSONObject estimates = (JSONObject) pers.get("estimates");
JSONObject raw = (JSONObject) data.get("raw");
KeyValue wi = new KeyValue();
wi = new KeyValue();
wi.setKey("Next Payout");
if (estimates.getDouble("payout") > 0)
wi.setValue(estimates.getDouble("payout") + " DOG");
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Last Block Time");
if (blocks != null && blocks.get(0) != null) {
JSONObject block = (JSONObject) blocks.get(0);
long time = block.getLong("time");
wi.setValue("" + sdf.format(new Date(time * 1000)));
} else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Last Block Finder");
if (blocks != null && blocks.get(0) != null) {
JSONObject block = (JSONObject) blocks.get(0);
String finder = block.getString("finder");
if (block.isNull("group_name"))
wi.setValue(finder);
else
wi.setValue(finder + " (SOLO)");
} else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Difficulty");
if (net.getDouble("difficulty") > 0)
wi.setValue("" + net.getDouble("difficulty"));
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Next Difficulty");
if (net.getDouble("nextdifficulty") > 0)
wi.setValue("" + net.getDouble("nextdifficulty"));
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Pool Hashrate");
if (raw.getJSONObject("pool").getDouble("hashrate") > 0)
wi.setValue((raw.getJSONObject("pool").getDouble("hashrate") / 1000000) + " GH/s");
else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue();
wi.setKey("Network Hashrate");
if (raw.getJSONObject("network").getDouble("hashrate") > 0)
wi.setValue((raw.getJSONObject("network").getDouble("hashrate") / 1000000) + " GH/s");
else
wi.setValue("Unknown");
network.add(wi);
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
String miningJson = HttpHelper
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key="
+ dogapikey + "&id=282608&_=1621333944761", 5000);
if (miningJson != null && miningJson.length() > 0) {
JSONObject full = new JSONObject(miningJson);
JSONObject user = (JSONObject) full.get("getuserbalance");
JSONObject data = (JSONObject) user.get("data");
KeyValue wi = new KeyValue();
wi = new KeyValue();
wi.setKey("Paid");
if (data.getDouble("paid") >= 0)
wi.setValue(data.getDouble("paid") + " DOG");
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Confirmed");
if (data.getDouble("confirmed") >= 0)
wi.setValue(data.getDouble("confirmed") + " DOG");
else
wi.setValue("Unknown");
workers.add(wi);
wi = new KeyValue();
wi.setKey("Unconfirmed");
if (data.getDouble("unconfirmed") >= 0)
wi.setValue(data.getDouble("unconfirmed") + " DOG");
else
wi.setValue("Unknown");
workers.add(wi);
}
} }
}).start(); }).start();
} }
Thread.sleep(Constants.DEFAULT_HTTP_TIMEOUT); while (finished != 1042431) {
Thread.sleep(2000);
}
finished = 0;
KeyValue wi = new KeyValue(); KeyValue wi = new KeyValue();
wi.setKey("Last Update"); wi.setKey("Last Update");
@ -497,4 +539,41 @@ 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) {
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_CONNECTION_TIMEOUT, Constants.DEFAULT_HTTP_READ_TIMEOUT);
}
public String getStringResponse(String urlStr, int timeout, int readTimeout) {
String output = "";
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(false);
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");
conn.connect();
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 static void main(String[] args) {
int a = 0;
a = a | 100;
a = a | 1;
a = a | 10;
System.out.println(a);
}
} }

View File

@ -1,39 +0,0 @@
package cz.kamma.mining.helper;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import cz.kamma.mining.Constants;
public class HttpHelper {
public static String getStringResponse(String urlStr) {
return getStringResponse(urlStr, Constants.DEFAULT_HTTP_TIMEOUT);
}
public static String getStringResponse(String urlStr, int timeout) {
String output = "";
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(false);
conn.setConnectTimeout(timeout);
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");
conn.connect();
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;
}
}