diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-02-11 18:40:12 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-02-11 18:40:12 +0800 |
commit | cfddb7f3cd3b8cecb1e59412ce4db5769f6c8007 (patch) | |
tree | ab28c518bd1b78f6b8ac8b241951ad161cb268a9 /rpc/ws | |
parent | 21fd31dad8bc6e0291ca405314b516670333c707 (diff) | |
parent | c6af5f0a275608ea6c797ef826e6090885f24eac (diff) | |
download | go-tangerine-cfddb7f3cd3b8cecb1e59412ce4db5769f6c8007.tar.gz go-tangerine-cfddb7f3cd3b8cecb1e59412ce4db5769f6c8007.tar.zst go-tangerine-cfddb7f3cd3b8cecb1e59412ce4db5769f6c8007.zip |
Merge branch 'develop' into jsonrpc
Conflicts:
rpc/ws/server.go
Diffstat (limited to 'rpc/ws')
-rw-r--r-- | rpc/ws/server.go | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/rpc/ws/server.go b/rpc/ws/server.go index 2efc6ff02..fe6af042f 100644 --- a/rpc/ws/server.go +++ b/rpc/ws/server.go @@ -22,8 +22,6 @@ import ( "net/http" "code.google.com/p/go.net/websocket" - "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/xeth" @@ -33,25 +31,21 @@ var wslogger = logger.NewLogger("RPC-WS") var JSON rpc.JsonWrapper type WebSocketServer struct { - eth *eth.Ethereum - filterManager *filter.FilterManager - port int - doneCh chan bool - listener net.Listener + pipe *xeth.XEth + port int + doneCh chan bool + listener net.Listener } -func NewWebSocketServer(eth *eth.Ethereum, port int) (*WebSocketServer, error) { +func NewWebSocketServer(pipe *xeth.XEth, port int) (*WebSocketServer, error) { sport := fmt.Sprintf(":%d", port) l, err := net.Listen("tcp", sport) if err != nil { return nil, err } - filterManager := filter.NewFilterManager(eth.EventMux()) - go filterManager.Start() - - return &WebSocketServer{eth, - filterManager, + return &WebSocketServer{ + pipe, port, make(chan bool), l, @@ -76,7 +70,7 @@ func (self *WebSocketServer) Start() { wslogger.Infof("Starting RPC-WS server on port %d", self.port) go self.handlerLoop() - api := rpc.NewEthereumApi(xeth.New(self.eth)) + api := rpc.NewEthereumApi(self.pipe) h := self.apiHandler(api) http.Handle("/ws", h) @@ -97,6 +91,7 @@ func (s *WebSocketServer) apiHandler(api *rpc.EthereumApi) http.Handler { } func sockHandler(api *rpc.EthereumApi) websocket.Handler { + var jsonrpcver string = "2.0" fn := func(conn *websocket.Conn) { for { wslogger.Debugln("Handling connection") @@ -104,23 +99,22 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler { // reqParsed, reqerr := JSON.ParseRequestBody(conn.Request()) if err := websocket.JSON.Receive(conn, &reqParsed); err != nil { - // if reqerr != nil { - JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest}) - // websocket.JSON.Send(conn, rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest}) + jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest} + JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) continue } var response interface{} reserr := api.GetRequestReply(&reqParsed, &response) if reserr != nil { - // websocket.JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()}) - JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()}) + wslogger.Warnln(reserr) + jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()} + JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr}) continue } wslogger.Debugf("Generated response: %T %s", response, response) - JSON.Send(conn, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response}) - // websocket.JSON.Send(conn, rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response}) + JSON.Send(conn, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response}) } } return websocket.Handler(fn) |