diff options
author | obscuren <geffobscura@gmail.com> | 2014-08-15 06:24:14 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-08-15 06:24:14 +0800 |
commit | aadc5be3ff9e3818e41d83910b9730e5f1af042e (patch) | |
tree | 3dc980f34391257eb2a0c1be3a042e99f39489f3 /ethereal/ext_app.go | |
parent | 1fd69e956949671806b23b7ec1feec4f6c416a81 (diff) | |
download | dexon-aadc5be3ff9e3818e41d83910b9730e5f1af042e.tar.gz dexon-aadc5be3ff9e3818e41d83910b9730e5f1af042e.tar.zst dexon-aadc5be3ff9e3818e41d83910b9730e5f1af042e.zip |
Implemented new watch
* Old watch methods have been removed
* Implemented new callback handlers for onWatchCb
* added new Filter JS object
Diffstat (limited to 'ethereal/ext_app.go')
-rw-r--r-- | ethereal/ext_app.go | 63 |
1 files changed, 20 insertions, 43 deletions
diff --git a/ethereal/ext_app.go b/ethereal/ext_app.go index 4533b2438..627f9e9ca 100644 --- a/ethereal/ext_app.go +++ b/ethereal/ext_app.go @@ -7,7 +7,6 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethreact" "github.com/ethereum/eth-go/ethstate" - "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/javascript" "github.com/go-qml/qml" ) @@ -23,6 +22,7 @@ type AppContainer interface { ObjectChanged(*ethstate.StateObject) StorageChanged(*ethstate.StorageState) NewWatcher(chan bool) + Messages(ethstate.Messages, string) } type ExtApplication struct { @@ -31,9 +31,12 @@ type ExtApplication struct { blockChan chan ethreact.Event changeChan chan ethreact.Event + messageChan chan ethreact.Event quitChan chan bool watcherQuitChan chan bool + filters map[string]*ethchain.Filter + container AppContainer lib *UiLib registeredEvents []string @@ -45,8 +48,10 @@ func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { lib.eth, make(chan ethreact.Event, 100), make(chan ethreact.Event, 100), + make(chan ethreact.Event, 100), make(chan bool), make(chan bool), + make(map[string]*ethchain.Filter), container, lib, nil, @@ -73,6 +78,7 @@ func (app *ExtApplication) run() { // Subscribe to events reactor := app.lib.eth.Reactor() reactor.Subscribe("newBlock", app.blockChan) + reactor.Subscribe("messages", app.messageChan) app.container.NewWatcher(app.watcherQuitChan) @@ -118,56 +124,27 @@ out: } else if storageObject, ok := object.Resource.(*ethstate.StorageState); ok { app.container.StorageChanged(storageObject) } + + 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) + } + } + } } } } -func (app *ExtApplication) Watch(addr, storageAddr string) { - var event string - if len(storageAddr) == 0 { - event = "object:" + string(ethutil.Hex2Bytes(addr)) - app.lib.eth.Reactor().Subscribe(event, app.changeChan) - } else { - event = "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr)) - app.lib.eth.Reactor().Subscribe(event, app.changeChan) - } - - app.registeredEvents = append(app.registeredEvents, event) +func (self *ExtApplication) Watch(filterOptions map[string]interface{}, identifier string) { + self.filters[identifier] = ethchain.NewFilterFromMap(filterOptions, self.eth) } func (self *ExtApplication) GetMessages(object map[string]interface{}) string { - filter := ethchain.NewFilter(self.eth) - - if object["earliest"] != nil { - earliest := object["earliest"] - if e, ok := earliest.(string); ok { - filter.SetEarliestBlock(ethutil.Hex2Bytes(e)) - } else { - filter.SetEarliestBlock(earliest) - } - } - - if object["latest"] != nil { - latest := object["latest"] - if l, ok := latest.(string); ok { - filter.SetLatestBlock(ethutil.Hex2Bytes(l)) - } else { - filter.SetLatestBlock(latest) - } - } - if object["to"] != nil { - filter.AddTo(ethutil.Hex2Bytes(object["to"].(string))) - } - if object["from"] != nil { - filter.AddFrom(ethutil.Hex2Bytes(object["from"].(string))) - } - if object["max"] != nil { - filter.SetMax(object["max"].(int)) - } - if object["skip"] != nil { - filter.SetSkip(object["skip"].(int)) - } + filter := ethchain.NewFilterFromMap(object, self.eth) messages := filter.Find() var msgs []javascript.JSMessage |