aboutsummaryrefslogtreecommitdiffstats
path: root/mist/ext_app.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-10-15 01:38:38 +0800
committerFelix Lange <fjl@twurst.com>2014-10-15 01:38:38 +0800
commit0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a (patch)
tree2b483bc46c8db872a1bebc7ac0b47cd9a3046617 /mist/ext_app.go
parent83a4b8b49bc28dad0539d040dceca48b7b75baf2 (diff)
downloaddexon-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar
dexon-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.gz
dexon-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.bz2
dexon-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.lz
dexon-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.xz
dexon-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.tar.zst
dexon-0aea5fc4a3ed9c08272d3a894c0a31212dc25a7a.zip
adapt to new event package
Diffstat (limited to 'mist/ext_app.go')
-rw-r--r--mist/ext_app.go69
1 files changed, 24 insertions, 45 deletions
diff --git a/mist/ext_app.go b/mist/ext_app.go
index 514084c97..36241e58c 100644
--- a/mist/ext_app.go
+++ b/mist/ext_app.go
@@ -5,8 +5,8 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpipe"
- "github.com/ethereum/eth-go/ethreact"
"github.com/ethereum/eth-go/ethstate"
+ "github.com/ethereum/eth-go/event"
"github.com/ethereum/go-ethereum/javascript"
"gopkg.in/qml.v1"
)
@@ -28,9 +28,7 @@ type ExtApplication struct {
*ethpipe.JSPipe
eth ethchain.EthManager
- blockChan chan ethreact.Event
- messageChan chan ethreact.Event
- quitChan chan bool
+ events event.Subscription
watcherQuitChan chan bool
filters map[string]*ethchain.Filter
@@ -40,19 +38,14 @@ type ExtApplication struct {
}
func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
- app := &ExtApplication{
- ethpipe.NewJSPipe(lib.eth),
- lib.eth,
- make(chan ethreact.Event, 100),
- make(chan ethreact.Event, 100),
- make(chan bool),
- make(chan bool),
- make(map[string]*ethchain.Filter),
- container,
- lib,
+ return &ExtApplication{
+ JSPipe: ethpipe.NewJSPipe(lib.eth),
+ eth: lib.eth,
+ watcherQuitChan: make(chan bool),
+ filters: make(map[string]*ethchain.Filter),
+ container: container,
+ lib: lib,
}
-
- return app
}
func (app *ExtApplication) run() {
@@ -67,14 +60,13 @@ func (app *ExtApplication) run() {
return
}
+ // Subscribe to events
+ mux := app.lib.eth.EventMux()
+ app.events = mux.Subscribe(ethchain.NewBlockEvent{}, ethstate.Messages(nil))
+
// Call the main loop
go app.mainLoop()
- // Subscribe to events
- reactor := app.lib.eth.Reactor()
- reactor.Subscribe("newBlock", app.blockChan)
- reactor.Subscribe("messages", app.messageChan)
-
app.container.NewWatcher(app.watcherQuitChan)
win := app.container.Window()
@@ -85,42 +77,29 @@ func (app *ExtApplication) run() {
}
func (app *ExtApplication) stop() {
- // Clean up
- reactor := app.lib.eth.Reactor()
- reactor.Unsubscribe("newBlock", app.blockChan)
+ app.events.Unsubscribe()
// Kill the main loop
- app.quitChan <- true
app.watcherQuitChan <- true
- close(app.blockChan)
- close(app.quitChan)
-
app.container.Destroy()
}
func (app *ExtApplication) mainLoop() {
-out:
- for {
- select {
- case <-app.quitChan:
- break out
- case block := <-app.blockChan:
- if block, ok := block.Resource.(*ethchain.Block); ok {
- app.container.NewBlock(block)
- }
- case msg := <-app.messageChan:
- if messages, ok := msg.Resource.(ethstate.Messages); ok {
- for id, filter := range app.filters {
- msgs := filter.FilterMessages(messages)
- if len(msgs) > 0 {
- app.container.Messages(msgs, id)
- }
+ for ev := range app.events.Chan() {
+ switch ev := ev.(type) {
+ case ethchain.NewBlockEvent:
+ app.container.NewBlock(ev.Block)
+
+ case ethstate.Messages:
+ for id, filter := range app.filters {
+ msgs := filter.FilterMessages(ev)
+ if len(msgs) > 0 {
+ app.container.Messages(msgs, id)
}
}
}
}
-
}
func (self *ExtApplication) Watch(filterOptions map[string]interface{}, identifier string) {