From 27d3eae7441a96fa870030c7fcc7e276287eb507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 4 Jul 2022 16:14:53 +0200 Subject: [PATCH] fix: use Tendermint JSON serlization for JSON RPC results --- rpc/json/handler.go | 8 +++++++- rpc/json/service_test.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rpc/json/handler.go b/rpc/json/handler.go index fcb6b8a6d5d..a98038687a3 100644 --- a/rpc/json/handler.go +++ b/rpc/json/handler.go @@ -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) } diff --git a/rpc/json/service_test.go b/rpc/json/service_test.go index 6bab66fdc8b..4094632ed45 100644 --- a/rpc/json/service_test.go +++ b/rpc/json/service_test.go @@ -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()