Got create wallet working.

This commit is contained in:
jwinterm
2015-12-19 22:59:53 -08:00
parent ab668c6cad
commit 1c0809bdec
18 changed files with 226 additions and 121 deletions
Binary file not shown.
Binary file not shown.
+19 -24
View File
@@ -4,49 +4,44 @@ import java.io.File;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.jw.lightwallet.screens.CreateScreen;
import com.jw.lightwallet.screens.ImportKeysScreen;
import com.jw.lightwallet.screens.ImportSeedScreen;
import com.jw.lightwallet.screens.MainScreen;
import com.jw.lightwallet.screens.WizardScreen;
import com.jw.lightwallet.utils.WalletValues;
public class LightWallet extends Game {
public static final String LOG = LightWallet.class.getSimpleName(); // Logging constant
public String dir;
// Set screen methods
public MainScreen getMainScreen(){
return new MainScreen(this);
}
public WizardScreen getWizardScreen(){
return new WizardScreen(this);
}
public CreateScreen getCreateScreen(){
return new CreateScreen(this);
}
public ImportKeysScreen getImportKeysScreen(){
return new ImportKeysScreen(this);
}
public ImportSeedScreen getImportSeedScreen(){
return new ImportSeedScreen(this);
}
public String os;
public String simplewalletloc;
public WalletValues walletvalues;
@Override
public void create () {
// Initialize logger
Gdx.app.log(LightWallet.LOG, "Launching application");
// Object to store wallet values
walletvalues = new WalletValues();
// Get directory where program launched
dir = System.getProperty("user.dir");
os = System.getProperty("os.name");
if (os.contains("Windows")) {
simplewalletloc = dir + "\\" + "simplewallet.exe";
System.out.println(simplewalletloc);
}
// Initialize logger
Gdx.app.log(LightWallet.LOG, "Launching application in " + dir + " on " + os);
// Check if config file exists, if not launch setup wizard
File f = new File("lightwallet.conf");
if(f.exists() && !f.isDirectory()) {
setScreen(getMainScreen());
setScreen(new MainScreen(this));
}
else {setScreen(getWizardScreen());}
else {setScreen(new WizardScreen(this));}
}
@@ -27,9 +27,9 @@ public class DaemonRPC {
Gdx.net.sendHttpRequest (httpGet, new HttpResponseListener() {
public void handleHttpResponse(HttpResponse httpResponse) {
response = httpResponse.getResultAsString();
System.out.print("1st time response" + response);
//System.out.print("1st time response" + response);
DaemonResponse daemonresponse = new Gson().fromJson(response, DaemonResponse.class);
System.out.print("GSON response is" + daemonresponse.getId());
//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());
@@ -39,7 +39,7 @@ public class DaemonRPC {
public void failed(Throwable t) {
response = "failed";
System.out.print("Failed response status is: " + response);
//System.out.print("Failed response status is: " + response);
//do stuff here based on the failed attempt
}
@@ -1,9 +1,18 @@
package com.jw.lightwallet.screens;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
@@ -12,7 +21,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.jw.lightwallet.LightWallet;
import com.jw.lightwallet.utils.CreateWallet;
import com.jw.lightwallet.utils.Constants;
public class CreateScreen extends AbstractScreen {
@@ -38,14 +47,14 @@ public class CreateScreen extends AbstractScreen {
Label pwrptlabel;
TextField pwrpttext;
String pwrpt;
Label nodelabel;
TextField nodetext;
Table buttontable;
TextButton createbutton;
TextButton gobackbutton;
CreateWallet createwallet;
public CreateScreen(final LightWallet game) {
super(game);
System.out.print("CreateScreen creating.");
@@ -64,7 +73,8 @@ public class CreateScreen extends AbstractScreen {
instruction = "Please enter a name for your wallet in the \"Wallet name\" field. This is typically wallet.bin, "
+ "but you can make it whatever you like (as long as it is alphanumberic and periods only). "
+ "Then please enter a strong password for your wallet that you will use to unlock, and then repeat it to ensure it is correct. "
+ "Your password can be any combination of characters and symbols on your keyboard (I think).";
+ "Your password can be any combination of characters and symbols on your keyboard (I think). "
+ "The default bitmonerod node is set for moneroclub, if you want to run a local daemon change the node field to http://localhost:18081.";
instructionlabel= new Label(instruction, uiSkin);
instructionlabel.setWrap(true);
@@ -82,12 +92,16 @@ public class CreateScreen extends AbstractScreen {
pwrpttext = new TextField("", uiSkin);
pwrpttext.setPasswordMode(true);
pwrpttext.setPasswordCharacter((char) 42);
nodelabel = new Label("Node address: ", uiSkin);
nodetext = new TextField(Constants.moneroclub, uiSkin);
inputtable.add(namelabel).width(200);
inputtable.add(nametext).width(400).row();
inputtable.add(pwlabel).width(200);
inputtable.add(pwtext).width(400).row();
inputtable.add(pwrptlabel).width(200);
inputtable.add(pwrpttext).width(400).row();
inputtable.add(nodelabel).width(200);
inputtable.add(nodetext).width(400).row();
buttontable = new Table();
createbutton = new TextButton("Create!", uiSkin);
@@ -99,7 +113,7 @@ public class CreateScreen extends AbstractScreen {
pwrpt = pwrpttext.getText();
if (name.length() > 0 && pw.equals(pwrpt)) {
System.out.println(name + ", " + pw + ", " + pwrpt);
createwallet = new CreateWallet(name, pw);
CreateWallet(name, pw, game.simplewalletloc);
}
//game.setScreen(game.getCreateScreen());
}
@@ -108,7 +122,7 @@ public class CreateScreen extends AbstractScreen {
gobackbutton.addListener(new ClickListener() {
@Override
public void clicked (InputEvent event, float x, float y) {
game.setScreen(game.getWizardScreen());
game.setScreen(new WizardScreen(game));
}
});
buttontable.add(createbutton).width(150);
@@ -121,6 +135,8 @@ public class CreateScreen extends AbstractScreen {
screenlayout.setFillParent(true);
stage.addActor(screenlayout);
}
public void show() {
@@ -140,6 +156,105 @@ public class CreateScreen extends AbstractScreen {
super.dispose();
}
public void CreateWallet(String name, String pw, String simplewalletloc) {
int i = 0;
boolean flag = false;
String str = null;
String seed = "";
Dialog success_dialog = new Dialog("Success!", uiSkin, "dialog") {
public void result(Object obj) {
System.out.println("result "+obj);
}
};
Label success_label = new Label("Wallet successfully created. " + name + " file is your binary wallet file. "
+ name + ".keys is your keys file; "
+ "the keys file is password protected and you can restore your binary wallet file with it. " +
" A text file named " + name + "info.txt has also been created. This file contains your wallet recovery seed and view key. " +
"Please encrypt this file or print it and delete it. Your wallet seed allows wallet recovery and bypasses your password." +
"A file named lightwallet.conf has also been created; this file specifies the wallet and node currently in use.", uiSkin);
success_label.setWrap(true);
success_dialog.add(success_label).width(400).row();
success_dialog.button("Continue", true).addListener(new ClickListener() {
@Override
public void clicked (InputEvent event, float x, float y) {
game.setScreen(new MainScreen(game));
uiSkin.dispose();
stage.dispose();
}
});
success_dialog.key(Keys.ENTER, true); //sends "true" when the ENTER key is pressed
System.out.println("Starting creator");
try {
Process tr = Runtime.getRuntime().exec("simplewallet --generate-new-wallet " + name + " --password " + pw);
Writer wr = new OutputStreamWriter( tr.getOutputStream() );
BufferedReader rd = new BufferedReader( new InputStreamReader( tr.getInputStream() ) );
System.out.println("Here is the standard output of the command:\n");
while (true) {
str = rd.readLine();
System.out.println(i + " " + str);
i += 1;
if (str.contains("Japanese")) {
break;
}
}
wr.write( "0\n" );
wr.flush();
while (true) {
str = rd.readLine();
System.out.println(i + " " + str);
i += 1;
if (str.contains("*****") && flag == true) {break;}
if (str.contains("*****")) {flag = true;}
if (str.contains("new wallet:")) {
game.walletvalues.setAddress(str.split("wallet: ")[1]);
}
if (str.contains("view key:")) {
game.walletvalues.setViewkey(str.split("key: ")[1]);
}
if (i >=23 && i <=26) {seed += str;}
}
wr.write( "exit\n" );
wr.flush();
game.walletvalues.setName(name);
game.walletvalues.setPw(pw);
game.walletvalues.setSeed(seed);
PrintWriter infowriter = new PrintWriter(name + "info.txt", "UTF-8");
infowriter.println("Wallet name: " + name);
infowriter.println("Wallet pw: " + pw);
infowriter.println("Wallet address: " + game.walletvalues.getAddress());
infowriter.println("Wallet view key: " + game.walletvalues.getViewkey());
infowriter.println("Wallet seed: " + game.walletvalues.getSeed());
infowriter.close();
PrintWriter confwriter = new PrintWriter("lightwallet.conf", "UTF-8");
confwriter.println("Wallet name: " + name);
confwriter.println("Wallet address: " + game.walletvalues.getAddress());
confwriter.println("Wallet view key: " + game.walletvalues.getViewkey());
confwriter.println("Node address: " + nodetext.getText());
confwriter.close();
success_dialog.show(stage);
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
}
Gdx.app.log(LightWallet.LOG, "Address is: " + game.walletvalues.getAddress());
Gdx.app.log(LightWallet.LOG, "Seed is: " + game.walletvalues.getSeed());
}
}
@@ -119,7 +119,7 @@ public class MainScreen extends AbstractScreen {
daemonrpc.getinfo(daemonvalues);
daemonview.Update(daemonvalues);
}
}, 1f, 5f);
}, 1f, 10f);
}
@@ -61,7 +61,7 @@ public class WizardScreen extends AbstractScreen {
createbutton.addListener(new ClickListener() {
@Override
public void clicked (InputEvent event, float x, float y) {
game.setScreen(game.getCreateScreen());
game.setScreen(new CreateScreen(game));
}
});
createbutton.pad(padvalue);
@@ -70,7 +70,7 @@ public class WizardScreen extends AbstractScreen {
importkeysbutton.addListener(new ClickListener() {
@Override
public void clicked (InputEvent event, float x, float y) {
game.setScreen(game.getImportKeysScreen());
game.setScreen(new ImportKeysScreen(game));
}
});
importkeysbutton.pad(padvalue);
@@ -79,7 +79,7 @@ public class WizardScreen extends AbstractScreen {
importseedbutton.addListener(new ClickListener() {
@Override
public void clicked (InputEvent event, float x, float y) {
game.setScreen(game.getImportSeedScreen());
game.setScreen(new ImportSeedScreen(game));
}
});
importseedbutton.pad(padvalue);
@@ -1,84 +0,0 @@
package com.jw.lightwallet.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
public class CreateWallet {
String name;
String pw;
public CreateWallet(String name, String pw) {
this.name = name;
this.pw = pw;
System.out.println("Starting creator");
String s = null;
System.out.println("Working Directory = " +
System.getProperty("user.dir"));
try {
Process tr = Runtime.getRuntime().exec("E:\\src\\lightWallet\\simplewallet.exe --generate-new-wallet jj --password jj");
Writer wr = new OutputStreamWriter( tr.getOutputStream() );
BufferedReader rd = new BufferedReader( new InputStreamReader( tr.getInputStream() ) );
System.out.println("Here is the standard output of the command:\n");
while (true) {
String str = rd.readLine();
System.out.println( str );
if (str.contains("Japanese")) {
break;
}
}
wr.write( "0\n" );
wr.flush();
String str = rd.readLine();
System.out.println( str );
System.out.println("Here is the standard output of the command:\n");
while ((s = rd.readLine()) != null) {
System.out.println(s);
}
wr.write( "exit\n" );
wr.flush();
/*
// run the Unix "ps -ef" command
// using the Runtime exec method:
Process p = Runtime.getRuntime().exec("E:\\src\\lightWallet\\simplewallet.exe --generate-new-wallet jj --password jj");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}*/
System.exit(0);
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}
}
@@ -0,0 +1,44 @@
package com.jw.lightwallet.utils;
public class WalletValues {
String name;
String pw;
String address;
String viewkey;
String seed;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getViewkey() {
return viewkey;
}
public void setViewkey(String viewkey) {
this.viewkey = viewkey;
}
public String getSeed() {
return seed;
}
public void setSeed(String seed) {
this.seed = seed;
}
}