From a26aecdfdb0223b2fb54ca2d40adb2b531512d42 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 6 Jan 2015 11:44:22 +0100 Subject: Updated WS API. Fixes #219. Closes #220 --- cmd/utils/websockets.go | 70 ++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'cmd/utils') diff --git a/cmd/utils/websockets.go b/cmd/utils/websockets.go index e4bc1b185..ef9de192b 100644 --- a/cmd/utils/websockets.go +++ b/cmd/utils/websockets.go @@ -33,73 +33,73 @@ func (self *WebSocketServer) Serv() { data := ethutil.NewValue(msg.Args) bcode, err := ethutil.Compile(data.Get(0).Str(), false) if err != nil { - c.Write(args(nil, err.Error()), msg.Seed) + c.Write(args(nil, err.Error()), msg.Id) } code := ethutil.Bytes2Hex(bcode) - c.Write(args(code, nil), msg.Seed) - case "getBlockByNumber": + c.Write(args(code, nil), msg.Id) + case "eth_blockByNumber": args := msg.Arguments() block := pipe.BlockByNumber(int32(args.Get(0).Uint())) - c.Write(block, msg.Seed) + c.Write(block, msg.Id) - case "getKey": - c.Write(pipe.Key().PrivateKey, msg.Seed) - case "transact": + case "eth_blockByHash": + args := msg.Arguments() + + c.Write(pipe.BlockByHash(args.Get(0).Str()), msg.Id) + + case "eth_transact": if mp, ok := msg.Args[0].(map[string]interface{}); ok { object := mapToTxParams(mp) c.Write( - args(pipe.Transact(object["from"], object["to"], object["value"], object["gas"], object["gasPrice"], object["data"])), - msg.Seed, + args(pipe.Transact(pipe.Key().PrivateKey, object["to"], object["value"], object["gas"], object["gasPrice"], object["data"])), + msg.Id, ) } - case "getCoinBase": - c.Write(pipe.CoinBase(), msg.Seed) + case "eth_gasPrice": + c.Write("10000000000000", msg.Id) + case "eth_coinbase": + c.Write(pipe.CoinBase(), msg.Id) - case "getIsListening": - c.Write(pipe.IsListening(), msg.Seed) + case "eth_listening": + c.Write(pipe.IsListening(), msg.Id) - case "getIsMining": - c.Write(pipe.IsMining(), msg.Seed) - - case "getPeerCoint": - c.Write(pipe.PeerCount(), msg.Seed) - - case "getCountAt": - args := msg.Arguments() + case "eth_mining": + c.Write(pipe.IsMining(), msg.Id) - c.Write(pipe.TxCountAt(args.Get(0).Str()), msg.Seed) + case "eth_peerCount": + c.Write(pipe.PeerCount(), msg.Id) - case "getCodeAt": + case "eth_countAt": args := msg.Arguments() - c.Write(len(pipe.CodeAt(args.Get(0).Str())), msg.Seed) + c.Write(pipe.TxCountAt(args.Get(0).Str()), msg.Id) - case "getBlockByHash": + case "eth_codeAt": args := msg.Arguments() - c.Write(pipe.BlockByHash(args.Get(0).Str()), msg.Seed) + c.Write(len(pipe.CodeAt(args.Get(0).Str())), msg.Id) - case "getStorageAt": + case "eth_storageAt": args := msg.Arguments() - c.Write(pipe.StorageAt(args.Get(0).Str(), args.Get(1).Str()), msg.Seed) + c.Write(pipe.StorageAt(args.Get(0).Str(), args.Get(1).Str()), msg.Id) - case "getBalanceAt": + case "eth_balanceAt": args := msg.Arguments() - c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Seed) + c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Id) - case "getSecretToAddress": + case "eth_secretToAddress": args := msg.Arguments() - c.Write(pipe.SecretToAddress(args.Get(0).Str()), msg.Seed) + c.Write(pipe.SecretToAddress(args.Get(0).Str()), msg.Id) - case "newFilter": - case "newFilterString": - case "messages": + case "eth_newFilter": + case "eth_newFilterString": + case "eth_messages": // TODO } -- cgit v1.2.3 From 117f66e82375b752cc6a9ff22aa0d398ac337bb4 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 6 Jan 2015 12:13:57 +0100 Subject: Added license headers --- cmd/utils/cmd.go | 21 +++++++++++++++++++++ cmd/utils/vm_env.go | 20 ++++++++++++++++++++ cmd/utils/websockets.go | 20 ++++++++++++++++++++ 3 files changed, 61 insertions(+) (limited to 'cmd/utils') diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index d01d9da9f..1a85668b0 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -1,3 +1,24 @@ +/* + This file is part of go-ethereum + + go-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + go-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with go-ethereum. If not, see . +*/ +/** + * @authors + * Jeffrey Wilcke + * Viktor Tron + */ package utils import ( diff --git a/cmd/utils/vm_env.go b/cmd/utils/vm_env.go index acc2ffad9..5eaf63b65 100644 --- a/cmd/utils/vm_env.go +++ b/cmd/utils/vm_env.go @@ -1,3 +1,23 @@ +/* + This file is part of go-ethereum + + go-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + go-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with go-ethereum. If not, see . +*/ +/** + * @authors + * Jeffrey Wilcke + */ package utils import ( diff --git a/cmd/utils/websockets.go b/cmd/utils/websockets.go index ef9de192b..003e1bc22 100644 --- a/cmd/utils/websockets.go +++ b/cmd/utils/websockets.go @@ -1,3 +1,23 @@ +/* + This file is part of go-ethereum + + go-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + go-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with go-ethereum. If not, see . +*/ +/** + * @authors + * Jeffrey Wilcke + */ package utils import ( -- cgit v1.2.3 From fed3e6a808921fb8274b50043c5c39a24a1bbccf Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 7 Jan 2015 13:17:48 +0100 Subject: Refactored ethutil.Config.Db out --- cmd/utils/cmd.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'cmd/utils') diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 1a85668b0..a57d3266f 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -39,6 +39,7 @@ import ( "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/xeth" ) @@ -259,7 +260,8 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error { parent := ethereum.ChainManager().GetBlock(block.ParentHash()) - _, err := ethereum.BlockProcessor().TransitionState(parent.State(), parent, block) + statedb := state.New(parent.Root(), ethereum.Db()) + _, err := ethereum.BlockProcessor().TransitionState(statedb, parent, block) if err != nil { return err } -- cgit v1.2.3 From e3da85faedf21a3ddb73a0fa29decf65364e6c39 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 Jan 2015 00:51:56 +0100 Subject: Implemented filter for ws + fixes * proper 0xhex * filters fixed * start of filter manager * accounts for ws. Closes #246 --- cmd/utils/websockets.go | 54 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'cmd/utils') 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") -- cgit v1.2.3 From 7e6b72cb5c0172b8a6a15239a6628b64c8f8de23 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 Jan 2015 18:08:43 +0100 Subject: removed accidental qt dep --- cmd/utils/websockets.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmd/utils') diff --git a/cmd/utils/websockets.go b/cmd/utils/websockets.go index 5d97599c3..48ea4014b 100644 --- a/cmd/utils/websockets.go +++ b/cmd/utils/websockets.go @@ -28,7 +28,7 @@ import ( "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/ui" "github.com/ethereum/go-ethereum/websocket" "github.com/ethereum/go-ethereum/xeth" ) @@ -126,7 +126,7 @@ func (self *WebSocketServer) Serv() { case "eth_newFilter": if mp, ok := msg.Args[0].(map[string]interface{}); ok { var id int - filter := qt.NewFilterFromMap(mp, self.eth) + filter := ui.NewFilterFromMap(mp, self.eth) filter.MessageCallback = func(messages state.Messages) { c.Event(toMessages(messages), "eth_changed", id) } -- cgit v1.2.3