Implemented key importing/generation for the GUI
This commit is contained in:
@@ -53,7 +53,6 @@ type Gui struct {
|
||||
txDb *ethdb.LDBDatabase
|
||||
|
||||
addr []byte
|
||||
|
||||
}
|
||||
|
||||
// Create GUI, but doesn't start it
|
||||
@@ -64,10 +63,16 @@ func New(ethereum *eth.Ethereum) *Gui {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
key := ethutil.Config.Db.GetKeys()[0]
|
||||
addr := key.Address()
|
||||
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
||||
// On first run we won't have any keys yet, so this would crash.
|
||||
// Therefor we check if we are ready to actually start this process
|
||||
var addr []byte
|
||||
if len(data) > 0 {
|
||||
key := ethutil.Config.Db.GetKeys()[0]
|
||||
addr = key.Address()
|
||||
|
||||
ethereum.StateManager().WatchAddr(addr)
|
||||
ethereum.StateManager().WatchAddr(addr)
|
||||
}
|
||||
|
||||
return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr}
|
||||
}
|
||||
@@ -94,9 +99,18 @@ func (ui *Gui) Start(assetPath string) {
|
||||
context.SetVar("ui", uiLib)
|
||||
|
||||
// Load the main QML interface
|
||||
component, err := ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml"))
|
||||
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
||||
var err error
|
||||
var component qml.Object
|
||||
firstRun := len(data) == 0
|
||||
|
||||
if firstRun {
|
||||
component, err = ui.engine.LoadFile(uiLib.AssetPath("qml/first_run.qml"))
|
||||
} else {
|
||||
component, err = ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml"))
|
||||
}
|
||||
if err != nil {
|
||||
ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'")
|
||||
ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'")
|
||||
panic(err)
|
||||
}
|
||||
ui.engine.LoadFile(uiLib.AssetPath("qml/transactions.qml"))
|
||||
@@ -111,9 +125,11 @@ func (ui *Gui) Start(assetPath string) {
|
||||
ethutil.Config.Log.AddLogSystem(ui)
|
||||
|
||||
// Loads previous blocks
|
||||
go ui.setInitialBlockChain()
|
||||
go ui.readPreviousTransactions()
|
||||
go ui.update()
|
||||
if firstRun == false {
|
||||
go ui.setInitialBlockChain()
|
||||
go ui.readPreviousTransactions()
|
||||
go ui.update()
|
||||
}
|
||||
|
||||
ui.win.Show()
|
||||
ui.win.Wait()
|
||||
|
@@ -5,7 +5,9 @@ import (
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethchain"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"github.com/ethereum/go-ethereum/utils"
|
||||
"github.com/obscuren/mutan"
|
||||
"github.com/obscuren/secp256k1-go"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -15,6 +17,32 @@ type EthLib struct {
|
||||
txPool *ethchain.TxPool
|
||||
}
|
||||
|
||||
func (lib *EthLib) ImportAndSetPrivKey(privKey string) bool {
|
||||
fmt.Println(privKey)
|
||||
mnemonic := strings.Split(privKey, " ")
|
||||
if len(mnemonic) == 24 {
|
||||
fmt.Println("Got mnemonic key, importing.")
|
||||
key := ethutil.MnemonicDecode(mnemonic)
|
||||
utils.ImportPrivateKey(key)
|
||||
} else if len(mnemonic) == 1 {
|
||||
fmt.Println("Got hex key, importing.")
|
||||
utils.ImportPrivateKey(privKey)
|
||||
} else {
|
||||
fmt.Println("Did not recognise format, exiting.")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) {
|
||||
pub, prv := secp256k1.GenerateKeyPair()
|
||||
pair := ðutil.Key{PrivateKey: prv, PublicKey: pub}
|
||||
ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode())
|
||||
mne := ethutil.MnemonicEncode(ethutil.Hex(prv))
|
||||
mnemonicString := strings.Join(mne, " ")
|
||||
return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub)
|
||||
}
|
||||
|
||||
func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) {
|
||||
var hash []byte
|
||||
var contractCreation bool
|
||||
|
Reference in New Issue
Block a user