aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal/gui.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethereal/gui.go')
-rw-r--r--ethereal/gui.go158
1 files changed, 80 insertions, 78 deletions
diff --git a/ethereal/gui.go b/ethereal/gui.go
index 31d4248b2..61f7b1099 100644
--- a/ethereal/gui.go
+++ b/ethereal/gui.go
@@ -14,6 +14,7 @@ import (
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethminer"
"github.com/ethereum/eth-go/ethpub"
+ "github.com/ethereum/eth-go/ethreact"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/go-ethereum/utils"
@@ -151,7 +152,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
gui.readPreviousTransactions()
}()
- go gui.update()
+ gui.update()
return win, nil
}
@@ -284,30 +285,16 @@ func (self *Gui) getObjectByName(objectName string) qml.Object {
// Simple go routine function that updates the list of peers in the GUI
func (gui *Gui) update() {
- reactor := gui.eth.Reactor()
var (
- blockChan = make(chan ethutil.React, 1)
- txChan = make(chan ethutil.React, 1)
- objectChan = make(chan ethutil.React, 1)
- peerChan = make(chan ethutil.React, 1)
- chainSyncChan = make(chan ethutil.React, 1)
- miningChan = make(chan ethutil.React, 1)
+ blockChan = make(chan ethreact.Event, 100)
+ txChan = make(chan ethreact.Event, 100)
+ objectChan = make(chan ethreact.Event, 100)
+ peerChan = make(chan ethreact.Event, 100)
+ chainSyncChan = make(chan ethreact.Event, 100)
+ miningChan = make(chan ethreact.Event, 100)
)
- reactor.Subscribe("newBlock", blockChan)
- reactor.Subscribe("newTx:pre", txChan)
- reactor.Subscribe("newTx:post", txChan)
- reactor.Subscribe("chainSync", chainSyncChan)
- reactor.Subscribe("miner:start", miningChan)
- reactor.Subscribe("miner:stop", miningChan)
-
- nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
- if nameReg != nil {
- reactor.Subscribe("object:"+string(nameReg.Address()), objectChan)
- }
- reactor.Subscribe("peerList", peerChan)
-
peerUpdateTicker := time.NewTicker(5 * time.Second)
generalUpdateTicker := time.NewTicker(1 * time.Second)
@@ -319,74 +306,89 @@ func (gui *Gui) update() {
lastBlockLabel := gui.getObjectByName("lastBlockLabel")
- for {
- select {
- case b := <-blockChan:
- block := b.Resource.(*ethchain.Block)
- gui.processBlock(block, false)
- if bytes.Compare(block.Coinbase, gui.address()) == 0 {
- gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Balance, nil)
- }
-
- case txMsg := <-txChan:
- tx := txMsg.Resource.(*ethchain.Transaction)
+ go func() {
+ for {
+ select {
+ case b := <-blockChan:
+ block := b.Resource.(*ethchain.Block)
+ gui.processBlock(block, false)
+ if bytes.Compare(block.Coinbase, gui.address()) == 0 {
+ gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Balance, nil)
+ }
+ case txMsg := <-txChan:
+ tx := txMsg.Resource.(*ethchain.Transaction)
- if txMsg.Event == "newTx:pre" {
- object := state.GetAccount(gui.address())
+ if txMsg.Name == "newTx:pre" {
+ object := state.GetAccount(gui.address())
- if bytes.Compare(tx.Sender(), gui.address()) == 0 {
- gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send")
- gui.txDb.Put(tx.Hash(), tx.RlpEncode())
-
- unconfirmedFunds.Sub(unconfirmedFunds, tx.Value)
- } else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
- gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv")
- gui.txDb.Put(tx.Hash(), tx.RlpEncode())
+ if bytes.Compare(tx.Sender(), gui.address()) == 0 {
+ gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send")
+ gui.txDb.Put(tx.Hash(), tx.RlpEncode())
- unconfirmedFunds.Add(unconfirmedFunds, tx.Value)
- }
+ unconfirmedFunds.Sub(unconfirmedFunds, tx.Value)
+ } else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
+ gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv")
+ gui.txDb.Put(tx.Hash(), tx.RlpEncode())
- gui.setWalletValue(object.Balance, unconfirmedFunds)
- } else {
- object := state.GetAccount(gui.address())
- if bytes.Compare(tx.Sender(), gui.address()) == 0 {
- object.SubAmount(tx.Value)
- } else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
- object.AddAmount(tx.Value)
- }
+ unconfirmedFunds.Add(unconfirmedFunds, tx.Value)
+ }
- gui.setWalletValue(object.Balance, nil)
+ gui.setWalletValue(object.Balance, unconfirmedFunds)
+ } else {
+ object := state.GetAccount(gui.address())
+ if bytes.Compare(tx.Sender(), gui.address()) == 0 {
+ object.SubAmount(tx.Value)
+ } else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
+ object.AddAmount(tx.Value)
+ }
- state.UpdateStateObject(object)
- }
- case msg := <-chainSyncChan:
- sync := msg.Resource.(bool)
- gui.win.Root().ObjectByName("syncProgressIndicator").Set("visible", sync)
-
- case <-objectChan:
- gui.loadAddressBook()
- case <-peerChan:
- gui.setPeerInfo()
- case <-peerUpdateTicker.C:
- gui.setPeerInfo()
- case msg := <-miningChan:
- if msg.Event == "miner:start" {
- gui.miner = msg.Resource.(*ethminer.Miner)
- } else {
- gui.miner = nil
- }
+ gui.setWalletValue(object.Balance, nil)
- case <-generalUpdateTicker.C:
- statusText := "#" + gui.eth.BlockChain().CurrentBlock.Number.String()
- if gui.miner != nil {
- pow := gui.miner.GetPow()
- if pow.GetHashrate() != 0 {
- statusText = "Mining @ " + strconv.FormatInt(pow.GetHashrate(), 10) + "Khash - " + statusText
+ state.UpdateStateObject(object)
+ }
+ case msg := <-chainSyncChan:
+ sync := msg.Resource.(bool)
+ gui.win.Root().ObjectByName("syncProgressIndicator").Set("visible", sync)
+
+ case <-objectChan:
+ gui.loadAddressBook()
+ case <-peerChan:
+ gui.setPeerInfo()
+ case <-peerUpdateTicker.C:
+ gui.setPeerInfo()
+ case msg := <-miningChan:
+ if msg.Name == "miner:start" {
+ gui.miner = msg.Resource.(*ethminer.Miner)
+ } else {
+ gui.miner = nil
+ }
+ case <-generalUpdateTicker.C:
+ statusText := "#" + gui.eth.BlockChain().CurrentBlock.Number.String()
+ if gui.miner != nil {
+ pow := gui.miner.GetPow()
+ if pow.GetHashrate() != 0 {
+ statusText = "Mining @ " + strconv.FormatInt(pow.GetHashrate(), 10) + "Khash - " + statusText
+ }
}
+ lastBlockLabel.Set("text", statusText)
}
- lastBlockLabel.Set("text", statusText)
}
+ }()
+
+ reactor := gui.eth.Reactor()
+
+ reactor.Subscribe("newBlock", blockChan)
+ reactor.Subscribe("newTx:pre", txChan)
+ reactor.Subscribe("newTx:post", txChan)
+ reactor.Subscribe("chainSync", chainSyncChan)
+ reactor.Subscribe("miner:start", miningChan)
+ reactor.Subscribe("miner:stop", miningChan)
+
+ nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
+ if nameReg != nil {
+ reactor.Subscribe("object:"+string(nameReg.Address()), objectChan)
}
+ reactor.Subscribe("peerList", peerChan)
}
func (gui *Gui) setPeerInfo() {