diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-10 07:51:56 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-10 07:51:56 +0800 |
commit | e3da85faedf21a3ddb73a0fa29decf65364e6c39 (patch) | |
tree | 516faf70a5346bec9016bbdd308b6bcc23d5bccb /cmd | |
parent | 491c23a728e4f5cdedfa040aded6a6b136f6bee0 (diff) | |
download | go-tangerine-e3da85faedf21a3ddb73a0fa29decf65364e6c39.tar.gz go-tangerine-e3da85faedf21a3ddb73a0fa29decf65364e6c39.tar.zst go-tangerine-e3da85faedf21a3ddb73a0fa29decf65364e6c39.zip |
Implemented filter for ws + fixes
* proper 0xhex
* filters fixed
* start of filter manager
* accounts for ws. Closes #246
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/mist/assets/qml/browser.qml | 2 | ||||
-rw-r--r-- | cmd/mist/ui_lib.go | 1 | ||||
-rw-r--r-- | cmd/utils/websockets.go | 54 |
3 files changed, 46 insertions, 11 deletions
diff --git a/cmd/mist/assets/qml/browser.qml b/cmd/mist/assets/qml/browser.qml index f6d2d2d64..fcec774a5 100644 --- a/cmd/mist/assets/qml/browser.qml +++ b/cmd/mist/assets/qml/browser.qml @@ -66,7 +66,7 @@ Rectangle { onMessages: { // Bit of a cheat to get proper JSON var m = JSON.parse(JSON.parse(JSON.stringify(messages))) - webview.postEvent("messages", id, m); + webview.postEvent("eth_changed", id, m); } function onShhMessage(message, id) { diff --git a/cmd/mist/ui_lib.go b/cmd/mist/ui_lib.go index 60c7181c1..f3559183e 100644 --- a/cmd/mist/ui_lib.go +++ b/cmd/mist/ui_lib.go @@ -70,6 +70,7 @@ func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { lib := &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)} lib.miner = miner.New(eth.KeyManager().Address(), eth) lib.filterManager = filter.NewFilterManager(eth.EventMux()) + go lib.filterManager.Start() return lib } diff --git a/cmd/utils/websockets.go b/cmd/utils/websockets.go index 003e1bc22..5d97599c3 100644 --- a/cmd/utils/websockets.go +++ b/cmd/utils/websockets.go @@ -21,9 +21,14 @@ package utils import ( + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/state" + "github.com/ethereum/go-ethereum/ui/qt" "github.com/ethereum/go-ethereum/websocket" "github.com/ethereum/go-ethereum/xeth" ) @@ -35,16 +40,19 @@ func args(v ...interface{}) []interface{} { } type WebSocketServer struct { - ethereum *eth.Ethereum - filterCallbacks map[int][]int + eth *eth.Ethereum + filterManager *filter.FilterManager } func NewWebSocketServer(eth *eth.Ethereum) *WebSocketServer { - return &WebSocketServer{eth, make(map[int][]int)} + filterManager := filter.NewFilterManager(eth.EventMux()) + go filterManager.Start() + + return &WebSocketServer{eth, filterManager} } func (self *WebSocketServer) Serv() { - pipe := xeth.NewJSXEth(self.ethereum) + pipe := xeth.NewJSXEth(self.eth) wsServ := websocket.NewServer("/eth", ":40404") wsServ.MessageFunc(func(c *websocket.Client, msg *websocket.Message) { @@ -112,15 +120,32 @@ func (self *WebSocketServer) Serv() { c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Id) - case "eth_secretToAddress": - args := msg.Arguments() - - c.Write(pipe.SecretToAddress(args.Get(0).Str()), msg.Id) + case "eth_accounts": + c.Write(pipe.Accounts(), msg.Id) case "eth_newFilter": + if mp, ok := msg.Args[0].(map[string]interface{}); ok { + var id int + filter := qt.NewFilterFromMap(mp, self.eth) + filter.MessageCallback = func(messages state.Messages) { + c.Event(toMessages(messages), "eth_changed", id) + } + id = self.filterManager.InstallFilter(filter) + c.Write(id, msg.Id) + } case "eth_newFilterString": - case "eth_messages": - // TODO + var id int + filter := core.NewFilter(self.eth) + filter.BlockCallback = func(block *types.Block) { + c.Event(nil, "eth_changed", id) + } + id = self.filterManager.InstallFilter(filter) + c.Write(id, msg.Id) + case "eth_filterLogs": + filter := self.filterManager.GetFilter(int(msg.Arguments().Get(0).Uint())) + if filter != nil { + c.Write(toMessages(filter.Find()), msg.Id) + } } }) @@ -128,6 +153,15 @@ func (self *WebSocketServer) Serv() { wsServ.Listen() } +func toMessages(messages state.Messages) (msgs []xeth.JSMessage) { + msgs = make([]xeth.JSMessage, len(messages)) + for i, msg := range messages { + msgs[i] = xeth.NewJSMessage(msg) + } + + return +} + func StartWebSockets(eth *eth.Ethereum) { wslogger.Infoln("Starting WebSockets") |