mirror of
https://github.com/jwinterm/LightWallet2.git
synced 2026-10-17 05:21:26 +02:00
Some more work on JSON stuff.
This commit is contained in:
@@ -13,18 +13,14 @@ public class MainScreen extends AbstractScreen {
|
||||
Table screenlayout;
|
||||
TextButton daemonbutton;
|
||||
TextButton walletbutton;
|
||||
// Daemon layout
|
||||
Table daemonlayout;
|
||||
|
||||
// Bitmonerod info variables
|
||||
int blockheight;
|
||||
int diff;
|
||||
int hashrate;
|
||||
float blockreward;
|
||||
|
||||
public MainScreen(LightWallet game) {
|
||||
super(game);
|
||||
|
||||
daemonrpc = new DaemonRPC();
|
||||
daemonrpc.getinfo();
|
||||
|
||||
}
|
||||
|
||||
@@ -32,5 +28,14 @@ public class MainScreen extends AbstractScreen {
|
||||
super.show();
|
||||
|
||||
}
|
||||
|
||||
public void render(float delta) {
|
||||
super.render(delta);
|
||||
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,39 +5,50 @@ import com.badlogic.gdx.Net.HttpMethods;
|
||||
import com.badlogic.gdx.Net.HttpRequest;
|
||||
import com.badlogic.gdx.Net.HttpResponse;
|
||||
import com.badlogic.gdx.Net.HttpResponseListener;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class DaemonRPC {
|
||||
public String address;
|
||||
String status;
|
||||
String response;
|
||||
String getlastblock;
|
||||
DaemonResponse daemonresponse;
|
||||
|
||||
public DaemonRPC () {
|
||||
address = "http://node.moneroclub.com:8880/json_rpc";
|
||||
getlastblock = "{\"jsonrpc\":\"2.0\",\"id\":\"test\",\"method\":\"getlastblockheader\",\"params\":[]}";
|
||||
}
|
||||
|
||||
public void getinfo () {
|
||||
public DaemonResponse getinfo () {
|
||||
HttpRequest httpGet = new HttpRequest(HttpMethods.POST);
|
||||
httpGet.setUrl(address);
|
||||
httpGet.setContent(getlastblock);
|
||||
httpGet.setContent(getlastblock);
|
||||
|
||||
Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() {
|
||||
Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() {
|
||||
public void handleHttpResponse(HttpResponse httpResponse) {
|
||||
status = httpResponse.getResultAsString();
|
||||
System.out.print(status);
|
||||
response = httpResponse.getResultAsString();
|
||||
System.out.print(response);
|
||||
JsonObject gsonresponse = new Gson().fromJson(response, JsonObject.class);
|
||||
// Bitmonerod info variables
|
||||
String status = gsonresponse.getAsJsonObject("response").getAsJsonObject("status").getAsString();
|
||||
int blockheight = gsonresponse.getAsJsonObject("response").getAsJsonObject("block_header").get("height").getAsInt();
|
||||
int diff = gsonresponse.getAsJsonObject("response").getAsJsonObject("block_header").get("difficulty").getAsInt();
|
||||
float blockreward = gsonresponse.getAsJsonObject("response").getAsJsonObject("block_header").get("reward").getAsFloat();
|
||||
int timestamp = gsonresponse.getAsJsonObject("response").getAsJsonObject("block_header").get("timestamp").getAsInt();
|
||||
daemonresponse = new DaemonResponse(status, blockheight, diff, timestamp, blockreward);
|
||||
}
|
||||
|
||||
public void failed(Throwable t) {
|
||||
status = "failed";
|
||||
response = "failed";
|
||||
//do stuff here based on the failed attempt
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelled() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
if (daemonresponse.status == "OK") {return daemonresponse;}
|
||||
else {return null;}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.jw.lightwallet.utils;
|
||||
|
||||
public class DaemonResponse {
|
||||
String status;
|
||||
int blockheight;
|
||||
int diff;
|
||||
int hashrate;
|
||||
int lastblocktime;
|
||||
float blockreward;
|
||||
|
||||
DaemonResponse (String status, int blockheight, int diff, int lastblocktime, float blockreward) {
|
||||
this.status = status;
|
||||
this.blockheight = blockheight;
|
||||
this.diff = diff;
|
||||
this.hashrate = diff/60;
|
||||
this.lastblocktime = lastblocktime;
|
||||
this.blockreward = blockreward;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user