rpc/lib/types: RPCResponse.Result is not a pointer

This commit is contained in:
Ethan Buchman
2017-11-08 00:25:36 +00:00
parent a01c226dc4
commit 593c127257
5 changed files with 16 additions and 17 deletions

View File

@@ -67,14 +67,14 @@ func (err RPCError) Error() string {
}
type RPCResponse struct {
JSONRPC string `json:"jsonrpc"`
ID string `json:"id"`
Result *json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
JSONRPC string `json:"jsonrpc"`
ID string `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
func NewRPCSuccessResponse(id string, res interface{}) RPCResponse {
var raw *json.RawMessage
var rawMsg json.RawMessage
if res != nil {
var js []byte
@@ -82,11 +82,10 @@ func NewRPCSuccessResponse(id string, res interface{}) RPCResponse {
if err != nil {
return RPCInternalError(id, errors.Wrap(err, "Error marshalling response"))
}
rawMsg := json.RawMessage(js)
raw = &rawMsg
rawMsg = json.RawMessage(js)
}
return RPCResponse{JSONRPC: "2.0", ID: id, Result: raw}
return RPCResponse{JSONRPC: "2.0", ID: id, Result: rawMsg}
}
func NewRPCErrorResponse(id string, code int, msg string, data string) RPCResponse {
@@ -98,7 +97,7 @@ func NewRPCErrorResponse(id string, code int, msg string, data string) RPCRespon
}
func (resp RPCResponse) String() string {
if resp.Error == nil {
if resp.Error != nil {
return fmt.Sprintf("[%s %v]", resp.ID, resp.Result)
} else {
return fmt.Sprintf("[%s %s]", resp.ID, resp.Error)