diff options
author | Jeffrey Wilcke <obscuren@users.noreply.github.com> | 2014-07-07 16:58:42 +0800 |
---|---|---|
committer | Jeffrey Wilcke <obscuren@users.noreply.github.com> | 2014-07-07 16:58:42 +0800 |
commit | 0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354 (patch) | |
tree | 0399c40eff878c381413d96e2e304441edff775d /ethereal | |
parent | f9e2e5276f64d5a9c93fb55adda06365be14c26a (diff) | |
download | go-tangerine-0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354.tar go-tangerine-0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354.tar.gz go-tangerine-0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354.tar.bz2 go-tangerine-0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354.tar.lz go-tangerine-0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354.tar.xz go-tangerine-0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354.tar.zst go-tangerine-0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354.zip |
Revert "ethreact - Feature/ethutil refactor"
Diffstat (limited to 'ethereal')
-rw-r--r-- | ethereal/ext_app.go | 9 | ||||
-rw-r--r-- | ethereal/gui.go | 107 |
2 files changed, 56 insertions, 60 deletions
diff --git a/ethereal/ext_app.go b/ethereal/ext_app.go index c02f5ccb3..17c342a1b 100644 --- a/ethereal/ext_app.go +++ b/ethereal/ext_app.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethpub" - "github.com/ethereum/eth-go/ethreact" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" ) @@ -25,8 +24,8 @@ type AppContainer interface { type ExtApplication struct { *ethpub.PEthereum - blockChan chan ethreact.Event - changeChan chan ethreact.Event + blockChan chan ethutil.React + changeChan chan ethutil.React quitChan chan bool watcherQuitChan chan bool @@ -38,8 +37,8 @@ type ExtApplication struct { func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { app := &ExtApplication{ ethpub.NewPEthereum(lib.eth), - make(chan ethreact.Event), - make(chan ethreact.Event), + make(chan ethutil.React, 1), + make(chan ethutil.React, 1), make(chan bool), make(chan bool), container, diff --git a/ethereal/gui.go b/ethereal/gui.go index 2bad90361..9f28045f8 100644 --- a/ethereal/gui.go +++ b/ethereal/gui.go @@ -8,7 +8,6 @@ import ( "github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethlog" "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" @@ -144,7 +143,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { gui.readPreviousTransactions() gui.setPeerInfo() - gui.update() + go gui.update() return win, nil } @@ -267,10 +266,20 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { func (gui *Gui) update() { reactor := gui.eth.Reactor() - blockChan := make(chan ethreact.Event) - txChan := make(chan ethreact.Event) - objectChan := make(chan ethreact.Event) - peerChan := make(chan ethreact.Event) + blockChan := make(chan ethutil.React, 1) + txChan := make(chan ethutil.React, 1) + objectChan := make(chan ethutil.React, 1) + peerChan := make(chan ethutil.React, 1) + + reactor.Subscribe("newBlock", blockChan) + reactor.Subscribe("newTx:pre", txChan) + reactor.Subscribe("newTx:post", txChan) + + nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg() + if nameReg != nil { + reactor.Subscribe("object:"+string(nameReg.Address()), objectChan) + } + reactor.Subscribe("peerList", peerChan) ticker := time.NewTicker(5 * time.Second) @@ -279,66 +288,54 @@ func (gui *Gui) update() { unconfirmedFunds := new(big.Int) gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount))) - 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()).Amount, nil) - } + 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()).Amount, nil) + } - case txMsg := <-txChan: - tx := txMsg.Resource.(*ethchain.Transaction) + case txMsg := <-txChan: + tx := txMsg.Resource.(*ethchain.Transaction) - if txMsg.Name == "newTx:pre" { - object := state.GetAccount(gui.address()) + if txMsg.Event == "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()) + 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()) + 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()) - unconfirmedFunds.Add(unconfirmedFunds, tx.Value) - } + unconfirmedFunds.Add(unconfirmedFunds, tx.Value) + } - gui.setWalletValue(object.Amount, 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) - } + gui.setWalletValue(object.Amount, 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) + } - gui.setWalletValue(object.Amount, nil) + gui.setWalletValue(object.Amount, nil) - state.UpdateStateObject(object) - } - case <-objectChan: - gui.loadAddressBook() - case <-peerChan: - gui.setPeerInfo() - case <-ticker.C: - gui.setPeerInfo() + state.UpdateStateObject(object) } + case <-objectChan: + gui.loadAddressBook() + case <-peerChan: + gui.setPeerInfo() + case <-ticker.C: + gui.setPeerInfo() } - }() - reactor.Subscribe("newBlock", blockChan) - reactor.Subscribe("newTx:pre", txChan) - reactor.Subscribe("newTx:post", txChan) - - 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() { |