Skip to content

Commit

Permalink
fix: use Tendermint JSON serlization for JSON RPC results
Browse files Browse the repository at this point in the history
  • Loading branch information
tzdybal committed Jul 4, 2022
1 parent e454904 commit 27d3eae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion rpc/json/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ func (h *handler) serveJSONRPCforWS(w http.ResponseWriter, r *http.Request, wsCo

// Encode the response.
if errResult == nil {
codecReq.WriteResponse(w, rets[0].Interface())
var raw json.RawMessage
raw, err = tmjson.Marshal(rets[0].Interface())
if err != nil {
codecReq.WriteError(w, http.StatusInternalServerError, err)
return
}
codecReq.WriteResponse(w, raw)
} else {
codecReq.WriteError(w, statusCode, errResult)
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestStringyRequest(t *testing.T) {
// `starport chain faucet ...` generates broken JSON (ints are "quoted" as strings)
brokenJSON := `{"jsonrpc":"2.0","id":0,"method":"tx_search","params":{"order_by":"","page":"1","per_page":"1000","prove":true,"query":"message.sender='cosmos1njr26e02fjcq3schxstv458a3w5szp678h23dh' AND transfer.recipient='cosmos1e0ajth0s847kqcu2ssnhut32fsrptf94fqnfzx'"}}`

respJson := `{"jsonrpc":"2.0","result":{"txs":[],"total_count":0},"id":0}` + "\n"
respJson := `{"jsonrpc":"2.0","result":{"txs":[],"total_count":"0"},"id":0}` + "\n"

req := httptest.NewRequest(http.MethodGet, "/", strings.NewReader(brokenJSON))
resp := httptest.NewRecorder()
Expand Down

0 comments on commit 27d3eae

Please sign in to comment.