mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-30 09:12:14 +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
|
continue
|
||||||
}
|
}
|
||||||
result := new(ctypes.ResultEvent)
|
result := new(ctypes.ResultEvent)
|
||||||
err := json.Unmarshal(*resp.Result, result)
|
err := json.Unmarshal(resp.Result, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// ignore silently (eg. subscribe, unsubscribe and maybe other events)
|
// ignore silently (eg. subscribe, unsubscribe and maybe other events)
|
||||||
// TODO: ?
|
// TODO: ?
|
||||||
|
@ -153,7 +153,7 @@ func unmarshalResponseBytes(responseBytes []byte, result interface{}) (interface
|
|||||||
return nil, errors.Errorf("Response error: %v", response.Error)
|
return nil, errors.Errorf("Response error: %v", response.Error)
|
||||||
}
|
}
|
||||||
// unmarshal the RawMessage into the result
|
// unmarshal the RawMessage into the result
|
||||||
err = json.Unmarshal(*response.Result, result)
|
err = json.Unmarshal(response.Result, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("Error unmarshalling rpc response result: %v", err)
|
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()
|
h.mtx.RUnlock()
|
||||||
|
|
||||||
res := json.RawMessage(`{}`)
|
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 {
|
if err := conn.WriteMessage(messageType, emptyRespBytes); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ func callWgDoneOnResult(t *testing.T, c *WSClient, wg *sync.WaitGroup) {
|
|||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
t.Fatalf("unexpected error: %v", resp.Error)
|
t.Fatalf("unexpected error: %v", resp.Error)
|
||||||
}
|
}
|
||||||
if *resp.Result != nil {
|
if resp.Result != nil {
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}
|
}
|
||||||
case <-c.Quit:
|
case <-c.Quit:
|
||||||
|
@ -223,7 +223,7 @@ func echoViaWS(cl *client.WSClient, val string) (string, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
result := new(ResultEcho)
|
result := new(ResultEcho)
|
||||||
err = json.Unmarshal(*msg.Result, result)
|
err = json.Unmarshal(msg.Result, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ func echoBytesViaWS(cl *client.WSClient, bytes []byte) ([]byte, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
result := new(ResultEchoBytes)
|
result := new(ResultEchoBytes)
|
||||||
err = json.Unmarshal(*msg.Result, result)
|
err = json.Unmarshal(msg.Result, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
@ -328,7 +328,7 @@ func TestWSNewWSRPCFunc(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
result := new(ResultEcho)
|
result := new(ResultEcho)
|
||||||
err = json.Unmarshal(*msg.Result, result)
|
err = json.Unmarshal(msg.Result, result)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
got := result.Value
|
got := result.Value
|
||||||
assert.Equal(t, got, val)
|
assert.Equal(t, got, val)
|
||||||
@ -353,7 +353,7 @@ func TestWSHandlesArrayParams(t *testing.T) {
|
|||||||
t.Fatalf("%+v", err)
|
t.Fatalf("%+v", err)
|
||||||
}
|
}
|
||||||
result := new(ResultEcho)
|
result := new(ResultEcho)
|
||||||
err = json.Unmarshal(*msg.Result, result)
|
err = json.Unmarshal(msg.Result, result)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
got := result.Value
|
got := result.Value
|
||||||
assert.Equal(t, got, val)
|
assert.Equal(t, got, val)
|
||||||
|
@ -69,12 +69,12 @@ func (err RPCError) Error() string {
|
|||||||
type RPCResponse struct {
|
type RPCResponse struct {
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Result *json.RawMessage `json:"result,omitempty"`
|
Result json.RawMessage `json:"result,omitempty"`
|
||||||
Error *RPCError `json:"error,omitempty"`
|
Error *RPCError `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRPCSuccessResponse(id string, res interface{}) RPCResponse {
|
func NewRPCSuccessResponse(id string, res interface{}) RPCResponse {
|
||||||
var raw *json.RawMessage
|
var rawMsg json.RawMessage
|
||||||
|
|
||||||
if res != nil {
|
if res != nil {
|
||||||
var js []byte
|
var js []byte
|
||||||
@ -82,11 +82,10 @@ func NewRPCSuccessResponse(id string, res interface{}) RPCResponse {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return RPCInternalError(id, errors.Wrap(err, "Error marshalling response"))
|
return RPCInternalError(id, errors.Wrap(err, "Error marshalling response"))
|
||||||
}
|
}
|
||||||
rawMsg := json.RawMessage(js)
|
rawMsg = json.RawMessage(js)
|
||||||
raw = &rawMsg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
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 {
|
func (resp RPCResponse) String() string {
|
||||||
if resp.Error == nil {
|
if resp.Error != nil {
|
||||||
return fmt.Sprintf("[%s %v]", resp.ID, resp.Result)
|
return fmt.Sprintf("[%s %v]", resp.ID, resp.Result)
|
||||||
} else {
|
} else {
|
||||||
return fmt.Sprintf("[%s %s]", resp.ID, resp.Error)
|
return fmt.Sprintf("[%s %s]", resp.ID, resp.Error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user