added ETH

This commit is contained in:
rdavidek 2021-05-18 12:28:52 +02:00
parent 00f5522167
commit 3fde5d7f1d
5 changed files with 271 additions and 230 deletions

View File

@ -2,7 +2,7 @@ package cz.kamma.mining;
public interface Constants {
public static final String APP_VERSION = "v0.4";
public static final String APP_VERSION = "v0.5";
public static final String COPYRIGHT = "2021";
public static final int DEFAULT_HTTP_TIMEOUT = 2000;
}

View File

@ -29,6 +29,7 @@ public class MiningBean {
String apikey = request.getParameter("apikey");
String ltcWallet = request.getParameter("ltc");
String xrpWallet = request.getParameter("xrp");
String ethWallet = request.getParameter("eth");
String currency = request.getParameter("cur");
if (request.getParameter("apikey") == null) {
@ -58,7 +59,8 @@ public class MiningBean {
for (int i = 0; i < cryptoCur.length; i++) {
String ccur = cryptoCur[i];
restRequest = HttpHelper.getStringResponse("https://www.bitstamp.net/api/v2/ticker/".concat(ccur).concat(currency));
restRequest = HttpHelper
.getStringResponse("https://www.bitstamp.net/api/v2/ticker/".concat(ccur).concat(currency));
if (restRequest != null && restRequest.length() > 0) {
JSONObject tmp = new JSONObject(restRequest);
double res = tmp.getDouble("last");
@ -75,7 +77,8 @@ public class MiningBean {
}
if (ltcWallet != null && !"null".equals(ltcWallet) && ltcWallet.length() > 0) {
restRequest = HttpHelper.getStringResponse("https://chain.so/api/v2/get_address_balance/LTC/".concat(ltcWallet));
restRequest = HttpHelper
.getStringResponse("https://chain.so/api/v2/get_address_balance/LTC/".concat(ltcWallet));
if (restRequest != null && restRequest.length() > 0) {
JSONObject full = new JSONObject(restRequest);
JSONObject data = (JSONObject) full.get("data");
@ -94,7 +97,8 @@ public class MiningBean {
}
if (xrpWallet != null && !"null".equals(xrpWallet) && xrpWallet.length() > 0) {
restRequest = HttpHelper.getStringResponse("https://data.ripple.com/v2/accounts/".concat(xrpWallet).concat("/balances"));
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");
@ -110,8 +114,30 @@ public class MiningBean {
}
}
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);
}
}
if (apikey != null && !"null".equals(apikey) && apikey.length() > 0) {
String miningJson = HttpHelper.getStringResponse("https://www.litecoinpool.org/api?api_key=".concat(apikey));
String miningJson = HttpHelper
.getStringResponse("https://www.litecoinpool.org/api?api_key=".concat(apikey));
if (miningJson != null && miningJson.length() > 0) {
JSONObject full = new JSONObject(miningJson);
JSONObject user = (JSONObject) full.get("user");
@ -136,7 +162,8 @@ public class MiningBean {
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])));
wi.setValue(user.getDouble("paid_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("paid_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
@ -144,7 +171,8 @@ public class MiningBean {
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])));
wi.setValue(user.getDouble("unpaid_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("unpaid_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
@ -152,7 +180,8 @@ public class MiningBean {
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])));
wi.setValue(user.getDouble("total_rewards") + " LTC " + curSym
+ String.format("%.2f", (user.getDouble("total_rewards") * lastPrices[1])));
else
wi.setValue("Unknown");
workers.add(wi);
@ -160,7 +189,8 @@ public class MiningBean {
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])));
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);
@ -168,7 +198,8 @@ public class MiningBean {
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])));
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);
@ -237,25 +268,29 @@ public class MiningBean {
String tmp = "";
for (KeyValue kv : prices) {
tmp = tmp.concat("<pair><key>").concat(kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
tmp = tmp.concat("<pair><key>").concat(
kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
}
res = res.replace("#PRICES#", tmp);
tmp = "";
for (KeyValue kv : workers) {
tmp = tmp.concat("<pair><key>").concat(kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
tmp = tmp.concat("<pair><key>").concat(
kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
}
res = res.replace("#WORKERS#", tmp);
tmp = "";
for (KeyValue kv : pool) {
tmp = tmp.concat("<pair><key>").concat(kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
tmp = tmp.concat("<pair><key>").concat(
kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
}
res = res.replace("#POOL#", tmp);
tmp = "";
for (KeyValue kv : network) {
tmp = tmp.concat("<pair><key>").concat(kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
tmp = tmp.concat("<pair><key>").concat(
kv.getKey().concat("</key>").concat("<value>").concat(kv.getValue()).concat("</value></pair>"));
}
res = res.replace("#NETWORK#", tmp);

View File

@ -24,7 +24,7 @@
<script language=javascript type='text/javascript'>
function asynchUpdate() {
AX_asynchUpdate("<%=request.getParameter("apikey")%>", "<%=request.getParameter("ltc")%>", "<%=request.getParameter("xrp")%>", "<%=request.getParameter("cur")%>");
AX_asynchUpdate("<%=request.getParameter("apikey")%>", "<%=request.getParameter("ltc")%>", "<%=request.getParameter("eth")%>", "<%=request.getParameter("xrp")%>", "<%=request.getParameter("cur")%>");
setTimeout('asynchUpdate();', 5000);
}
asynchUpdate();

View File

@ -73,8 +73,8 @@ function ajaxGetXmlResponse() {
}
}
function AX_asynchUpdate(apikey, ltc, xrp, cur) {
var data = 'ajaxMethod=asynchUpdate&apikey=' + apikey + '&ltc=' + ltc
function AX_asynchUpdate(apikey, ltc, eth, xrp, cur) {
var data = 'ajaxMethod=asynchUpdate&apikey=' + apikey + '&ltc=' + ltc + '&eth=' + eth
+ '&xrp=' + xrp+ '&cur=' + cur;
ajaxSendRequest(data, AX_asynchUpdateResponse);
}

View File

@ -27,6 +27,12 @@
style='transition: text-shadow 0.7s ease-in-out;'><input
type="text" name="ltc" size="40" /></td>
</tr>
<tr>
<td class='group'>Ethereum wallet address (optional)</td>
<td align="right" class='group'
style='transition: text-shadow 0.7s ease-in-out;'><input
type="text" name="eth" size="40" /></td>
</tr>
<tr>
<td class='group'>Ripple wallet address (optional)</td>
<td align="right" class='group'