Skip to content

Commit

Permalink
More json.Marshal => cdc.MarshalJSON, can we lint this?
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Jun 28, 2018
1 parent 3533fc5 commit 22414b3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 38 deletions.
52 changes: 26 additions & 26 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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": [],
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [],
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions x/bank/client/rest/sendtx.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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()))
Expand Down
6 changes: 3 additions & 3 deletions x/gov/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions x/gov/client/rest/util.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rest

import (
"encoding/json"
"io/ioutil"
"net/http"

Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions x/stake/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rest

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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()))
Expand Down

0 comments on commit 22414b3

Please sign in to comment.