From 22414b3e9c2056abaabc8f2e24be09dc9fff439f Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Fri, 29 Jun 2018 01:56:35 +0200 Subject: [PATCH] More json.Marshal => cdc.MarshalJSON, can we lint this? --- client/lcd/lcd_test.go | 52 ++++++++++++++++++------------------ x/bank/client/rest/sendtx.go | 5 ++-- x/gov/client/rest/rest.go | 6 ++--- x/gov/client/rest/util.go | 5 ++-- x/stake/client/rest/tx.go | 5 ++-- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index eceb67971db4..feaadc922db2 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -621,9 +621,9 @@ func doSend(t *testing.T, port, seed, name, password string, addr sdk.Address) ( jsonStr := []byte(fmt.Sprintf(`{ "name":"%s", "password":"%s", - "account_number":%d, - "sequence":%d, - "gas": 10000, + "account_number":"%d", + "sequence":"%d", + "gas": "10000", "amount":[%s], "chain_id":"%s" }`, name, password, accnum, sequence, coinbz, chainID)) @@ -655,14 +655,14 @@ func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Add jsonStr := []byte(fmt.Sprintf(`{ "name":"%s", "password": "%s", - "account_number":%d, - "sequence": %d, - "gas": 100000, + "account_number":"%d", + "sequence": "%d", + "gas": "100000", "chain_id": "%s", "amount":[ { "denom": "%s", - "amount": 1 + "amount": "1" } ] }`, name, password, accnum, sequence, chainID, "steak")) @@ -704,15 +704,15 @@ func doDelegate(t *testing.T, port, seed, name, password string, delegatorAddr, jsonStr := []byte(fmt.Sprintf(`{ "name": "%s", "password": "%s", - "account_number": %d, - "sequence": %d, - "gas": 10000, + "account_number": "%d", + "sequence": "%d", + "gas": "10000", "chain_id": "%s", "delegations": [ { "delegator_addr": "%s", "validator_addr": "%s", - "bond": { "denom": "%s", "amount": 60 } + "bond": { "denom": "%s", "amount": "60" } } ], "begin_unbondings": [], @@ -747,9 +747,9 @@ func doBeginUnbonding(t *testing.T, port, seed, name, password string, jsonStr := []byte(fmt.Sprintf(`{ "name": "%s", "password": "%s", - "account_number": %d, - "sequence": %d, - "gas": 10000, + "account_number": "%d", + "sequence": "%d", + "gas": "10000", "chain_id": "%s", "delegations": [], "begin_unbondings": [ @@ -791,9 +791,9 @@ func doBeginRedelegation(t *testing.T, port, seed, name, password string, jsonStr := []byte(fmt.Sprintf(`{ "name": "%s", "password": "%s", - "account_number": %d, - "sequence": %d, - "gas": 10000, + "account_number": "%d", + "sequence": "%d", + "gas": "10000", "chain_id": "%s", "delegations": [], "begin_unbondings": [], @@ -925,9 +925,9 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA "name": "%s", "password": "%s", "chain_id": "%s", - "account_number": %d, - "sequence": %d, - "gas": 100000 + "account_number":"%d", + "sequence":"%d", + "gas":"100000" } }`, bechProposerAddr, name, password, chainID, accnum, sequence)) res, body := Request(t, port, "POST", "/gov/proposals", jsonStr) @@ -958,9 +958,9 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk "name": "%s", "password": "%s", "chain_id": "%s", - "account_number": %d, - "sequence": %d, - "gas": 100000 + "account_number":"%d", + "sequence": "%d", + "gas":"100000" } }`, bechProposerAddr, name, password, chainID, accnum, sequence)) res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/deposits", proposalID), jsonStr) @@ -991,9 +991,9 @@ func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.Ad "name": "%s", "password": "%s", "chain_id": "%s", - "account_number": %d, - "sequence": %d, - "gas": 100000 + "account_number": "%d", + "sequence": "%d", + "gas":"100000" } }`, bechProposerAddr, name, password, chainID, accnum, sequence)) res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/votes", proposalID), jsonStr) diff --git a/x/bank/client/rest/sendtx.go b/x/bank/client/rest/sendtx.go index 66b9e4ab16c4..3dd7656ccc30 100644 --- a/x/bank/client/rest/sendtx.go +++ b/x/bank/client/rest/sendtx.go @@ -1,12 +1,11 @@ package rest import ( - "encoding/json" "io/ioutil" "net/http" - "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/crypto/keys" + "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" @@ -111,7 +110,7 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreCont return } - output, err := json.MarshalIndent(res, "", " ") + output, err := wire.MarshalJSONIndent(cdc, res) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(err.Error())) diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 3bd8735c92a6..a47823ab320a 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -59,7 +59,7 @@ type voteReq struct { func postProposalHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req postProposalReq - err := buildReq(w, r, &req) + err := buildReq(w, r, cdc, &req) if err != nil { return } @@ -113,7 +113,7 @@ func depositHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreContext) } var req depositReq - err = buildReq(w, r, &req) + err = buildReq(w, r, cdc, &req) if err != nil { return } @@ -161,7 +161,7 @@ func voteHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreContext) ht } var req voteReq - err = buildReq(w, r, &req) + err = buildReq(w, r, cdc, &req) if err != nil { return } diff --git a/x/gov/client/rest/util.go b/x/gov/client/rest/util.go index 6bc90945c928..3f5fadbd72f9 100644 --- a/x/gov/client/rest/util.go +++ b/x/gov/client/rest/util.go @@ -1,7 +1,6 @@ package rest import ( - "encoding/json" "io/ioutil" "net/http" @@ -20,13 +19,13 @@ type baseReq struct { Gas int64 `json:"gas"` } -func buildReq(w http.ResponseWriter, r *http.Request, req interface{}) error { +func buildReq(w http.ResponseWriter, r *http.Request, cdc *wire.Codec, req interface{}) error { body, err := ioutil.ReadAll(r.Body) if err != nil { writeErr(&w, http.StatusBadRequest, err.Error()) return err } - err = json.Unmarshal(body, &req) + err = cdc.UnmarshalJSON(body, &req) if err != nil { writeErr(&w, http.StatusBadRequest, err.Error()) return err diff --git a/x/stake/client/rest/tx.go b/x/stake/client/rest/tx.go index 0c713481cb07..1d854766229c 100644 --- a/x/stake/client/rest/tx.go +++ b/x/stake/client/rest/tx.go @@ -2,7 +2,6 @@ package rest import ( "bytes" - "encoding/json" "fmt" "io/ioutil" "net/http" @@ -74,7 +73,7 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte w.Write([]byte(err.Error())) return } - err = json.Unmarshal(body, &m) + err = cdc.UnmarshalJSON(body, &m) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) @@ -285,7 +284,7 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte results[i] = res } - output, err := json.MarshalIndent(results[:], "", " ") + output, err := wire.MarshalJSONIndent(cdc, results[:]) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(err.Error()))