diff --git a/core/src/com/jw/lightwallet/screens/MainScreen.java b/core/src/com/jw/lightwallet/screens/MainScreen.java index acd8a10..670bff0 100644 --- a/core/src/com/jw/lightwallet/screens/MainScreen.java +++ b/core/src/com/jw/lightwallet/screens/MainScreen.java @@ -23,7 +23,9 @@ import com.jw.lightwallet.daemon.DaemonRPC; import com.jw.lightwallet.utils.BalanceValues; import com.jw.lightwallet.utils.Constants; import com.jw.lightwallet.utils.DaemonValues; +import com.jw.lightwallet.utils.WalletSaveValues; import com.jw.lightwallet.wallet.BalanceRPC; +import com.jw.lightwallet.wallet.WalletSaveRPC; public class MainScreen extends AbstractScreen { @@ -34,6 +36,9 @@ public class MainScreen extends AbstractScreen { BalanceRPC balancerpc; BalanceValues balancevalues; + WalletSaveRPC walletsaverpc; + WalletSaveValues walletsavevalues; + // Layout stuff Stage stage; Table screenlayout; @@ -55,7 +60,7 @@ public class MainScreen extends AbstractScreen { // Timers Timer daemontimer; - Timer wallettimer; + Timer walletsavetimer; Timer balancetimer; // Wallet thread and queue stuff @@ -68,8 +73,8 @@ public class MainScreen extends AbstractScreen { super(game); daemontimer = new Timer(); - wallettimer = new Timer(); - wq = new AtomicQueue(100); + walletsavetimer = new Timer(); + wq = new AtomicQueue(1000); balancetimer = new Timer(); Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); @@ -79,6 +84,9 @@ public class MainScreen extends AbstractScreen { balancerpc = new BalanceRPC(); balancevalues = new BalanceValues(); + + walletsaverpc = new WalletSaveRPC(); + walletsavevalues= new WalletSaveValues(); stage = new Stage(); Gdx.input.setInputProcessor(stage); @@ -94,8 +102,7 @@ public class MainScreen extends AbstractScreen { @Override public void clicked (InputEvent event, float x, float y) { System.out.println("Daemon button Pressed"); - viewcontainer.removeActor(walletview.walletlayout); - viewcontainer.removeActor(transactionview.txlayout); + viewcontainer.removeActor(viewcontainer.getChildren().get(0)); viewcontainer.add(daemonview.daemonlayout).expand().bottom(); } }); @@ -104,8 +111,7 @@ public class MainScreen extends AbstractScreen { @Override public void clicked (InputEvent event, float x, float y) { System.out.println("Wallet button Pressed"); - viewcontainer.removeActor(daemonview.daemonlayout); - viewcontainer.removeActor(transactionview.txlayout); + viewcontainer.removeActor(viewcontainer.getChildren().get(0)); viewcontainer.add(walletview.walletlayout).expand().bottom(); } }); @@ -114,8 +120,7 @@ public class MainScreen extends AbstractScreen { @Override public void clicked (InputEvent event, float x, float y) { System.out.println("Transfer button Pressed"); - viewcontainer.removeActor(daemonview.daemonlayout); - viewcontainer.removeActor(walletview.walletlayout); + viewcontainer.removeActor(viewcontainer.getChildren().get(0)); viewcontainer.add(transactionview.txlayout).expand().bottom(); } }); @@ -124,6 +129,8 @@ public class MainScreen extends AbstractScreen { @Override public void clicked (InputEvent event, float x, float y) { System.out.println("History button Pressed"); + viewcontainer.removeActor(viewcontainer.getChildren().get(0)); + viewcontainer.add(transactionview.txlayout).expand().bottom(); } }); @@ -189,37 +196,7 @@ public class MainScreen extends AbstractScreen { } }, 1f, 10f); - // Timer task to get output from simplewallet logging and check balances - /*wallettimer.scheduleTask(new Timer.Task() { - @Override - public void run() { - String queuepoll = wq.poll(); - Gdx.app.log(LightWallet.LOG, "Queue result: " + queuepoll); - try{ - if (queuepoll != null && queuepoll.contains("height:")) { - String height = queuepoll.split("height: ")[1].split(",")[0]; - walletview.syncvalue.setText(height + " / " + daemonvalues.getBlockheight()); - } - else if (queuepoll != null && queuepoll.contains("height ")) { - String height = queuepoll.split("height ")[1].split(",")[0]; - walletview.syncvalue.setText(height + " / " + daemonvalues.getBlockheight()); - } - else if (queuepoll != null && queuepoll.contains("money")) { - PrintWriter txout; - try { - txout = new PrintWriter(new BufferedWriter(new FileWriter(game.walletvalues.getName() + "tx.txt", true))); - txout.println(queuepoll); - txout.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } catch (NullPointerException e){e.printStackTrace();} - } - }, 1f, 0.05f);*/ - - // Timer task to get network info from daemon + // Timer task to check balance from simplewallet balancetimer.scheduleTask(new Timer.Task() { @Override public void run() { @@ -227,8 +204,17 @@ public class MainScreen extends AbstractScreen { } }, 1f, 5f); + // Timer task to try and save wallet every minute + walletsavetimer.scheduleTask(new Timer.Task() { + @Override + public void run() { + walletsaverpc.trysave(walletsavevalues); + } + }, 60f, 60f); + } + public void render(float delta) { super.render(delta); @@ -259,23 +245,20 @@ public class MainScreen extends AbstractScreen { } } } catch (NullPointerException e){e.printStackTrace();} - } + public void dispose() { super.dispose(); - } + @Override public void hide() { // TODO Auto-generated method stub super.hide(); wp.destroy(); - } - - } diff --git a/core/src/com/jw/lightwallet/screens/WalletView.java b/core/src/com/jw/lightwallet/screens/WalletView.java index 564efe2..b5c5fcb 100644 --- a/core/src/com/jw/lightwallet/screens/WalletView.java +++ b/core/src/com/jw/lightwallet/screens/WalletView.java @@ -22,7 +22,9 @@ public class WalletView { Label unlockedlabel; Label unlockedvalue; Label lockedlabel; - Label lockedvalue; + Label lockedvalue; + TextButton savewalletbtn; + Label savewalletlabel; int padvalue; @@ -32,7 +34,7 @@ public class WalletView { Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); walletlayout = new Table(); - padvalue = 15; + padvalue = 16; namelabel = new Label("Name: ", uiSkin); namevalue = new Label(game.walletvalues.getName(), uiSkin); @@ -60,6 +62,11 @@ public class WalletView { walletlayout.add(lockedlabel).pad(padvalue); walletlayout.add(lockedvalue).pad(padvalue).row(); + savewalletbtn = new TextButton("Save wallet\n(will attempt autosave every 60 s)", uiSkin); + savewalletlabel = new Label("Not saved :(", uiSkin, "redlabel"); + walletlayout.add(savewalletbtn); + walletlayout.add(savewalletlabel); + addresslabel.addListener(new ClickListener() { @Override public void clicked (InputEvent event, float x, float y) { diff --git a/core/src/com/jw/lightwallet/utils/WalletSaveValues.java b/core/src/com/jw/lightwallet/utils/WalletSaveValues.java new file mode 100644 index 0000000..53b3ad8 --- /dev/null +++ b/core/src/com/jw/lightwallet/utils/WalletSaveValues.java @@ -0,0 +1,5 @@ +package com.jw.lightwallet.utils; + +public class WalletSaveValues { + +} diff --git a/core/src/com/jw/lightwallet/wallet/WalletSaveRPC.java b/core/src/com/jw/lightwallet/wallet/WalletSaveRPC.java new file mode 100644 index 0000000..5ccf87a --- /dev/null +++ b/core/src/com/jw/lightwallet/wallet/WalletSaveRPC.java @@ -0,0 +1,47 @@ +package com.jw.lightwallet.wallet; + +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.utils.WalletSaveValues; + + +public class WalletSaveRPC { + public String swaddress; + String response; + String store; + + public WalletSaveRPC () { + swaddress = "http://localhost:19091/json_rpc"; + store = "{\"jsonrpc\":\"2.0\",\"id\":\"test\",\"method\":\"store\",\"params\":[]}"; + } + + public void trysave (final WalletSaveValues walletsavevalues) { + HttpRequest httpGet = new HttpRequest(HttpMethods.POST); + httpGet.setUrl(swaddress); + httpGet.setContent(store); + + Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() { + public void handleHttpResponse(HttpResponse httpResponse) { + response = httpResponse.getResultAsString(); + //System.out.print("Balance response: " + response); + + + } + + 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 + } + }); + } +} diff --git a/desktop/bitmonerod.exe b/desktop/bitmonerod.exe index d76baa2..7fe325c 100644 Binary files a/desktop/bitmonerod.exe and b/desktop/bitmonerod.exe differ diff --git a/desktop/libeay32.dll b/desktop/libeay32.dll index 7c3f4a7..4359304 100644 Binary files a/desktop/libeay32.dll and b/desktop/libeay32.dll differ diff --git a/desktop/simplewallet.exe b/desktop/simplewallet.exe index 7f69a2b..fa66672 100644 Binary files a/desktop/simplewallet.exe and b/desktop/simplewallet.exe differ diff --git a/desktop/ssleay32.dll b/desktop/ssleay32.dll index 97f1db0..b979662 100644 Binary files a/desktop/ssleay32.dll and b/desktop/ssleay32.dll differ