aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/ws
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-02-04 07:29:29 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-02-04 07:29:29 +0800
commit55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd (patch)
tree34ec5ce35049377792ccc33892191b76fc49069a /rpc/ws
parent07590196a5ee1a63856f1653516da950dfa4966b (diff)
downloaddexon-55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd.tar
dexon-55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd.tar.gz
dexon-55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd.tar.bz2
dexon-55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd.tar.lz
dexon-55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd.tar.xz
dexon-55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd.tar.zst
dexon-55ed0ff07c6cf2dc8b422a3bf8d623a039ad6dbd.zip
Update RPC message format
Diffstat (limited to 'rpc/ws')
-rw-r--r--rpc/ws/server.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/rpc/ws/server.go b/rpc/ws/server.go
index 85cacf80b..6be4e8ce9 100644
--- a/rpc/ws/server.go
+++ b/rpc/ws/server.go
@@ -28,6 +28,7 @@ import (
)
var wslogger = logger.NewLogger("RPC-WS")
+var JSON rpc.JsonWrapper
type WebSocketServer struct {
pipe *xeth.XEth
@@ -90,27 +91,29 @@ 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 request")
var reqParsed rpc.RpcRequest
if err := websocket.JSON.Receive(conn, &reqParsed); err != nil {
- wslogger.Debugln(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 {
- wslogger.Errorln(reserr)
- websocket.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)
- 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)