From a7245c927f59eed651091cec17f1cdab4711e174 Mon Sep 17 00:00:00 2001 From: jwinterm Date: Tue, 22 Dec 2015 22:29:55 -0800 Subject: [PATCH] Got import wallet by keys working. --- .../lightwallet/screens/ImportKeysScreen.java | 291 +++++++++++++++++- .../jw/lightwallet/screens/MainScreen.java | 7 +- .../lightwallet/screens/TransactionView.java | 35 ++- .../jw/lightwallet/screens/WalletView.java | 18 +- desktop/ffff | 4 - desktop/ffff.address.txt | 1 - desktop/ffff.keys | Bin 577 -> 0 bytes desktop/ffffinfo.txt | 5 - desktop/lightwallet.conf | 4 - 9 files changed, 328 insertions(+), 37 deletions(-) delete mode 100644 desktop/ffff delete mode 100644 desktop/ffff.address.txt delete mode 100644 desktop/ffff.keys delete mode 100644 desktop/ffffinfo.txt delete mode 100644 desktop/lightwallet.conf diff --git a/core/src/com/jw/lightwallet/screens/ImportKeysScreen.java b/core/src/com/jw/lightwallet/screens/ImportKeysScreen.java index f5ef0e7..b1d6150 100644 --- a/core/src/com/jw/lightwallet/screens/ImportKeysScreen.java +++ b/core/src/com/jw/lightwallet/screens/ImportKeysScreen.java @@ -1,12 +1,301 @@ package com.jw.lightwallet.screens; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +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; +import com.badlogic.gdx.scenes.scene2d.ui.Table; +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.Constants; public class ImportKeysScreen extends AbstractScreen { + Stage stage; + Table screenlayout; + Skin uiSkin; + int padvalue; + + Image logo; + Texture logotex; + + Table textcontainer; + String instruction; + Label instructionlabel; + + Table inputtable; + Label pathlabel; + TextField pathtext; + String path; + Label pwlabel; + TextField pwtext; + String pw; + Label nodelabel; + TextField nodetext; + + Table buttontable; + TextButton importbutton; + TextButton gobackbutton; + + public ImportKeysScreen(final LightWallet game) { super(game); - // TODO Auto-generated constructor stub + + uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); + padvalue = 20; + + stage = new Stage(); + Gdx.input.setInputProcessor(stage); + + screenlayout = new Table(); + + logo = new Image(new Texture(Gdx.files.internal("logo.png"))); + //logo.scaleBy(0.02f); + + instruction = "Please enter the full path location of your .keys file to import in the file location field; , " + + "for instance: C:\\Users\\jw\\secretstuff\\wallet.keys or /home/jw/secretstuff/wallet.keys. " + + "Then please enter your password to unlock the wallet. " + + "The wallet keys file will be copied to the local directory and a new binary file will be created. " + + "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); + textcontainer = new Table(); + textcontainer.add(instructionlabel).width(600); + + inputtable = new Table(); + + pathlabel = new Label("Wallet path: ", uiSkin); + pathtext = new TextField("", uiSkin); + + pwlabel = new Label("Password: ", uiSkin); + pwtext = new TextField("", uiSkin); + pwtext.setPasswordMode(true); + pwtext.setPasswordCharacter((char) 42); + + nodelabel = new Label("Node address: ", uiSkin); + nodetext = new TextField(Constants.moneroclubdmn, uiSkin); + + inputtable.add(pathlabel).width(200); + inputtable.add(pathtext).width(400).row(); + inputtable.add(pwlabel).width(200); + inputtable.add(pwtext).width(400).row(); + inputtable.add(nodelabel).width(200); + inputtable.add(nodetext).width(400).row(); + + buttontable = new Table(); + + importbutton = new TextButton("Import!", uiSkin); + importbutton.addListener(new ClickListener() { + @Override + public void clicked (InputEvent event, float x, float y) { + path = pathtext.getText(); + pw = pwtext.getText(); + System.out.println(path + ", " + pw); + ImportWallet(path, pw, game.simplewalletloc); + } + }); + + gobackbutton = new TextButton("Cancel", uiSkin); + gobackbutton.addListener(new ClickListener() { + @Override + public void clicked (InputEvent event, float x, float y) { + game.setScreen(new WizardScreen(game)); + } + }); + + buttontable.add(importbutton).width(150); + buttontable.add(gobackbutton).width(150); + + screenlayout.add(logo).pad(10).width(200).height(50).center().row(); + screenlayout.add(textcontainer).pad(padvalue).row(); + screenlayout.add(inputtable).pad(padvalue).row(); + screenlayout.add(buttontable).pad(padvalue).row(); + + screenlayout.setFillParent(true); + stage.addActor(screenlayout); + + + } + + public void show() { + super.show(); + + } + + public void render(float delta) { + super.render(delta); + + stage.draw(); + stage.act(delta); + + } + + public void dispose() { + super.dispose(); + + } + + public void ImportWallet(String path, String pw, String simplewalletloc) { + + // Initialize variables local to ImportWallet function + int i = 0; + String str = null; + + File file = new File(path); + String fname = file.getName(); + String name = null; + + + // Create success and failure dialogs to show based on outcome + Dialog successdialog = new Dialog("Success!", uiSkin, "dialog") { + public void result(Object obj) { + System.out.println("result "+obj); + } + }; + Label successlabel = new Label("Wallet successfully imported. " + game.walletvalues.getName() + " file is your binary wallet file. " + + game.walletvalues.getName() + ".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 " + game.walletvalues.getName() + "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); + successlabel.setWrap(true); + successdialog.add(successlabel).width(400).row(); + successdialog.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(); + } + }); + successdialog.key(Keys.ENTER, true); //sends "true" when the ENTER key is pressed + + Dialog failuredialog = new Dialog("Utter failure!", uiSkin, "dialog") { + public void result(Object obj) { + System.out.println("result "+obj); + } + }; + Label failurelabel = new Label("Wallet import failed. Click to start over.", uiSkin); + failurelabel.setWrap(true); + failuredialog.add(failurelabel).width(400).row(); + failuredialog.button("Continue", true).addListener(new ClickListener() { + @Override + public void clicked (InputEvent event, float x, float y) { + game.setScreen(new WizardScreen(game)); + uiSkin.dispose(); + stage.dispose(); + } + }); + failuredialog.key(Keys.ENTER, true); //sends "true" when the ENTER key is pressed + + + // Try to parse wallet path for name of wallet and if fail throw failure screen + try { + name = fname.substring(0, fname.lastIndexOf('.')); + } + catch (Exception e) { + failuredialog.show(stage); + e.printStackTrace(); + return; + } + + + try { + Files.copy(file.toPath(), new File(file.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING); + } + catch (IOException e) { + failuredialog.show(stage); + e.printStackTrace(); + return; + } + + + try { + Process tr = Runtime.getRuntime().exec("simplewallet --wallet-file " + 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); + if (str.contains("Opened wallet:")) { + game.walletvalues.setAddress(str.split("wallet: ")[1]); + } + i += 1; + if (i > 5 && str.contains("****")) { + break; + } + } + wr.write( "viewkey\n" ); + wr.flush(); + + str = rd.readLine(); + System.out.println(i + " " + str.split(": ")[1]); + i += 1; + game.walletvalues.setViewkey(str.split(": ")[1]); + + wr.write( "seed\n" ); + wr.flush(); + + str = rd.readLine(); + System.out.println(i + " " + str.substring(str.indexOf(":"), str.length())); + i += 1; + game.walletvalues.setSeed(str.substring(str.indexOf(":"), str.length())); + + wr.write( "exit\n" ); + wr.flush(); + + game.walletvalues.setName(name); + game.walletvalues.setPw(pw); + game.walletvalues.setNode(nodetext.getText());; + + 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(); + + successdialog.show(stage); + } + + catch (IOException e) { + System.out.println("exception happened - here's what I know: "); + e.printStackTrace(); + failuredialog.show(stage); + return; + } + + Gdx.app.log(LightWallet.LOG, "Address is: " + game.walletvalues.getAddress()); + Gdx.app.log(LightWallet.LOG, "Seed is: " + game.walletvalues.getSeed()); } } diff --git a/core/src/com/jw/lightwallet/screens/MainScreen.java b/core/src/com/jw/lightwallet/screens/MainScreen.java index 65a866b..fe9d68a 100644 --- a/core/src/com/jw/lightwallet/screens/MainScreen.java +++ b/core/src/com/jw/lightwallet/screens/MainScreen.java @@ -192,11 +192,14 @@ public class MainScreen extends AbstractScreen { String queuepoll = wq.poll(); Gdx.app.log(LightWallet.LOG, "Queue result: " + queuepoll); try{ - - if (queuepoll != null && queuepoll.contains("height")) { + 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()); + } } catch (NullPointerException e){e.printStackTrace();} balancerpc.getinfo(balancevalues); diff --git a/core/src/com/jw/lightwallet/screens/TransactionView.java b/core/src/com/jw/lightwallet/screens/TransactionView.java index 4b582db..5b78385 100644 --- a/core/src/com/jw/lightwallet/screens/TransactionView.java +++ b/core/src/com/jw/lightwallet/screens/TransactionView.java @@ -31,27 +31,30 @@ public class TransactionView { Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); txlayout = new Table(); - padvalue = 15; + padvalue = 15; - addresslabel = new Label("Send to address: ", uiSkin); - addressvalue = new TextField("", uiSkin); - txlayout.add(addresslabel).pad(padvalue); - txlayout.add(addressvalue).pad(padvalue).row(); + addresslabel = new Label("Send to address: ", uiSkin); + addressvalue = new TextField("", uiSkin); + txlayout.add(addresslabel).pad(padvalue).width(150); + txlayout.add(addressvalue).pad(padvalue).width(650).row(); - amountlabel = new Label("Send amount XMR: ", uiSkin); - amountvalue = new TextField("", uiSkin); - txlayout.add(amountlabel).pad(padvalue); - txlayout.add(amountvalue).pad(padvalue).row(); + amountlabel = new Label("Send amount XMR: ", uiSkin); + amountvalue = new TextField("", uiSkin); + txlayout.add(amountlabel).pad(padvalue).width(150); + txlayout.add(amountvalue).pad(padvalue).width(650).row(); - mixinlabel = new Label("Mixin level: ", uiSkin); - mixinvalue = new TextField("", uiSkin); - txlayout.add(mixinlabel).pad(padvalue); - txlayout.add(mixinvalue).pad(padvalue).row(); + mixinlabel = new Label("Mixin level: ", uiSkin); + mixinvalue = new TextField("", uiSkin); + txlayout.add(mixinlabel).pad(padvalue).width(150); + txlayout.add(mixinvalue).pad(padvalue).width(650).row(); - idlabel = new Label("Payment id: ", uiSkin); + idlabel = new Label("Payment id: ", uiSkin); idvalue = new TextField("", uiSkin); - txlayout.add(idlabel).pad(padvalue); - txlayout.add(idvalue).pad(padvalue).row(); + txlayout.add(idlabel).pad(padvalue).width(150); + txlayout.add(idvalue).pad(padvalue).width(650).row(); + + sendbtn = new TextButton("Payola!", uiSkin); + txlayout.add(sendbtn).row(); } diff --git a/core/src/com/jw/lightwallet/screens/WalletView.java b/core/src/com/jw/lightwallet/screens/WalletView.java index 50580d5..564efe2 100644 --- a/core/src/com/jw/lightwallet/screens/WalletView.java +++ b/core/src/com/jw/lightwallet/screens/WalletView.java @@ -1,9 +1,12 @@ package com.jw.lightwallet.screens; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.jw.lightwallet.LightWallet; public class WalletView { @@ -12,7 +15,7 @@ public class WalletView { Label namelabel; Label namevalue; - Label addresslabel; + TextButton addresslabel; Label addressvalue; Label synclabel; Label syncvalue; @@ -24,7 +27,7 @@ public class WalletView { int padvalue; - public WalletView (LightWallet game) { + public WalletView (final LightWallet game) { Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); @@ -36,9 +39,9 @@ public class WalletView { walletlayout.add(namelabel).pad(padvalue); walletlayout.add(namevalue).pad(padvalue).row(); - addresslabel = new Label("Address: ", uiSkin); + addresslabel = new TextButton("Address (click to copy): ", uiSkin); addressvalue = new Label(game.walletvalues.getAddress(), uiSkin); - addressvalue.setFontScale(0.2f, 0.2f); + addressvalue.setFontScale(0.6f, 0.6f); walletlayout.add(addresslabel).pad(padvalue); walletlayout.add(addressvalue).pad(padvalue).row(); @@ -57,5 +60,12 @@ public class WalletView { walletlayout.add(lockedlabel).pad(padvalue); walletlayout.add(lockedvalue).pad(padvalue).row(); + addresslabel.addListener(new ClickListener() { + @Override + public void clicked (InputEvent event, float x, float y) { + Gdx.app.getClipboard().setContents(game.walletvalues.getAddress()); + } + }); + } } diff --git a/desktop/ffff b/desktop/ffff deleted file mode 100644 index a093c6b..0000000 --- a/desktop/ffff +++ /dev/null @@ -1,4 +0,0 @@ -hl›qf¬’ŠbnÛbÊkÑá”KÌ»ýœàšÝ.Êbõ/¸¿-kT/FVÚzK0ðæ›i‹â&=rÓà®z›o]o9 -=Ö^/›=Šl(–V©–¾oDéG`«ê· ðGyÒÁƒ -ŽßCaöcUÞ4ÉùûœYñ’–×rA{*@×û(”9ͽ×A¥.7«ò_n¯â ~ -ìÌúéÿ×H�)7Û�‹�0_³Šñƒz�“¢{aÀ$ÿ>†?;Š[ ö뎜ÐÑÿ·Ç – å;)1šiTÞêÆïUó‰WæÌOzWC‚ÓPLÐ'·™ùù@ÍϳÍxîõrXËEùvÖ˜�Òªz<ÀÐ�³[ƒ£ \ No newline at end of file diff --git a/desktop/ffff.address.txt b/desktop/ffff.address.txt deleted file mode 100644 index 9ff727c..0000000 --- a/desktop/ffff.address.txt +++ /dev/null @@ -1 +0,0 @@ -46CPGcWMGHViB2f1jitYvtUf9qitPobAZRSJteqe7Nrx9PvAZBGrEExCyoG4LHGkEoZ9Yyez1xety7dkDN7N99Jx4dfX5C6 \ No newline at end of file diff --git a/desktop/ffff.keys b/desktop/ffff.keys deleted file mode 100644 index 2007faf281f25798458df355ad7d79c39456701f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 577 zcmV-H0>1sVTE~uwqLL-jFs@U#nBJTc_U#hI`iE`{SP?!7w$4p3TRPAXbl>bHrxXtjq5ZZ6h+na zpK%AnXi3<$zDb_Ry!!vTmMvmWuqAwXWFA+W~D(Y9v zsjaeRSIe&|igI^O)y@zj`?tS}&2g&=|2Ym9DFh{|tlh+290>R;X|xR(TsJZkM?hnU zW1_nOt3$XoIZ;;qKKxw|q&?P+?v>$UEiMF~qZ_!kELgzODs35RPgzwlb=^%*URreE zJmP10-agwn$>1_tP9@_Jbd31O6cjbV{vmy_3m}X;%NAna=m3~{g+{NxG7fTe`IhA) zg-C5)?=dhz`L_-)C|h_#TQ){1*53MH#LgAQkC8CCR1=w+J8?xLfsXzy(@f0T33(QE zwP#1AFc;>Q0~iWy%fVzTAmA8FnyD=AHWU&~%RW_+x- zT4Yqh*wkWi#Aq#(XD8$g3I1|sc_