Got json working.

This commit is contained in:
jwinterm
2015-12-11 00:01:24 -08:00
parent 80f8e42a22
commit b5546e638f
18 changed files with 288 additions and 83 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+3 -1
View File
@@ -22,6 +22,7 @@ allprojects {
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.6.0'
visuiVersion = '0.9.5'
}
repositories {
@@ -73,6 +74,7 @@ project(":html") {
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources"
compile "com.kotcrab.vis:vis-ui:$visuiVersion:sources"
}
}
@@ -84,7 +86,7 @@ project(":core") {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.google.code.gson:gson:1.7.2"
compile "com.kotcrab.vis:vis-ui:$visuiVersion"
}
}
+1
View File
@@ -0,0 +1 @@
bitmonerod.exe --data-dir=D:\wallets\monero\data
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,87 @@
package com.jw.lightwallet.daemon;
public class BlockHeader {
int depth;
int difficulty;
String hash;
int height;
int major_version;
int minor_version;
int nonce;
boolean orphan_status;
String prev_hash;
int reward;
int timestamp;
public int getDepth() {
return depth;
}
public void setDepth(int depth) {
this.depth = depth;
}
public int getDifficulty() {
return difficulty;
}
public void setDifficulty(int difficulty) {
this.difficulty = difficulty;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getMajor_version() {
return major_version;
}
public void setMajor_version(int major_version) {
this.major_version = major_version;
}
public int getMinor_version() {
return minor_version;
}
public void setMinor_version(int minor_version) {
this.minor_version = minor_version;
}
public int getNonce() {
return nonce;
}
public void setNonce(int nonce) {
this.nonce = nonce;
}
public boolean isOrphan_status() {
return orphan_status;
}
public void setOrphan_status(boolean orphan_status) {
this.orphan_status = orphan_status;
}
public String getPrev_hash() {
return prev_hash;
}
public void setPrev_hash(String prev_hash) {
this.prev_hash = prev_hash;
}
public int getReward() {
return reward;
}
public void setReward(int reward) {
this.reward = reward;
}
public int getTimestamp() {
return timestamp;
}
public void setTimestamp(int timestamp) {
this.timestamp = timestamp;
}
}
@@ -0,0 +1,52 @@
package com.jw.lightwallet.daemon;
import com.badlogic.gdx.Gdx;
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.jw.lightwallet.daemon.DaemonResponse;
import com.jw.lightwallet.utils.DaemonValues;
public class DaemonRPC {
public String address;
String response;
String getlastblock;
public DaemonRPC () {
address = "http://node.moneroclub.com:8880/json_rpc";
getlastblock = "{\"jsonrpc\":\"2.0\",\"id\":\"test\",\"method\":\"getlastblockheader\",\"params\":[]}";
}
public void getinfo (final DaemonValues daemonvalues) {
HttpRequest httpGet = new HttpRequest(HttpMethods.POST);
httpGet.setUrl(address);
httpGet.setContent(getlastblock);
Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() {
public void handleHttpResponse(HttpResponse httpResponse) {
response = httpResponse.getResultAsString();
System.out.print("1st time response" + response);
DaemonResponse daemonresponse = new Gson().fromJson(response, DaemonResponse.class);
System.out.print("GSON response is" + daemonresponse.getId());
daemonvalues.setBlockheight(daemonresponse.getResult().getBlock_header().getHeight());
daemonvalues.setDiff(daemonresponse.getResult().getBlock_header().getDifficulty());
daemonvalues.setLastblocktime(daemonresponse.getResult().getBlock_header().getTimestamp());
daemonvalues.setLastblockreward(daemonresponse.getResult().getBlock_header().getReward());
daemonvalues.setStatus(daemonresponse.getResult().getStatus());
}
public void failed(Throwable t) {
response = "failed";
System.out.print("Failed response status is: " + response);
//do stuff here based on the failed attempt
}
@Override
public void cancelled() {
// TODO Auto-generated method stub
}
});
}
}
@@ -0,0 +1,28 @@
package com.jw.lightwallet.daemon;
public class DaemonResponse {
String id;
String jsonrpc;
Result result;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getJsonrpc() {
return jsonrpc;
}
public void setJsonrpc(String jsonrpc) {
this.jsonrpc = jsonrpc;
}
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
}
@@ -0,0 +1,24 @@
package com.jw.lightwallet.daemon;
public class Result {
BlockHeader block_header;
String status;
public BlockHeader getBlock_header() {
return block_header;
}
public void setBlock_header(BlockHeader block_header) {
this.block_header = block_header;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
@@ -12,7 +12,7 @@ public class AbstractScreen implements Screen {
protected float w;
protected float h;
protected float aspect;
protected long screenShowTime;
protected float accumulator;
public AbstractScreen (LightWallet game) {
this.game = game;
@@ -20,6 +20,7 @@ public class AbstractScreen implements Screen {
this.w = Gdx.graphics.getWidth();
this.h = Gdx.graphics.getHeight();
this.aspect = w/h;
this.accumulator = 0;
}
@Override
@@ -31,7 +32,8 @@ public class AbstractScreen implements Screen {
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
accumulator = accumulator + delta;
}
@Override
@@ -1,32 +1,62 @@
package com.jw.lightwallet.screens;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.Timer;
import com.jw.lightwallet.LightWallet;
import com.jw.lightwallet.utils.DaemonRPC;
import com.jw.lightwallet.daemon.DaemonRPC;
import com.jw.lightwallet.utils.DaemonValues;
public class MainScreen extends AbstractScreen {
// Interface classes
DaemonRPC daemonrpc;
DaemonValues daemonvalues;
// Layout stuff
Table screenlayout;
TextButton daemonbutton;
TextButton walletbutton;
// Daemon layout
Table daemonlayout;
Image logo;
Label statuslabel;
Label statusvalue;
Label blockheightlabel;
Label blockheightvalue;
Label difflabel;
Label diffvalue;
Label hashratelabel;
Label hashratevalue;
Label lastblocktimelabel;
Label lastblocktimevalue;
Label rewardlabel;
Label rewardvalue;
// Wallet layout
// Transfer layout
// Tx history layout
// Timer
Timer timer;
public MainScreen(LightWallet game) {
super(game);
timer = new Timer();
daemonrpc = new DaemonRPC();
daemonrpc.getinfo();
daemonvalues = new DaemonValues();
daemonrpc.getinfo(daemonvalues);
}
public void show() {
super.show();
timer.scheduleTask(new Timer.Task() {
@Override
public void run() {
System.out.print(daemonvalues.getBlockheight());
}
}, 5f, 5f);
}
public void render(float delta) {
@@ -37,5 +67,6 @@ public class MainScreen extends AbstractScreen {
public void dispose() {
}
}
@@ -1,54 +0,0 @@
package com.jw.lightwallet.utils;
import com.badlogic.gdx.Gdx;
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 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 DaemonResponse getinfo () {
HttpRequest httpGet = new HttpRequest(HttpMethods.POST);
httpGet.setUrl(address);
httpGet.setContent(getlastblock);
Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() {
public void handleHttpResponse(HttpResponse httpResponse) {
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) {
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;}
}
}
@@ -1,20 +0,0 @@
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;
}
}
@@ -0,0 +1,52 @@
package com.jw.lightwallet.utils;
public class DaemonValues {
int blockheight;
int diff;
int hashrate;
int lastblocktime;
int lastblockreward;
String status;
public int getBlockheight() {
return blockheight;
}
public void setBlockheight(int blockheight) {
this.blockheight = blockheight;
}
public int getDiff() {
return diff;
}
public void setDiff(int diff) {
this.diff = diff;
this.hashrate = diff/60;
}
public int getHashrate() {
return hashrate;
}
public int getLastblocktime() {
return lastblocktime;
}
public void setLastblocktime(int lastblocktime) {
this.lastblocktime = lastblocktime;
}
public int getLastblockreward() {
return lastblockreward;
}
public void setLastblockreward(int lastblockreward) {
this.lastblockreward = lastblockreward;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
@@ -3,7 +3,7 @@
<module rename-to="html">
<inherits name='com.badlogic.gdx.backends.gdx_backends_gwt' />
<inherits name='com.badlogic.gdx.physics.box2d.box2d-gwt' />
<inherits name='com.kotcrab.vis.vis-ui' />
<inherits name='LightWallet' />
<entry-point class='com.jw.lightwallet.client.HtmlLauncher' />
@@ -5,7 +5,7 @@
<inherits name='com.badlogic.gdx.physics.box2d.box2d-gwt' />
<inherits name='com.jw.lightwallet.GdxDefinition' />
<inherits name='com.kotcrab.vis.vis-ui' />
<collapse-all-properties />
<add-linker name="xsiframe"/>