Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow RPC ID to be string or null #300

Merged
merged 4 commits into from
Feb 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rpc/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
if reserr != nil {
rpchttplogger.Warnln(reserr)
jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()}
JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr})
JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr})
return
}

Expand Down
6 changes: 3 additions & 3 deletions rpc/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ const (
)

type RpcRequest struct {
ID interface{} `json:"id"`
JsonRpc string `json:"jsonrpc"`
ID int `json:"id"`
Method string `json:"method"`
Params []json.RawMessage `json:"params"`
}

type RpcSuccessResponse struct {
ID int `json:"id"`
ID interface{} `json:"id"`
JsonRpc string `json:"jsonrpc"`
Result interface{} `json:"result"`
}

type RpcErrorResponse struct {
ID *int `json:"id"`
ID interface{} `json:"id"`
JsonRpc string `json:"jsonrpc"`
Error *RpcErrorObject `json:"error"`
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error)

// Convert JSON to native types
d := json.NewDecoder(req.Body)
// d.UseNumber()
defer req.Body.Close()
err := d.Decode(&reqParsed)

if err != nil {
rpclogger.Errorln("Error decoding JSON: ", err)
return reqParsed, err
}

rpclogger.DebugDetailf("Parsed request: %s", reqParsed)

return reqParsed, nil
Expand Down
5 changes: 3 additions & 2 deletions rpc/ws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
var jsonrpcver string = "2.0"
fn := func(conn *websocket.Conn) {
for {
wslogger.Debugln("Handling request")
wslogger.Debugln("Handling connection")
var reqParsed rpc.RpcRequest

// reqParsed, reqerr := JSON.ParseRequestBody(conn.Request())
if err := websocket.JSON.Receive(conn, &reqParsed); err != nil {
jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest}
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
Expand All @@ -108,7 +109,7 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
if reserr != nil {
wslogger.Warnln(reserr)
jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()}
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr})
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr})
continue
}

Expand Down