diff --git a/src/main/java/cz/kamma/mining/bean/MiningBean.java b/src/main/java/cz/kamma/mining/bean/MiningBean.java index 084e9f6..12ad492 100644 --- a/src/main/java/cz/kamma/mining/bean/MiningBean.java +++ b/src/main/java/cz/kamma/mining/bean/MiningBean.java @@ -1,6 +1,10 @@ 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.Date; import java.util.Iterator; import java.util.List; @@ -23,7 +27,7 @@ public class MiningBean { List pool = new ArrayList<>(); List 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 }; String ltcapikey = request.getParameter("ltcapikey"); @@ -43,7 +47,7 @@ public class MiningBean { if (currency.equals("usd")) curSym = "$"; else if (currency.equals("eur")) - curSym = "€"; + curSym = ""; workers.clear(); prices.clear(); @@ -275,11 +279,11 @@ public class MiningBean { wi = new KeyValue(); wi.setKey("HashRate " + workersJson.getString("username")); 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); } } - + miningJson = HttpHelper .getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getdashboarddata&api_key=" + dogapikey + "&id=282608&_=1621333944761", 5000); @@ -289,10 +293,12 @@ public class MiningBean { 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) @@ -301,6 +307,19 @@ public class MiningBean { wi.setValue("Unknown"); 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.setKey("Difficulty"); if (net.getDouble("difficulty") > 0) @@ -324,7 +343,7 @@ public class MiningBean { else wi.setValue("Unknown"); network.add(wi); - + wi = new KeyValue(); wi.setKey("Network Hashrate"); if (raw.getJSONObject("network").getDouble("hashrate") > 0) @@ -333,7 +352,7 @@ public class MiningBean { wi.setValue("Unknown"); network.add(wi); } - + miningJson = HttpHelper .getStringResponse("https://aikapool.com/doge/index.php?page=api&action=getuserbalance&api_key=" + dogapikey + "&id=282608&_=1621333944761", 5000); @@ -342,7 +361,7 @@ public class MiningBean { 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) @@ -358,7 +377,7 @@ public class MiningBean { else wi.setValue("Unknown"); workers.add(wi); - + wi = new KeyValue(); wi.setKey("Unconfirmed"); if (data.getDouble("unconfirmed") >= 0)