Merge pull request #101 from ethereum/revert-100-feature/ethutil-refactor

Revert "ethreact - Feature/ethutil refactor"
This commit is contained in:
Jeffrey Wilcke 2014-07-07 10:59:30 +02:00
commit 0360e60dd5
3 changed files with 72 additions and 76 deletions

View File

@ -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,

View File

@ -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,7 +288,6 @@ 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:
@ -292,7 +300,7 @@ func (gui *Gui) update() {
case txMsg := <-txChan:
tx := txMsg.Resource.(*ethchain.Transaction)
if txMsg.Name == "newTx:pre" {
if txMsg.Event == "newTx:pre" {
object := state.GetAccount(gui.address())
if bytes.Compare(tx.Sender(), gui.address()) == 0 {
@ -328,17 +336,6 @@ func (gui *Gui) update() {
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() {

View File

@ -6,7 +6,6 @@ import (
"github.com/ethereum/eth-go/ethchain"
"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/go-ethereum/utils"
"github.com/obscuren/otto"
@ -23,8 +22,8 @@ type JSRE struct {
vm *otto.Otto
lib *ethpub.PEthereum
blockChan chan ethreact.Event
changeChan chan ethreact.Event
blockChan chan ethutil.React
changeChan chan ethutil.React
quitChan chan bool
objectCb map[string][]otto.Value
@ -49,8 +48,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
ethereum,
otto.New(),
ethpub.NewPEthereum(ethereum),
make(chan ethreact.Event),
make(chan ethreact.Event),
make(chan ethutil.React, 1),
make(chan ethutil.React, 1),
make(chan bool),
make(map[string][]otto.Value),
}
@ -64,9 +63,6 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
// We have to make sure that, whoever calls this, calls "Stop"
go re.mainLoop()
// Subscribe to events
reactor := ethereum.Reactor()
reactor.Subscribe("newBlock", re.blockChan)
re.Bind("eth", &JSEthereum{re.lib, re.vm})
@ -112,6 +108,10 @@ func (self *JSRE) Stop() {
}
func (self *JSRE) mainLoop() {
// Subscribe to events
reactor := self.ethereum.Reactor()
reactor.Subscribe("newBlock", self.blockChan)
out:
for {
select {