diff --git a/client/context.go b/client/context.go index cffa8ba768c0..907764333372 100644 --- a/client/context.go +++ b/client/context.go @@ -370,10 +370,10 @@ func (ctx Context) PrintOutput(toPrint interface{}) error { out, err = yaml.Marshal(&toPrint) case "json": + out, err = ctx.JSONMarshaler.MarshalJSON(toPrint) + if ctx.Indent { - out, err = ctx.Codec.MarshalJSONIndent(toPrint, "", " ") - } else { - out, err = ctx.Codec.MarshalJSON(toPrint) + out, err = codec.MarshalIndentFromJSON(out) } } diff --git a/x/auth/client/cli/broadcast.go b/x/auth/client/cli/broadcast.go index 9e24d63e5a38..61567b3e06bd 100644 --- a/x/auth/client/cli/broadcast.go +++ b/x/auth/client/cli/broadcast.go @@ -26,7 +26,7 @@ $ tx broadcast ./mytxn.json `), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) if clientCtx.Offline { return errors.New("cannot broadcast tx during offline mode") diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index efd124921b52..a5b8b46a4cb2 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -29,9 +29,9 @@ func GetDecodeCommand(codec *codec.Codec) *cobra.Command { return flags.PostCommands(cmd)[0] } -func runDecodeTxString(codec *codec.Codec) func(cmd *cobra.Command, args []string) (err error) { +func runDecodeTxString(cdc *codec.Codec) func(cmd *cobra.Command, args []string) (err error) { return func(cmd *cobra.Command, args []string) (err error) { - clientCtx := client.NewContext().WithCodec(codec).WithOutput(cmd.OutOrStdout()) + clientCtx := client.NewContext().WithCodec(cdc).WithOutput(cmd.OutOrStdout()).WithJSONMarshaler(cdc) var txBytes []byte if viper.GetBool(flagHex) { diff --git a/x/auth/client/cli/encode.go b/x/auth/client/cli/encode.go index c97533c859ef..3a0726729907 100644 --- a/x/auth/client/cli/encode.go +++ b/x/auth/client/cli/encode.go @@ -29,7 +29,7 @@ Read a transaction from , serialize it to the Amino wire protocol, and out If you supply a dash (-) argument in place of an input filename, the command reads from standard input.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) stdTx, err := authclient.ReadStdTxFromFile(clientCtx.Codec, args[0]) if err != nil { diff --git a/x/auth/client/rest.go b/x/auth/client/rest.go index 98f40786bcf6..f825be42f144 100644 --- a/x/auth/client/rest.go +++ b/x/auth/client/rest.go @@ -51,7 +51,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, clientCtx client.Context, return } - output, err := clientCtx.Codec.MarshalJSON(types.NewStdTx(stdMsg.Msgs, stdMsg.Fee, nil, stdMsg.Memo)) + output, err := clientCtx.JSONMarshaler.MarshalJSON(types.NewStdTx(stdMsg.Msgs, stdMsg.Fee, nil, stdMsg.Memo)) if rest.CheckInternalServerError(w, err) { return } diff --git a/x/auth/client/rest/broadcast.go b/x/auth/client/rest/broadcast.go index 1c988c58e7d0..4508f2e69393 100644 --- a/x/auth/client/rest/broadcast.go +++ b/x/auth/client/rest/broadcast.go @@ -27,7 +27,7 @@ func BroadcastTxRequest(clientCtx client.Context) http.HandlerFunc { return } - if err := clientCtx.Codec.UnmarshalJSON(body, &req); rest.CheckBadRequestError(w, err) { + if err := clientCtx.JSONMarshaler.UnmarshalJSON(body, &req); rest.CheckBadRequestError(w, err) { return } diff --git a/x/auth/client/rest/decode.go b/x/auth/client/rest/decode.go index 9d42d10f950a..dd6f23833e32 100644 --- a/x/auth/client/rest/decode.go +++ b/x/auth/client/rest/decode.go @@ -32,7 +32,7 @@ func DecodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return } - err = clientCtx.Codec.UnmarshalJSON(body, &req) + err = clientCtx.JSONMarshaler.UnmarshalJSON(body, &req) if rest.CheckBadRequestError(w, err) { return } diff --git a/x/auth/client/rest/encode.go b/x/auth/client/rest/encode.go index fd1d48fc84a1..4f7c495506db 100644 --- a/x/auth/client/rest/encode.go +++ b/x/auth/client/rest/encode.go @@ -27,7 +27,7 @@ func EncodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc { return } - err = clientCtx.Codec.UnmarshalJSON(body, &req) + err = clientCtx.JSONMarshaler.UnmarshalJSON(body, &req) if rest.CheckBadRequestError(w, err) { return } diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index d8dfb531b051..a6932aa50a8a 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -85,14 +85,12 @@ func CompleteAndBroadcastTxCLI(txBldr authtypes.TxBuilder, clientCtx client.Cont return err } - var json []byte + json := clientCtx.JSONMarshaler.MustMarshalJSON(stdSignMsg) if viper.GetBool(flags.FlagIndentResponse) { - json, err = clientCtx.Codec.MarshalJSONIndent(stdSignMsg, "", " ") + json, err = codec.MarshalIndentFromJSON(json) if err != nil { panic(err) } - } else { - json = clientCtx.Codec.MustMarshalJSON(stdSignMsg) } _, _ = fmt.Fprintf(os.Stderr, "%s\n\n", json) @@ -161,16 +159,18 @@ func PrintUnsignedStdTx(txBldr authtypes.TxBuilder, clientCtx client.Context, ms return err } - var json []byte - if viper.GetBool(flags.FlagIndentResponse) { - json, err = clientCtx.Codec.MarshalJSONIndent(stdTx, "", " ") - } else { - json, err = clientCtx.Codec.MarshalJSON(stdTx) - } + json, err := clientCtx.JSONMarshaler.MarshalJSON(stdTx) if err != nil { return err } + if viper.GetBool(flags.FlagIndentResponse) { + json, err = codec.MarshalIndentFromJSON(json) + if err != nil { + return err + } + } + _, _ = fmt.Fprintf(clientCtx.Output, "%s\n", json) return nil } diff --git a/x/bank/client/cli/query.go b/x/bank/client/cli/query.go index 533db577d9c6..2d7ce79e0ad6 100644 --- a/x/bank/client/cli/query.go +++ b/x/bank/client/cli/query.go @@ -57,7 +57,7 @@ func GetBalancesCmd(cdc *codec.Codec) *cobra.Command { Short: "Query for account balances by address", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) addr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -135,7 +135,7 @@ $ %s query %s total stake ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) if len(args) == 0 { return queryTotalSupply(clientCtx, cdc) diff --git a/x/bank/client/rest/query.go b/x/bank/client/rest/query.go index 524ed077aaf0..f282115f7c19 100644 --- a/x/bank/client/rest/query.go +++ b/x/bank/client/rest/query.go @@ -85,7 +85,7 @@ func totalSupplyHandlerFn(clientCtx client.Context) http.HandlerFunc { } params := types.NewQueryTotalSupplyParams(page, limit) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return @@ -112,7 +112,7 @@ func supplyOfHandlerFn(clientCtx client.Context) http.HandlerFunc { } params := types.NewQuerySupplyOfParams(denom) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return diff --git a/x/distribution/client/cli/query.go b/x/distribution/client/cli/query.go index 720cfe9d22bc..105928c61c4f 100644 --- a/x/distribution/client/cli/query.go +++ b/x/distribution/client/cli/query.go @@ -45,7 +45,7 @@ func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { Args: cobra.NoArgs, Short: "Query distribution params", RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams) res, _, err := clientCtx.QueryWithData(route, nil) @@ -80,7 +80,7 @@ $ %s query distribution validator-outstanding-rewards cosmosvaloper1lwjmdnks33xw ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) valAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -127,7 +127,7 @@ $ %s query distribution commission cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9l ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) validatorAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -162,7 +162,7 @@ $ %s query distribution slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmq ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) validatorAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -216,7 +216,7 @@ $ %s query distribution rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p co ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // query for rewards from a particular delegation if len(args) == 2 { @@ -277,7 +277,7 @@ $ %s query distribution community-pool ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", queryRoute), nil) if err != nil { diff --git a/x/distribution/client/common/common.go b/x/distribution/client/common/common.go index ab2c267ba931..312698bc22a6 100644 --- a/x/distribution/client/common/common.go +++ b/x/distribution/client/common/common.go @@ -22,7 +22,7 @@ func QueryDelegationRewards(clientCtx client.Context, queryRoute, delAddr, valAd } params := types.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { return nil, 0, fmt.Errorf("failed to marshal params: %w", err) } @@ -36,7 +36,7 @@ func QueryDelegationRewards(clientCtx client.Context, queryRoute, delAddr, valAd func QueryDelegatorValidators(clientCtx client.Context, queryRoute string, delegatorAddr sdk.AccAddress) ([]byte, error) { res, _, err := clientCtx.QueryWithData( fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryDelegatorValidators), - clientCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)), + clientCtx.JSONMarshaler.MustMarshalJSON(types.NewQueryDelegatorParams(delegatorAddr)), ) return res, err } @@ -45,7 +45,7 @@ func QueryDelegatorValidators(clientCtx client.Context, queryRoute string, deleg func QueryValidatorCommission(clientCtx client.Context, queryRoute string, validatorAddr sdk.ValAddress) ([]byte, error) { res, _, err := clientCtx.QueryWithData( fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorCommission), - clientCtx.Codec.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)), + clientCtx.JSONMarshaler.MustMarshalJSON(types.NewQueryValidatorCommissionParams(validatorAddr)), ) return res, err } @@ -61,7 +61,7 @@ func WithdrawAllDelegatorRewards(clientCtx client.Context, queryRoute string, de } var validators []sdk.ValAddress - if err := clientCtx.Codec.UnmarshalJSON(bz, &validators); err != nil { + if err := clientCtx.JSONMarshaler.UnmarshalJSON(bz, &validators); err != nil { return nil, err } diff --git a/x/distribution/client/common/common_test.go b/x/distribution/client/common/common_test.go index b08fde7e8004..8f81ec0f2365 100644 --- a/x/distribution/client/common/common_test.go +++ b/x/distribution/client/common/common_test.go @@ -8,17 +8,18 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/distribution/types" ) func TestQueryDelegationRewardsAddrValidation(t *testing.T) { - cdc := codec.New() viper.Set(flags.FlagOffline, true) - ctx := client.NewContext().WithCodec(cdc) + ctx := client.NewContext().WithJSONMarshaler(types.ModuleCdc) + type args struct { delAddr string valAddr string } + tests := []struct { name string args args @@ -30,6 +31,7 @@ func TestQueryDelegationRewardsAddrValidation(t *testing.T) { {"invalid validator address", args{"cosmos1zxcsu7l5qxs53lvp0fqgd09a9r2g6kqrk2cdpa", "invalid"}, nil, true}, {"empty validator address", args{"cosmos1zxcsu7l5qxs53lvp0fqgd09a9r2g6kqrk2cdpa", ""}, nil, true}, } + for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { diff --git a/x/distribution/client/rest/query.go b/x/distribution/client/rest/query.go index f3a889a946cd..57b1293e8d83 100644 --- a/x/distribution/client/rest/query.go +++ b/x/distribution/client/rest/query.go @@ -79,7 +79,7 @@ func delegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { } params := types.NewQueryDelegatorParams(delegatorAddr) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal params: %s", err)) return @@ -131,7 +131,7 @@ func delegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.HandlerFunc return } - bz := clientCtx.Codec.MustMarshalJSON(types.NewQueryDelegatorWithdrawAddrParams(delegatorAddr)) + bz := clientCtx.JSONMarshaler.MustMarshalJSON(types.NewQueryDelegatorWithdrawAddrParams(delegatorAddr)) res, height, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/withdraw_addr", types.QuerierRoute), bz) if rest.CheckInternalServerError(w, err) { return @@ -180,7 +180,7 @@ func validatorInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { } var commission types.ValidatorAccumulatedCommission - if rest.CheckInternalServerError(w, clientCtx.Codec.UnmarshalJSON(bz, &commission)) { + if rest.CheckInternalServerError(w, clientCtx.JSONMarshaler.UnmarshalJSON(bz, &commission)) { return } @@ -192,11 +192,11 @@ func validatorInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { } var rewards sdk.DecCoins - if rest.CheckInternalServerError(w, clientCtx.Codec.UnmarshalJSON(bz, &rewards)) { + if rest.CheckInternalServerError(w, clientCtx.JSONMarshaler.UnmarshalJSON(bz, &rewards)) { return } - bz, err = clientCtx.Codec.MarshalJSON(NewValidatorDistInfo(delAddr, rewards, commission)) + bz, err = clientCtx.JSONMarshaler.MarshalJSON(NewValidatorDistInfo(delAddr, rewards, commission)) if rest.CheckInternalServerError(w, err) { return } @@ -263,7 +263,7 @@ func communityPoolHandler(clientCtx client.Context) http.HandlerFunc { } var result sdk.DecCoins - if rest.CheckInternalServerError(w, clientCtx.Codec.UnmarshalJSON(res, &result)) { + if rest.CheckInternalServerError(w, clientCtx.JSONMarshaler.UnmarshalJSON(res, &result)) { return } @@ -285,7 +285,7 @@ func outstandingRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc { return } - bin := clientCtx.Codec.MustMarshalJSON(types.NewQueryValidatorOutstandingRewardsParams(validatorAddr)) + bin := clientCtx.JSONMarshaler.MustMarshalJSON(types.NewQueryValidatorOutstandingRewardsParams(validatorAddr)) res, height, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/validator_outstanding_rewards", types.QuerierRoute), bin) if rest.CheckInternalServerError(w, err) { return diff --git a/x/evidence/client/cli/query.go b/x/evidence/client/cli/query.go index 4eb1b4e51b74..b3218b96b552 100644 --- a/x/evidence/client/cli/query.go +++ b/x/evidence/client/cli/query.go @@ -52,7 +52,7 @@ func QueryEvidenceCmd(cdc *codec.Codec) func(*cobra.Command, []string) error { return err } - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) if hash := args[0]; hash != "" { return queryEvidence(cdc, clientCtx, hash) diff --git a/x/evidence/client/rest/query.go b/x/evidence/client/rest/query.go index 5e8ed2aeeffa..84138525b31e 100644 --- a/x/evidence/client/rest/query.go +++ b/x/evidence/client/rest/query.go @@ -40,7 +40,7 @@ func queryEvidenceHandler(clientCtx client.Context) http.HandlerFunc { } params := types.NewQueryEvidenceParams(evidenceHash) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err)) return @@ -70,7 +70,7 @@ func queryAllEvidenceHandler(clientCtx client.Context) http.HandlerFunc { } params := types.NewQueryAllEvidenceParams(page, limit) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err)) return diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 5de254415358..68b96fe3571b 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -121,7 +121,7 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, sm } txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc) + clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc).WithJSONMarshaler(cdc) // Set the generate-only flag here after the CLI context has // been created. This allows the from name/key to be correctly populated. diff --git a/x/genutil/client/rest/query.go b/x/genutil/client/rest/query.go index dcb932be5034..62fe40546269 100644 --- a/x/genutil/client/rest/query.go +++ b/x/genutil/client/rest/query.go @@ -34,7 +34,7 @@ func QueryGenesisTxs(clientCtx client.Context, w http.ResponseWriter) { genState := types.GetGenesisStateFromAppState(clientCtx.Codec, appState) genTxs := make([]sdk.Tx, len(genState.GenTxs)) for i, tx := range genState.GenTxs { - err := clientCtx.Codec.UnmarshalJSON(tx, &genTxs[i]) + err := clientCtx.JSONMarshaler.UnmarshalJSON(tx, &genTxs[i]) if err != nil { rest.WriteErrorResponse( w, http.StatusInternalServerError, diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index a064549fae3b..fd52c0b140b1 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -60,7 +60,7 @@ $ %s query gov proposal 1 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -140,7 +140,7 @@ $ %s query gov proposals --page=2 --limit=100 return err } - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/proposals", queryRoute), bz) if err != nil { @@ -187,7 +187,7 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -257,7 +257,7 @@ $ %[1]s query gov votes 1 --page=2 --limit=100 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -321,7 +321,7 @@ $ %s query gov deposit 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -384,7 +384,7 @@ $ %s query gov deposits 1 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -442,7 +442,7 @@ $ %s query gov tally 1 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -492,7 +492,7 @@ $ %s query gov params ), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) tp, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/tallying", queryRoute), nil) if err != nil { return err @@ -536,7 +536,7 @@ $ %s query gov param deposit ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // Query store res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, args[0]), nil) @@ -582,7 +582,7 @@ $ %s query gov proposer 1 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // validate that the proposalID is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) diff --git a/x/gov/client/rest/query.go b/x/gov/client/rest/query.go index f9a1174cfe7e..7c7228a3b22e 100644 --- a/x/gov/client/rest/query.go +++ b/x/gov/client/rest/query.go @@ -69,7 +69,7 @@ func queryProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQueryProposalParams(proposalID) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -101,7 +101,7 @@ func queryDepositsHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQueryProposalParams(proposalID) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -112,7 +112,7 @@ func queryDepositsHandlerFn(clientCtx client.Context) http.HandlerFunc { } var proposal types.Proposal - if rest.CheckInternalServerError(w, clientCtx.Codec.UnmarshalJSON(res, &proposal)) { + if rest.CheckInternalServerError(w, clientCtx.JSONMarshaler.UnmarshalJSON(res, &proposal)) { return } @@ -192,7 +192,7 @@ func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQueryDepositParams(proposalID, depositorAddr) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -203,7 +203,7 @@ func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { } var deposit types.Deposit - if rest.CheckBadRequestError(w, clientCtx.Codec.UnmarshalJSON(res, &deposit)) { + if rest.CheckBadRequestError(w, clientCtx.JSONMarshaler.UnmarshalJSON(res, &deposit)) { return } @@ -211,7 +211,7 @@ func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc { // which case the deposit would be removed from state and should be queried // for directly via a txs query. if deposit.Empty() { - bz, err := clientCtx.Codec.MarshalJSON(types.NewQueryProposalParams(proposalID)) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(types.NewQueryProposalParams(proposalID)) if rest.CheckBadRequestError(w, err) { return } @@ -269,7 +269,7 @@ func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQueryVoteParams(proposalID, voterAddr) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -280,7 +280,7 @@ func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { } var vote types.Vote - if rest.CheckBadRequestError(w, clientCtx.Codec.UnmarshalJSON(res, &vote)) { + if rest.CheckBadRequestError(w, clientCtx.JSONMarshaler.UnmarshalJSON(res, &vote)) { return } @@ -288,7 +288,7 @@ func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc { // which case the vote would be removed from state and should be queried for // directly via a txs query. if vote.Empty() { - bz, err := clientCtx.Codec.MarshalJSON(types.NewQueryProposalParams(proposalID)) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(types.NewQueryProposalParams(proposalID)) if rest.CheckBadRequestError(w, err) { return } @@ -339,7 +339,7 @@ func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQueryProposalVotesParams(proposalID, page, limit) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -350,7 +350,7 @@ func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { } var proposal types.Proposal - if rest.CheckInternalServerError(w, clientCtx.Codec.UnmarshalJSON(res, &proposal)) { + if rest.CheckInternalServerError(w, clientCtx.JSONMarshaler.UnmarshalJSON(res, &proposal)) { return } @@ -412,7 +412,7 @@ func queryProposalsWithParameterFn(clientCtx client.Context) http.HandlerFunc { } params := types.NewQueryProposalsParams(page, limit, proposalStatus, voterAddr, depositorAddr) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -452,7 +452,7 @@ func queryTallyOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQueryProposalParams(proposalID) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } diff --git a/x/gov/client/utils/query.go b/x/gov/client/utils/query.go index 6739dc1bc224..b4ff81902f5e 100644 --- a/x/gov/client/utils/query.go +++ b/x/gov/client/utils/query.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -65,11 +66,16 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params types.QueryProposal } } + bz, err := clientCtx.JSONMarshaler.MarshalJSON(deposits) + if err != nil { + return nil, err + } + if clientCtx.Indent { - return clientCtx.Codec.MarshalJSONIndent(deposits, "", " ") + return codec.MarshalIndentFromJSON(bz) } - return clientCtx.Codec.MarshalJSON(deposits) + return bz, nil } // QueryVotesByTxQuery will query for votes via a direct txs tags query. It @@ -115,10 +121,17 @@ func QueryVotesByTxQuery(clientCtx client.Context, params types.QueryProposalVot } else { votes = votes[start:end] } + + bz, err := clientCtx.JSONMarshaler.MarshalJSON(votes) + if err != nil { + return nil, err + } + if clientCtx.Indent { - return clientCtx.Codec.MarshalJSONIndent(votes, "", " ") + return codec.MarshalIndentFromJSON(bz) } - return clientCtx.Codec.MarshalJSON(votes) + + return bz, nil } // QueryVoteByTxQuery will query for a single vote via a direct txs tags query. @@ -147,11 +160,16 @@ func QueryVoteByTxQuery(clientCtx client.Context, params types.QueryVoteParams) Option: voteMsg.Option, } + bz, err := clientCtx.JSONMarshaler.MarshalJSON(vote) + if err != nil { + return nil, err + } + if clientCtx.Indent { - return clientCtx.Codec.MarshalJSONIndent(vote, "", " ") + return codec.MarshalIndentFromJSON(bz) } - return clientCtx.Codec.MarshalJSON(vote) + return bz, nil } } } @@ -187,11 +205,16 @@ func QueryDepositByTxQuery(clientCtx client.Context, params types.QueryDepositPa Amount: depMsg.Amount, } + bz, err := clientCtx.JSONMarshaler.MarshalJSON(deposit) + if err != nil { + return nil, err + } + if clientCtx.Indent { - return clientCtx.Codec.MarshalJSONIndent(deposit, "", " ") + return codec.MarshalIndentFromJSON(bz) } - return clientCtx.Codec.MarshalJSON(deposit) + return bz, nil } } } @@ -230,7 +253,7 @@ func QueryProposerByTxQuery(clientCtx client.Context, proposalID uint64) (Propos // QueryProposalByID takes a proposalID and returns a proposal func QueryProposalByID(proposalID uint64, clientCtx client.Context, queryRoute string) ([]byte, error) { params := types.NewQueryProposalParams(proposalID) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { return nil, err } diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index ede1abf09d0d..c7deca45b82d 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -129,25 +129,33 @@ func TestGetPaginatedVotes(t *testing.T) { }, }, } { + tc := tc + t.Run(tc.description, func(t *testing.T) { var ( marshalled = make([]tmtypes.Tx, len(tc.txs)) cdc = newTestCodec() ) + for i := range tc.txs { tx, err := cdc.MarshalBinaryBare(&tc.txs[i]) require.NoError(t, err) marshalled[i] = tx } + cli := TxSearchMock{txs: marshalled} - clientCtx := client.Context{}.WithCodec(cdc).WithTrustNode(true).WithClient(cli) + clientCtx := client.Context{}. + WithJSONMarshaler(cdc). + WithCodec(cdc). + WithTrustNode(true). + WithClient(cli) params := types.NewQueryProposalVotesParams(0, tc.page, tc.limit) votesData, err := QueryVotesByTxQuery(clientCtx, params) require.NoError(t, err) votes := []types.Vote{} - require.NoError(t, clientCtx.Codec.UnmarshalJSON(votesData, &votes)) + require.NoError(t, clientCtx.JSONMarshaler.UnmarshalJSON(votesData, &votes)) require.Equal(t, len(tc.votes), len(votes)) for i := range votes { require.Equal(t, tc.votes[i], votes[i]) diff --git a/x/ibc/02-client/client/rest/query.go b/x/ibc/02-client/client/rest/query.go index b3f115583552..91d3c7684173 100644 --- a/x/ibc/02-client/client/rest/query.go +++ b/x/ibc/02-client/client/rest/query.go @@ -145,7 +145,7 @@ func queryHeaderHandlerFn(clientCtx client.Context) http.HandlerFunc { return } - res := clientCtx.Codec.MustMarshalJSON(header) + res := clientCtx.JSONMarshaler.MustMarshalJSON(header) clientCtx = clientCtx.WithHeight(height) rest.PostProcessResponse(w, clientCtx, res) } @@ -166,7 +166,7 @@ func queryNodeConsensusStateHandlerFn(clientCtx client.Context) http.HandlerFunc rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) } - res := clientCtx.Codec.MustMarshalJSON(state) + res := clientCtx.JSONMarshaler.MustMarshalJSON(state) clientCtx = clientCtx.WithHeight(height) rest.PostProcessResponse(w, clientCtx, res) } diff --git a/x/ibc/02-client/client/utils/utils.go b/x/ibc/02-client/client/utils/utils.go index 6acfac44a34d..b8754e8902db 100644 --- a/x/ibc/02-client/client/utils/utils.go +++ b/x/ibc/02-client/client/utils/utils.go @@ -18,7 +18,7 @@ import ( // any merkle proof. func QueryAllClientStates(clientCtx client.Context, page, limit int) ([]exported.ClientState, int64, error) { params := types.NewQueryAllClientsParams(page, limit) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { return nil, 0, fmt.Errorf("failed to marshal query params: %w", err) } @@ -30,7 +30,7 @@ func QueryAllClientStates(clientCtx client.Context, page, limit int) ([]exported } var clients []exported.ClientState - err = clientCtx.Codec.UnmarshalJSON(res, &clients) + err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &clients) if err != nil { return nil, 0, fmt.Errorf("failed to unmarshal light clients: %w", err) } diff --git a/x/ibc/03-connection/client/utils/utils.go b/x/ibc/03-connection/client/utils/utils.go index 5694dac36759..4c5d7af101f7 100644 --- a/x/ibc/03-connection/client/utils/utils.go +++ b/x/ibc/03-connection/client/utils/utils.go @@ -19,7 +19,7 @@ import ( // any merkle proof. func QueryAllConnections(clientCtx client.Context, page, limit int) ([]types.ConnectionEnd, int64, error) { params := types.NewQueryAllConnectionsParams(page, limit) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { return nil, 0, fmt.Errorf("failed to marshal query params: %w", err) } @@ -31,7 +31,7 @@ func QueryAllConnections(clientCtx client.Context, page, limit int) ([]types.Con } var connections []types.ConnectionEnd - err = clientCtx.Codec.UnmarshalJSON(res, &connections) + err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &connections) if err != nil { return nil, 0, fmt.Errorf("failed to unmarshal connections: %w", err) } @@ -68,7 +68,7 @@ func QueryConnection( // _does not_ return any merkle proof. func QueryAllClientConnectionPaths(clientCtx client.Context, page, limit int) ([]types.ConnectionPaths, int64, error) { params := types.NewQueryAllConnectionsParams(page, limit) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { return nil, 0, fmt.Errorf("failed to marshal query params: %w", err) } @@ -80,7 +80,7 @@ func QueryAllClientConnectionPaths(clientCtx client.Context, page, limit int) ([ } var connectionPaths []types.ConnectionPaths - err = clientCtx.Codec.UnmarshalJSON(res, &connectionPaths) + err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &connectionPaths) if err != nil { return nil, 0, fmt.Errorf("failed to unmarshal client connection paths: %w", err) } diff --git a/x/ibc/04-channel/client/utils/utils.go b/x/ibc/04-channel/client/utils/utils.go index 58aa32d1eb09..61c6c7b4f268 100644 --- a/x/ibc/04-channel/client/utils/utils.go +++ b/x/ibc/04-channel/client/utils/utils.go @@ -76,7 +76,7 @@ func QueryChannel( // a Channel. func QueryChannelClientState(clientCtx client.Context, portID, channelID string) (clientexported.ClientState, int64, error) { params := types.NewQueryChannelClientStateParams(portID, channelID) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { return nil, 0, fmt.Errorf("failed to marshal query params: %w", err) } @@ -88,7 +88,7 @@ func QueryChannelClientState(clientCtx client.Context, portID, channelID string) } var clientState clientexported.ClientState - err = clientCtx.Codec.UnmarshalJSON(res, &clientState) + err = clientCtx.JSONMarshaler.UnmarshalJSON(res, &clientState) if err != nil { return nil, 0, fmt.Errorf("failed to unmarshal connections: %w", err) } diff --git a/x/mint/client/cli/query.go b/x/mint/client/cli/query.go index 9815868e8de5..0aa91a1a4d26 100644 --- a/x/mint/client/cli/query.go +++ b/x/mint/client/cli/query.go @@ -41,7 +41,7 @@ func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { Short: "Query the current minting parameters", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters) res, _, err := clientCtx.QueryWithData(route, nil) @@ -67,7 +67,7 @@ func GetCmdQueryInflation(cdc *codec.Codec) *cobra.Command { Short: "Query the current minting inflation value", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation) res, _, err := clientCtx.QueryWithData(route, nil) @@ -93,7 +93,7 @@ func GetCmdQueryAnnualProvisions(cdc *codec.Codec) *cobra.Command { Short: "Query the current minting annual provisions value", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions) res, _, err := clientCtx.QueryWithData(route, nil) diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index 442096885fbb..63f90788b1ae 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -47,7 +47,7 @@ $ query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdge `), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, args[0]) if err != nil { @@ -88,7 +88,7 @@ func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { $ query slashing params `), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) route := fmt.Sprintf("custom/%s/parameters", types.QuerierRoute) res, _, err := clientCtx.QueryWithData(route, nil) diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index edc54c14377e..179b17f75422 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -45,7 +45,7 @@ func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQuerySigningInfoParams(sdk.ConsAddress(pk.Address())) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -75,7 +75,7 @@ func signingInfoHandlerListFn(clientCtx client.Context) http.HandlerFunc { } params := types.NewQuerySigningInfosParams(page, limit) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckInternalServerError(w, err) { return } diff --git a/x/staking/client/cli/query.go b/x/staking/client/cli/query.go index 9d61801aae39..4d2fa8fea5d6 100644 --- a/x/staking/client/cli/query.go +++ b/x/staking/client/cli/query.go @@ -60,7 +60,7 @@ $ %s query staking validator cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhff ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) addr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -102,7 +102,7 @@ $ %s query staking validators ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) resKVs, _, err := clientCtx.QuerySubspace(types.ValidatorsKey, storeName) if err != nil { @@ -140,7 +140,7 @@ $ %s query staking unbonding-delegations-from cosmosvaloper1gghjut3ccd8ay0zduzj6 ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) valAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -187,7 +187,7 @@ $ %s query staking redelegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) valSrcAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -231,7 +231,7 @@ $ %s query staking delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosm ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) delAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -281,7 +281,7 @@ $ %s query staking delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) delAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -326,7 +326,7 @@ $ %s query staking delegations-to cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ld ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) valAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -376,7 +376,7 @@ $ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld7 ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) valAddr, err := sdk.ValAddressFromBech32(args[1]) if err != nil { @@ -426,7 +426,7 @@ $ %s query staking unbonding-delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) delegatorAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -471,7 +471,7 @@ $ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p co ), Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) delAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -526,7 +526,7 @@ $ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) delAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { @@ -570,7 +570,7 @@ $ %s query staking historical-info 5 ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) height, err := strconv.ParseInt(args[0], 10, 64) if err != nil || height < 0 { @@ -614,7 +614,7 @@ $ %s query staking pool ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) bz, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/pool", storeName), nil) if err != nil { @@ -647,7 +647,7 @@ $ %s query staking params ), ), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) route := fmt.Sprintf("custom/%s/%s", storeName, types.QueryParameters) bz, _, err := clientCtx.QueryWithData(route, nil) diff --git a/x/staking/client/rest/query.go b/x/staking/client/rest/query.go index 0232bff53dbb..2dabef40c45c 100644 --- a/x/staking/client/rest/query.go +++ b/x/staking/client/rest/query.go @@ -179,7 +179,7 @@ func delegatorTxsHandlerFn(clientCtx client.Context) http.HandlerFunc { txs = append(txs, foundTxs) } - res, err := clientCtx.Codec.MarshalJSON(txs) + res, err := clientCtx.JSONMarshaler.MarshalJSON(txs) if rest.CheckInternalServerError(w, err) { return } @@ -234,7 +234,7 @@ func redelegationsHandlerFn(clientCtx client.Context) http.HandlerFunc { params.DstValidatorAddr = dstValidatorAddr } - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -284,7 +284,7 @@ func validatorsHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQueryValidatorsParams(page, limit, status) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -330,7 +330,7 @@ func historicalInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { params := types.NewQueryHistoricalInfoParams(height) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckInternalServerError(w, err) { return } diff --git a/x/staking/client/rest/utils.go b/x/staking/client/rest/utils.go index e08b5f0c9565..185c4562b949 100644 --- a/x/staking/client/rest/utils.go +++ b/x/staking/client/rest/utils.go @@ -59,7 +59,7 @@ func queryBonds(clientCtx client.Context, endpoint string) http.HandlerFunc { params := types.NewQueryBondsParams(delegatorAddr, validatorAddr) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -91,7 +91,7 @@ func queryDelegator(clientCtx client.Context, endpoint string) http.HandlerFunc params := types.NewQueryDelegatorParams(delegatorAddr) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } @@ -128,7 +128,7 @@ func queryValidator(clientCtx client.Context, endpoint string) http.HandlerFunc params := types.NewQueryValidatorParams(validatorAddr, page, limit) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return } diff --git a/x/upgrade/client/cli/query.go b/x/upgrade/client/cli/query.go index 7392e4e1ce03..a64987ffa3a7 100644 --- a/x/upgrade/client/cli/query.go +++ b/x/upgrade/client/cli/query.go @@ -20,7 +20,7 @@ func GetPlanCmd(storeName string, cdc *codec.Codec) *cobra.Command { Long: "Gets the currently scheduled upgrade plan, if one exists", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) // ignore height for now res, _, err := clientCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryCurrent)) @@ -51,11 +51,11 @@ func GetAppliedHeightCmd(storeName string, cdc *codec.Codec) *cobra.Command { "This helps a client determine which binary was valid over a given range of blocks, as well as more context to understand past migrations.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.NewContext().WithCodec(cdc) + clientCtx := client.NewContext().WithCodec(cdc).WithJSONMarshaler(cdc) name := args[0] params := types.NewQueryAppliedParams(name) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if err != nil { return err } diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index a3d597d377a0..16cd14f9184a 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -46,7 +46,7 @@ func getDonePlanHandler(clientCtx client.Context) func(http.ResponseWriter, *htt name := mux.Vars(r)["name"] params := types.NewQueryAppliedParams(name) - bz, err := clientCtx.Codec.MarshalJSON(params) + bz, err := clientCtx.JSONMarshaler.MarshalJSON(params) if rest.CheckBadRequestError(w, err) { return }