Skip to content

Commit ef6c7bd

Browse files
committed
Merge pull request #300 from tgerring/jsonrpc
Allow RPC ID to be string or null
2 parents c6af5f0 + d613bf6 commit ef6c7bd

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

rpc/http/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
102102
if reserr != nil {
103103
rpchttplogger.Warnln(reserr)
104104
jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()}
105-
JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr})
105+
JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr})
106106
return
107107
}
108108

rpc/message.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ const (
3434
)
3535

3636
type RpcRequest struct {
37+
ID interface{} `json:"id"`
3738
JsonRpc string `json:"jsonrpc"`
38-
ID int `json:"id"`
3939
Method string `json:"method"`
4040
Params []json.RawMessage `json:"params"`
4141
}
4242

4343
type RpcSuccessResponse struct {
44-
ID int `json:"id"`
44+
ID interface{} `json:"id"`
4545
JsonRpc string `json:"jsonrpc"`
4646
Result interface{} `json:"result"`
4747
}
4848

4949
type RpcErrorResponse struct {
50-
ID *int `json:"id"`
50+
ID interface{} `json:"id"`
5151
JsonRpc string `json:"jsonrpc"`
5252
Error *RpcErrorObject `json:"error"`
5353
}

rpc/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error)
4747

4848
// Convert JSON to native types
4949
d := json.NewDecoder(req.Body)
50-
// d.UseNumber()
5150
defer req.Body.Close()
5251
err := d.Decode(&reqParsed)
5352

5453
if err != nil {
5554
rpclogger.Errorln("Error decoding JSON: ", err)
5655
return reqParsed, err
5756
}
57+
5858
rpclogger.DebugDetailf("Parsed request: %s", reqParsed)
5959

6060
return reqParsed, nil

rpc/ws/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
9494
var jsonrpcver string = "2.0"
9595
fn := func(conn *websocket.Conn) {
9696
for {
97-
wslogger.Debugln("Handling request")
97+
wslogger.Debugln("Handling connection")
9898
var reqParsed rpc.RpcRequest
9999

100+
// reqParsed, reqerr := JSON.ParseRequestBody(conn.Request())
100101
if err := websocket.JSON.Receive(conn, &reqParsed); err != nil {
101102
jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest}
102103
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
@@ -108,7 +109,7 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
108109
if reserr != nil {
109110
wslogger.Warnln(reserr)
110111
jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()}
111-
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr})
112+
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr})
112113
continue
113114
}
114115

0 commit comments

Comments
 (0)