diff options
Diffstat (limited to 'ethereal/ui/gui.go')
-rw-r--r-- | ethereal/ui/gui.go | 91 |
1 files changed, 36 insertions, 55 deletions
diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 7f84272d6..aa0364998 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -42,15 +42,11 @@ func New(ethereum *eth.Ethereum) *Gui { panic(err) } - 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) + if ethutil.GetKeyRing().Len() != 0 { + addr = ethutil.GetKeyRing().Get(0).Address() } pub := ethpub.NewPEthereum(ethereum) @@ -59,6 +55,8 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { + const version = "0.5.0 RC6" + defer gui.txDb.Close() // Register ethereum functions @@ -68,7 +66,7 @@ func (gui *Gui) Start(assetPath string) { Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) - ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.5.0 RC4")) + ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version)) ethutil.Config.Log.Infoln("[GUI] Starting GUI") // Create a new QML engine gui.engine = qml.NewEngine() @@ -81,43 +79,6 @@ func (gui *Gui) Start(assetPath string) { // Load the main QML interface data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) - /* - var err error - var component qml.Object - firstRun := len(data) == 0 - - if firstRun { - component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/first_run.qml")) - } else { - component, err = gui.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) - } - - gui.win = component.CreateWindow(nil) - uiLib.win = gui.win - db := &Debugger{gui.win, make(chan bool)} - gui.lib.Db = db - uiLib.Db = db - - // Add the ui as a log system so we can log directly to the UGI - ethutil.Config.Log.AddLogSystem(gui) - - // Loads previous blocks - if firstRun == false { - go gui.setInitialBlockChain() - go gui.readPreviousTransactions() - go gui.update() - } - - gui.win.Show() - gui.win.Wait() - - gui.eth.Stop() - */ var win *qml.Window var err error @@ -199,8 +160,29 @@ func (gui *Gui) processBlock(block *ethchain.Block) { gui.win.Root().Call("addBlock", ethpub.NewPBlock(block)) } +func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { + var str string + if unconfirmedFunds != nil { + pos := "+" + if unconfirmedFunds.Cmp(big.NewInt(0)) >= 0 { + pos = "-" + } + val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds))) + str = fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(amount), pos, val) + } else { + str = fmt.Sprintf("%v", ethutil.CurrencyToString(amount)) + } + + gui.win.Root().Call("setWalletValue", str) +} + // Simple go routine function that updates the list of peers in the GUI func (gui *Gui) update() { + blockChan := make(chan ethutil.React, 1) + reactor := gui.eth.Reactor() + + reactor.Subscribe("newBlock", blockChan) + txChan := make(chan ethchain.TxMsg, 1) gui.eth.TxPool().Subscribe(txChan) @@ -211,6 +193,12 @@ func (gui *Gui) update() { for { select { + case b := <-blockChan: + block := b.Resource.(*ethchain.Block) + if bytes.Compare(block.Coinbase, gui.addr) == 0 { + gui.setWalletValue(gui.eth.StateManager().ProcState().GetAccount(gui.addr).Amount, nil) + } + case txMsg := <-txChan: tx := txMsg.Tx @@ -232,14 +220,7 @@ func (gui *Gui) update() { unconfirmedFunds.Add(unconfirmedFunds, tx.Value) } - pos := "+" - if unconfirmedFunds.Cmp(big.NewInt(0)) >= 0 { - pos = "-" - } - val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds))) - str := fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(object.Amount), pos, val) - - gui.win.Root().Call("setWalletValue", str) + gui.setWalletValue(object.Amount, unconfirmedFunds) } else { object := state.GetAccount(gui.addr) if bytes.Compare(tx.Sender(), gui.addr) == 0 { @@ -248,7 +229,7 @@ func (gui *Gui) update() { object.AddAmount(tx.Value) } - gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(object.Amount))) + gui.setWalletValue(object.Amount, nil) state.SetStateObject(object) } @@ -274,13 +255,13 @@ func (gui *Gui) Printf(format string, v ...interface{}) { } func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { - keyPair := ethutil.Config.Db.GetKeys()[0] + keyPair := ethutil.GetKeyRing().Get(0) return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data) } func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { - keyPair := ethutil.Config.Db.GetKeys()[0] + keyPair := ethutil.GetKeyRing().Get(0) mainInput, initInput := mutan.PreParse(data) |