From e7dd1a2730af07d1e3f15cb1ec5f39726ae8657d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=BA=86=E5=8D=87?= Date: Fri, 28 Sep 2018 16:03:36 +0800 Subject: [PATCH] fix null result unmarshal --- rpc/client.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index d96189a2d8..d8c0fbbe3a 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -80,12 +80,12 @@ type BatchElem struct { // A value of this type can a JSON-RPC request, notification, successful response or // error response. Which one it is depends on the fields. type jsonrpcMessage struct { - Version string `json:"jsonrpc"` - ID json.RawMessage `json:"id,omitempty"` - Method string `json:"method,omitempty"` - Params json.RawMessage `json:"params,omitempty"` - Error *jsonError `json:"error,omitempty"` - Result json.RawMessage `json:"result,omitempty"` + Version string `json:"jsonrpc"` + ID json.RawMessage `json:"id,omitempty"` + Method string `json:"method,omitempty"` + Params json.RawMessage `json:"params,omitempty"` + Error *jsonError `json:"error,omitempty"` + Result *json.RawMessage `json:"result,omitempty"` } func (msg *jsonrpcMessage) isNotification() bool { @@ -310,10 +310,10 @@ func (c *Client) CallContext(ctx context.Context, result interface{}, method str return err case resp.Error != nil: return resp.Error - case len(resp.Result) == 0: + case resp.Result == nil: return ErrNoResult default: - return json.Unmarshal(resp.Result, &result) + return json.Unmarshal(*resp.Result, &result) } } @@ -381,11 +381,11 @@ func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error { elem.Error = resp.Error continue } - if len(resp.Result) == 0 { + if resp.Result == nil { elem.Error = ErrNoResult continue } - elem.Error = json.Unmarshal(resp.Result, elem.Result) + elem.Error = json.Unmarshal(*resp.Result, elem.Result) } return err } @@ -665,7 +665,7 @@ func (c *Client) handleResponse(msg *jsonrpcMessage) { op.err = msg.Error return } - if op.err = json.Unmarshal(msg.Result, &op.sub.subid); op.err == nil { + if op.err = json.Unmarshal(*msg.Result, &op.sub.subid); op.err == nil { go op.sub.start() c.subs[op.sub.subid] = op.sub }