mirror of
https://github.com/jwinterm/LightWallet2.git
synced 2026-10-17 05:21:26 +02:00
Got import wallet by keys working.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ÀÐ�³[ƒ£
|
||||
@@ -1 +0,0 @@
|
||||
46CPGcWMGHViB2f1jitYvtUf9qitPobAZRSJteqe7Nrx9PvAZBGrEExCyoG4LHGkEoZ9Yyez1xety7dkDN7N99Jx4dfX5C6
|
||||
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
Wallet name: ffff
|
||||
Wallet pw: f
|
||||
Wallet address: 46CPGcWMGHViB2f1jitYvtUf9qitPobAZRSJteqe7Nrx9PvAZBGrEExCyoG4LHGkEoZ9Yyez1xety7dkDN7N99Jx4dfX5C6
|
||||
Wallet view key: eb45bd3b2d7949facc10a573f4bf302772a1bb192ca9f47ccfe41a6d78b45708
|
||||
Wallet seed: jackets soprano goes auctions inbound ailments fruit rustledaimless tilt hawk hobby stylishly people fever muffinvogue emails deodorant oilfield dabbing idled inundate joking muffin
|
||||
@@ -1,4 +0,0 @@
|
||||
Wallet name: ffff
|
||||
Wallet address: 46CPGcWMGHViB2f1jitYvtUf9qitPobAZRSJteqe7Nrx9PvAZBGrEExCyoG4LHGkEoZ9Yyez1xety7dkDN7N99Jx4dfX5C6
|
||||
Wallet view key: eb45bd3b2d7949facc10a573f4bf302772a1bb192ca9f47ccfe41a6d78b45708
|
||||
Node address: http://node.monoerclub.com/json_rpc:8880
|
||||
Reference in New Issue
Block a user