mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
rpc/lib/types: RPCResponse.Result is not a pointer
This commit is contained in:
parent
a01c226dc4
commit
593c127257
@ -311,7 +311,7 @@ func (w *WSEvents) eventListener() {
|
||||
continue
|
||||
}
|
||||
result := new(ctypes.ResultEvent)
|
||||
err := json.Unmarshal(*resp.Result, result)
|
||||
err := json.Unmarshal(resp.Result, result)
|
||||
if err != nil {
|
||||
// ignore silently (eg. subscribe, unsubscribe and maybe other events)
|
||||
// TODO: ?
|
||||
|
@ -153,7 +153,7 @@ func unmarshalResponseBytes(responseBytes []byte, result interface{}) (interface
|
||||
return nil, errors.Errorf("Response error: %v", response.Error)
|
||||
}
|
||||
// unmarshal the RawMessage into the result
|
||||
err = json.Unmarshal(*response.Result, result)
|
||||
err = json.Unmarshal(response.Result, result)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("Error unmarshalling rpc response result: %v", err)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
h.mtx.RUnlock()
|
||||
|
||||
res := json.RawMessage(`{}`)
|
||||
emptyRespBytes, _ := json.Marshal(types.RPCResponse{Result: &res})
|
||||
emptyRespBytes, _ := json.Marshal(types.RPCResponse{Result: res})
|
||||
if err := conn.WriteMessage(messageType, emptyRespBytes); err != nil {
|
||||
return
|
||||
}
|
||||
@ -204,7 +204,7 @@ func callWgDoneOnResult(t *testing.T, c *WSClient, wg *sync.WaitGroup) {
|
||||
if resp.Error != nil {
|
||||
t.Fatalf("unexpected error: %v", resp.Error)
|
||||
}
|
||||
if *resp.Result != nil {
|
||||
if resp.Result != nil {
|
||||
wg.Done()
|
||||
}
|
||||
case <-c.Quit:
|
||||
|
@ -223,7 +223,7 @@ func echoViaWS(cl *client.WSClient, val string) (string, error) {
|
||||
|
||||
}
|
||||
result := new(ResultEcho)
|
||||
err = json.Unmarshal(*msg.Result, result)
|
||||
err = json.Unmarshal(msg.Result, result)
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
@ -247,7 +247,7 @@ func echoBytesViaWS(cl *client.WSClient, bytes []byte) ([]byte, error) {
|
||||
|
||||
}
|
||||
result := new(ResultEchoBytes)
|
||||
err = json.Unmarshal(*msg.Result, result)
|
||||
err = json.Unmarshal(msg.Result, result)
|
||||
if err != nil {
|
||||
return []byte{}, nil
|
||||
}
|
||||
@ -328,7 +328,7 @@ func TestWSNewWSRPCFunc(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := new(ResultEcho)
|
||||
err = json.Unmarshal(*msg.Result, result)
|
||||
err = json.Unmarshal(msg.Result, result)
|
||||
require.Nil(t, err)
|
||||
got := result.Value
|
||||
assert.Equal(t, got, val)
|
||||
@ -353,7 +353,7 @@ func TestWSHandlesArrayParams(t *testing.T) {
|
||||
t.Fatalf("%+v", err)
|
||||
}
|
||||
result := new(ResultEcho)
|
||||
err = json.Unmarshal(*msg.Result, result)
|
||||
err = json.Unmarshal(msg.Result, result)
|
||||
require.Nil(t, err)
|
||||
got := result.Value
|
||||
assert.Equal(t, got, val)
|
||||
|
@ -69,12 +69,12 @@ func (err RPCError) Error() string {
|
||||
type RPCResponse struct {
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
ID string `json:"id"`
|
||||
Result *json.RawMessage `json:"result,omitempty"`
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user