aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal/ui
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-12 01:36:27 +0800
committerobscuren <geffobscura@gmail.com>2014-04-12 01:36:27 +0800
commit710bbed1a2c508bcfa48f9a56b55342d4cdc9971 (patch)
tree008eb4bb2d2369c58aecb97feaa7d941531193c1 /ethereal/ui
parenta9a65859134b93cfe2818fdad290530822d6a7b4 (diff)
parent4d18798468c82650ddc809a03a187999f2237813 (diff)
downloadgo-tangerine-710bbed1a2c508bcfa48f9a56b55342d4cdc9971.tar
go-tangerine-710bbed1a2c508bcfa48f9a56b55342d4cdc9971.tar.gz
go-tangerine-710bbed1a2c508bcfa48f9a56b55342d4cdc9971.tar.bz2
go-tangerine-710bbed1a2c508bcfa48f9a56b55342d4cdc9971.tar.lz
go-tangerine-710bbed1a2c508bcfa48f9a56b55342d4cdc9971.tar.xz
go-tangerine-710bbed1a2c508bcfa48f9a56b55342d4cdc9971.tar.zst
go-tangerine-710bbed1a2c508bcfa48f9a56b55342d4cdc9971.zip
Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop
Diffstat (limited to 'ethereal/ui')
-rw-r--r--ethereal/ui/gui.go33
-rw-r--r--ethereal/ui/library.go40
2 files changed, 62 insertions, 11 deletions
diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go
index 32e7edbdc..fa4a5c833 100644
--- a/ethereal/ui/gui.go
+++ b/ethereal/ui/gui.go
@@ -63,10 +63,16 @@ func New(ethereum *eth.Ethereum) *Gui {
panic(err)
}
- key := ethutil.Config.Db.GetKeys()[0]
- addr := key.Address()
-
- ethereum.StateManager().WatchAddr(addr)
+ 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)
+ }
return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr}
}
@@ -93,7 +99,16 @@ 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'")
panic(err)
@@ -111,9 +126,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()
diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go
index 13400a2a0..08f99e7db 100644
--- a/ethereal/ui/library.go
+++ b/ethereal/ui/library.go
@@ -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 := &ethutil.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
@@ -35,9 +63,15 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin
var tx *ethchain.Transaction
// Compile and assemble the given data
if contractCreation {
- asm, err := mutan.Compile(strings.NewReader(data), false)
- if err != nil {
- return "", err
+ asm, errors := mutan.Compile(strings.NewReader(data), false)
+ if len(errors) > 0 {
+ var errs string
+ for _, er := range errors {
+ if er != nil {
+ errs += er.Error()
+ }
+ }
+ return "", fmt.Errorf(errs)
}
code := ethutil.Assemble(asm...)