use ethreact.Event, unbuffered event channels, subscribe after loop reading from channel starts
This commit is contained in:
		@@ -4,6 +4,7 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethchain"
 | 
						"github.com/ethereum/eth-go/ethchain"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethpub"
 | 
						"github.com/ethereum/eth-go/ethpub"
 | 
				
			||||||
 | 
						"github.com/ethereum/eth-go/ethreact"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethutil"
 | 
						"github.com/ethereum/eth-go/ethutil"
 | 
				
			||||||
	"github.com/go-qml/qml"
 | 
						"github.com/go-qml/qml"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -24,8 +25,8 @@ type AppContainer interface {
 | 
				
			|||||||
type ExtApplication struct {
 | 
					type ExtApplication struct {
 | 
				
			||||||
	*ethpub.PEthereum
 | 
						*ethpub.PEthereum
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	blockChan       chan ethutil.React
 | 
						blockChan       chan ethreact.Event
 | 
				
			||||||
	changeChan      chan ethutil.React
 | 
						changeChan      chan ethreact.Event
 | 
				
			||||||
	quitChan        chan bool
 | 
						quitChan        chan bool
 | 
				
			||||||
	watcherQuitChan chan bool
 | 
						watcherQuitChan chan bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -37,8 +38,8 @@ type ExtApplication struct {
 | 
				
			|||||||
func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
 | 
					func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
 | 
				
			||||||
	app := &ExtApplication{
 | 
						app := &ExtApplication{
 | 
				
			||||||
		ethpub.NewPEthereum(lib.eth),
 | 
							ethpub.NewPEthereum(lib.eth),
 | 
				
			||||||
		make(chan ethutil.React, 1),
 | 
							make(chan ethreact.Event),
 | 
				
			||||||
		make(chan ethutil.React, 1),
 | 
							make(chan ethreact.Event),
 | 
				
			||||||
		make(chan bool),
 | 
							make(chan bool),
 | 
				
			||||||
		make(chan bool),
 | 
							make(chan bool),
 | 
				
			||||||
		container,
 | 
							container,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ import (
 | 
				
			|||||||
	"github.com/ethereum/eth-go/ethdb"
 | 
						"github.com/ethereum/eth-go/ethdb"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethlog"
 | 
						"github.com/ethereum/eth-go/ethlog"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethpub"
 | 
						"github.com/ethereum/eth-go/ethpub"
 | 
				
			||||||
 | 
						"github.com/ethereum/eth-go/ethreact"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethutil"
 | 
						"github.com/ethereum/eth-go/ethutil"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethwire"
 | 
						"github.com/ethereum/eth-go/ethwire"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/utils"
 | 
						"github.com/ethereum/go-ethereum/utils"
 | 
				
			||||||
@@ -143,7 +144,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
 | 
				
			|||||||
	gui.readPreviousTransactions()
 | 
						gui.readPreviousTransactions()
 | 
				
			||||||
	gui.setPeerInfo()
 | 
						gui.setPeerInfo()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	go gui.update()
 | 
						gui.update()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return win, nil
 | 
						return win, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -266,20 +267,10 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
 | 
				
			|||||||
func (gui *Gui) update() {
 | 
					func (gui *Gui) update() {
 | 
				
			||||||
	reactor := gui.eth.Reactor()
 | 
						reactor := gui.eth.Reactor()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	blockChan := make(chan ethutil.React, 1)
 | 
						blockChan := make(chan ethreact.Event)
 | 
				
			||||||
	txChan := make(chan ethutil.React, 1)
 | 
						txChan := make(chan ethreact.Event)
 | 
				
			||||||
	objectChan := make(chan ethutil.React, 1)
 | 
						objectChan := make(chan ethreact.Event)
 | 
				
			||||||
	peerChan := make(chan ethutil.React, 1)
 | 
						peerChan := make(chan ethreact.Event)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	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)
 | 
						ticker := time.NewTicker(5 * time.Second)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -288,6 +279,7 @@ func (gui *Gui) update() {
 | 
				
			|||||||
	unconfirmedFunds := new(big.Int)
 | 
						unconfirmedFunds := new(big.Int)
 | 
				
			||||||
	gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount)))
 | 
						gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						go func() {
 | 
				
			||||||
		for {
 | 
							for {
 | 
				
			||||||
			select {
 | 
								select {
 | 
				
			||||||
			case b := <-blockChan:
 | 
								case b := <-blockChan:
 | 
				
			||||||
@@ -300,7 +292,7 @@ func (gui *Gui) update() {
 | 
				
			|||||||
			case txMsg := <-txChan:
 | 
								case txMsg := <-txChan:
 | 
				
			||||||
				tx := txMsg.Resource.(*ethchain.Transaction)
 | 
									tx := txMsg.Resource.(*ethchain.Transaction)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if txMsg.Event == "newTx:pre" {
 | 
									if txMsg.Name == "newTx:pre" {
 | 
				
			||||||
					object := state.GetAccount(gui.address())
 | 
										object := state.GetAccount(gui.address())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if bytes.Compare(tx.Sender(), gui.address()) == 0 {
 | 
										if bytes.Compare(tx.Sender(), gui.address()) == 0 {
 | 
				
			||||||
@@ -336,6 +328,17 @@ func (gui *Gui) update() {
 | 
				
			|||||||
				gui.setPeerInfo()
 | 
									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() {
 | 
					func (gui *Gui) setPeerInfo() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ import (
 | 
				
			|||||||
	"github.com/ethereum/eth-go/ethchain"
 | 
						"github.com/ethereum/eth-go/ethchain"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethlog"
 | 
						"github.com/ethereum/eth-go/ethlog"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethpub"
 | 
						"github.com/ethereum/eth-go/ethpub"
 | 
				
			||||||
 | 
						"github.com/ethereum/eth-go/ethreact"
 | 
				
			||||||
	"github.com/ethereum/eth-go/ethutil"
 | 
						"github.com/ethereum/eth-go/ethutil"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/utils"
 | 
						"github.com/ethereum/go-ethereum/utils"
 | 
				
			||||||
	"github.com/obscuren/otto"
 | 
						"github.com/obscuren/otto"
 | 
				
			||||||
@@ -22,8 +23,8 @@ type JSRE struct {
 | 
				
			|||||||
	vm       *otto.Otto
 | 
						vm       *otto.Otto
 | 
				
			||||||
	lib      *ethpub.PEthereum
 | 
						lib      *ethpub.PEthereum
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	blockChan  chan ethutil.React
 | 
						blockChan  chan ethreact.Event
 | 
				
			||||||
	changeChan chan ethutil.React
 | 
						changeChan chan ethreact.Event
 | 
				
			||||||
	quitChan   chan bool
 | 
						quitChan   chan bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	objectCb map[string][]otto.Value
 | 
						objectCb map[string][]otto.Value
 | 
				
			||||||
@@ -48,8 +49,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
 | 
				
			|||||||
		ethereum,
 | 
							ethereum,
 | 
				
			||||||
		otto.New(),
 | 
							otto.New(),
 | 
				
			||||||
		ethpub.NewPEthereum(ethereum),
 | 
							ethpub.NewPEthereum(ethereum),
 | 
				
			||||||
		make(chan ethutil.React, 1),
 | 
							make(chan ethreact.Event),
 | 
				
			||||||
		make(chan ethutil.React, 1),
 | 
							make(chan ethreact.Event),
 | 
				
			||||||
		make(chan bool),
 | 
							make(chan bool),
 | 
				
			||||||
		make(map[string][]otto.Value),
 | 
							make(map[string][]otto.Value),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -63,6 +64,9 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// We have to make sure that, whoever calls this, calls "Stop"
 | 
						// We have to make sure that, whoever calls this, calls "Stop"
 | 
				
			||||||
	go re.mainLoop()
 | 
						go re.mainLoop()
 | 
				
			||||||
 | 
						// Subscribe to events
 | 
				
			||||||
 | 
						reactor := ethereum.Reactor()
 | 
				
			||||||
 | 
						reactor.Subscribe("newBlock", re.blockChan)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	re.Bind("eth", &JSEthereum{re.lib, re.vm})
 | 
						re.Bind("eth", &JSEthereum{re.lib, re.vm})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -108,10 +112,6 @@ func (self *JSRE) Stop() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (self *JSRE) mainLoop() {
 | 
					func (self *JSRE) mainLoop() {
 | 
				
			||||||
	// Subscribe to events
 | 
					 | 
				
			||||||
	reactor := self.ethereum.Reactor()
 | 
					 | 
				
			||||||
	reactor.Subscribe("newBlock", self.blockChan)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
out:
 | 
					out:
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user