added last block

This commit is contained in:
rdavidek 2021-05-26 15:03:48 +02:00
parent 1b44489b20
commit 2810fb8b24

View File

@ -1,6 +1,10 @@
package cz.kamma.mining.bean; package cz.kamma.mining.bean;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -23,7 +27,7 @@ public class MiningBean {
List<KeyValue> pool = new ArrayList<>(); List<KeyValue> pool = new ArrayList<>();
List<KeyValue> network = new ArrayList<>(); List<KeyValue> network = new ArrayList<>();
String[] cryptoCur = new String[] { "btc", "ltc", "xrp", "eth"}; String[] cryptoCur = new String[] { "btc", "ltc", "xrp", "eth" };
double[] lastPrices = new double[] { 0, 0, 0, 0 }; double[] lastPrices = new double[] { 0, 0, 0, 0 };
String ltcapikey = request.getParameter("ltcapikey"); String ltcapikey = request.getParameter("ltcapikey");
@ -43,7 +47,7 @@ public class MiningBean {
if (currency.equals("usd")) if (currency.equals("usd"))
curSym = "$"; curSym = "$";
else if (currency.equals("eur")) else if (currency.equals("eur"))
curSym = ""; curSym = "";
workers.clear(); workers.clear();
prices.clear(); prices.clear();
@ -275,11 +279,11 @@ public class MiningBean {
wi = new KeyValue(); wi = new KeyValue();
wi.setKey("HashRate " + workersJson.getString("username")); wi.setKey("HashRate " + workersJson.getString("username"));
double hr = workersJson.getDouble("hashrate"); double hr = workersJson.getDouble("hashrate");
wi.setValue(String.format("%.2f",(hr / 1000)) + " MH/s"); wi.setValue(String.format("%.2f", (hr / 1000)) + " MH/s");
workers.add(wi); workers.add(wi);
} }
} }
miningJson = HttpHelper miningJson = HttpHelper
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key=" .getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key="
+ dogapikey + "&id=282608&_=1621333944761", 5000); + dogapikey + "&id=282608&_=1621333944761", 5000);
@ -289,10 +293,12 @@ public class MiningBean {
JSONObject data = (JSONObject) user.get("data"); JSONObject data = (JSONObject) user.get("data");
JSONObject net = (JSONObject) data.get("network"); JSONObject net = (JSONObject) data.get("network");
JSONObject pers = (JSONObject) data.get("personal"); 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 estimates = (JSONObject) pers.get("estimates");
JSONObject raw = (JSONObject) data.get("raw"); JSONObject raw = (JSONObject) data.get("raw");
KeyValue wi = new KeyValue(); KeyValue wi = new KeyValue();
wi = new KeyValue(); wi = new KeyValue();
wi.setKey("Next Payout"); wi.setKey("Next Payout");
if (estimates.getDouble("payout") > 0) if (estimates.getDouble("payout") > 0)
@ -301,6 +307,19 @@ public class MiningBean {
wi.setValue("Unknown"); wi.setValue("Unknown");
workers.add(wi); workers.add(wi);
wi = new KeyValue();
wi.setKey("Last Block");
if (blocks != null && blocks.get(0) != null) {
JSONObject block = (JSONObject)blocks.get(0);
long time = block.getLong("time");
String finder = block.getString("finder");
double amount = block.getDouble("amount");
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
wi.setValue("" + sdf.format(new Date(time*1000)) + " - "+finder + " - "+amount);
} else
wi.setValue("Unknown");
network.add(wi);
wi = new KeyValue(); wi = new KeyValue();
wi.setKey("Difficulty"); wi.setKey("Difficulty");
if (net.getDouble("difficulty") > 0) if (net.getDouble("difficulty") > 0)
@ -324,7 +343,7 @@ public class MiningBean {
else else
wi.setValue("Unknown"); wi.setValue("Unknown");
network.add(wi); network.add(wi);
wi = new KeyValue(); wi = new KeyValue();
wi.setKey("Network Hashrate"); wi.setKey("Network Hashrate");
if (raw.getJSONObject("network").getDouble("hashrate") > 0) if (raw.getJSONObject("network").getDouble("hashrate") > 0)
@ -333,7 +352,7 @@ public class MiningBean {
wi.setValue("Unknown"); wi.setValue("Unknown");
network.add(wi); network.add(wi);
} }
miningJson = HttpHelper miningJson = HttpHelper
.getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key=" .getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key="
+ dogapikey + "&id=282608&_=1621333944761", 5000); + dogapikey + "&id=282608&_=1621333944761", 5000);
@ -342,7 +361,7 @@ public class MiningBean {
JSONObject user = (JSONObject) full.get("getuserbalance"); JSONObject user = (JSONObject) full.get("getuserbalance");
JSONObject data = (JSONObject) user.get("data"); JSONObject data = (JSONObject) user.get("data");
KeyValue wi = new KeyValue(); KeyValue wi = new KeyValue();
wi = new KeyValue(); wi = new KeyValue();
wi.setKey("Paid"); wi.setKey("Paid");
if (data.getDouble("paid") >= 0) if (data.getDouble("paid") >= 0)
@ -358,7 +377,7 @@ public class MiningBean {
else else
wi.setValue("Unknown"); wi.setValue("Unknown");
workers.add(wi); workers.add(wi);
wi = new KeyValue(); wi = new KeyValue();
wi.setKey("Unconfirmed"); wi.setKey("Unconfirmed");
if (data.getDouble("unconfirmed") >= 0) if (data.getDouble("unconfirmed") >= 0)