diff --git a/client/context/context.go b/client/context/context.go index f93240d95..8179a9ef4 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -44,6 +44,7 @@ type CLIContext struct { GenerateOnly bool fromAddress types.AccAddress fromName string + Indent bool } // NewCLIContext returns a new initialized CLIContext with parameters from the @@ -76,15 +77,11 @@ func NewCLIContext() CLIContext { GenerateOnly: viper.GetBool(client.FlagGenerateOnly), fromAddress: fromAddress, fromName: fromName, + Indent: viper.GetBool(client.FlagIndentResponse), } } func createCertifier() tmlite.Certifier { - trustNodeDefined := viper.IsSet(client.FlagTrustNode) - if !trustNodeDefined { - return nil - } - trustNode := viper.GetBool(client.FlagTrustNode) if trustNode { return nil diff --git a/client/flags.go b/client/flags.go index 394cf0c7a..591becfaa 100644 --- a/client/flags.go +++ b/client/flags.go @@ -54,7 +54,7 @@ func GetCommands(cmds ...*cobra.Command) []*cobra.Command { c.Flags().String(FlagChainID, "", "Chain ID of tendermint node") c.Flags().String(FlagNode, "tcp://localhost:26657", ": to tendermint rpc interface for this chain") c.Flags().Int64(FlagHeight, 0, "block height to query, omit to get most recent provable block") - //viper.BindPFlag(FlagTrustNode, c.Flags().Lookup(FlagTrustNode)) + viper.BindPFlag(FlagTrustNode, c.Flags().Lookup(FlagTrustNode)) viper.BindPFlag(FlagUseLedger, c.Flags().Lookup(FlagUseLedger)) viper.BindPFlag(FlagChainID, c.Flags().Lookup(FlagChainID)) viper.BindPFlag(FlagNode, c.Flags().Lookup(FlagNode)) @@ -84,7 +84,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command { // --gas can accept integers and "simulate" c.Flags().Var(&GasFlagVar, "gas", fmt.Sprintf( "gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)", GasFlagSimulate, DefaultGasLimit)) - //viper.BindPFlag(FlagTrustNode, c.Flags().Lookup(FlagTrustNode)) + viper.BindPFlag(FlagTrustNode, c.Flags().Lookup(FlagTrustNode)) viper.BindPFlag(FlagUseLedger, c.Flags().Lookup(FlagUseLedger)) viper.BindPFlag(FlagChainID, c.Flags().Lookup(FlagChainID)) viper.BindPFlag(FlagNode, c.Flags().Lookup(FlagNode)) diff --git a/client/rpc/block.go b/client/rpc/block.go index a4bb5ee16..663b075bf 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -63,12 +63,10 @@ func getBlock(cliCtx context.CLIContext, height *int64) ([]byte, error) { } } - indent := viper.GetBool(client.FlagIndentResponse) - if indent { + if cliCtx.Indent { return cdc.MarshalJSONIndent(res, "", " ") - } else { - return cdc.MarshalJSON(res) } + return cdc.MarshalJSON(res) } // get the current blockchain height @@ -133,7 +131,7 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { w.Write([]byte(err.Error())) return } - utils.PostProcessResponse(w, cdc, output) + utils.PostProcessResponse(w, cdc, output, cliCtx.Indent) } } @@ -152,6 +150,6 @@ func LatestBlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { w.Write([]byte(err.Error())) return } - utils.PostProcessResponse(w, cdc, output) + utils.PostProcessResponse(w, cdc, output, cliCtx.Indent) } } diff --git a/client/rpc/status.go b/client/rpc/status.go index 11448edc5..77325c6f5 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -40,14 +40,16 @@ func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) { // CMD func printNodeStatus(cmd *cobra.Command, args []string) error { - status, err := getNodeStatus(context.NewCLIContext()) + // No need to verify proof in getting node status + viper.Set(client.FlagTrustNode, true) + cliCtx := context.NewCLIContext() + status, err := getNodeStatus(cliCtx) if err != nil { return err } var output []byte - indent := viper.GetBool(client.FlagIndentResponse) - if indent { + if cliCtx.Indent { output, err = cdc.MarshalJSONIndent(status, "", " ") } else { output, err = cdc.MarshalJSON(status) @@ -73,7 +75,7 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } nodeInfo := status.NodeInfo - utils.PostProcessResponse(w, cdc, nodeInfo) + utils.PostProcessResponse(w, cdc, nodeInfo, cliCtx.Indent) } } diff --git a/client/rpc/validators.go b/client/rpc/validators.go index 021f2cea5..0fd1f1e1d 100644 --- a/client/rpc/validators.go +++ b/client/rpc/validators.go @@ -98,13 +98,11 @@ func getValidators(cliCtx context.CLIContext, height *int64) ([]byte, error) { } } - indent := viper.GetBool(client.FlagIndentResponse) - - if indent { + if cliCtx.Indent { return cdc.MarshalJSONIndent(outputValidatorsRes, "", " ") - } else { - return cdc.MarshalJSON(outputValidatorsRes) } + return cdc.MarshalJSON(outputValidatorsRes) + } // CMD diff --git a/client/tx/broadcast.go b/client/tx/broadcast.go index 4876cc887..8346e1538 100644 --- a/client/tx/broadcast.go +++ b/client/tx/broadcast.go @@ -55,6 +55,6 @@ func BroadcastTxRequest(cliCtx context.CLIContext, cdc *codec.Codec) http.Handle utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return } - utils.PostProcessResponse(w, cdc, res) + utils.PostProcessResponse(w, cdc, res, cliCtx.Indent) } } diff --git a/client/tx/query.go b/client/tx/query.go index 30b6145aa..325b2b29c 100644 --- a/client/tx/query.go +++ b/client/tx/query.go @@ -79,12 +79,10 @@ func queryTx(cdc *codec.Codec, cliCtx context.CLIContext, hashHexStr string) ([] return nil, err } - indent := viper.GetBool(client.FlagIndentResponse) - if indent { + if cliCtx.Indent { return cdc.MarshalJSONIndent(info, "", " ") - } else { - return cdc.MarshalJSON(info) } + return cdc.MarshalJSON(info) } // ValidateTxResult performs transaction verification @@ -148,6 +146,6 @@ func QueryTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.H w.Write([]byte(err.Error())) return } - utils.PostProcessResponse(w, cdc, output) + utils.PostProcessResponse(w, cdc, output, cliCtx.Indent) } } diff --git a/client/tx/search.go b/client/tx/search.go index 17339cade..174256eca 100644 --- a/client/tx/search.go +++ b/client/tx/search.go @@ -53,8 +53,7 @@ $ gaiacli tendermint txs --tag test1,test2 --any } var output []byte - indent := viper.GetBool(client.FlagIndentResponse) - if indent { + if cliCtx.Indent { output, err = cdc.MarshalJSONIndent(txs, "", " ") } else { output, err = cdc.MarshalJSON(txs) @@ -182,6 +181,6 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http. return } - utils.PostProcessResponse(w, cdc, txs) + utils.PostProcessResponse(w, cdc, txs, cliCtx.Indent) } } diff --git a/client/utils/rest.go b/client/utils/rest.go index cc1557941..07b258ce9 100644 --- a/client/utils/rest.go +++ b/client/utils/rest.go @@ -15,7 +15,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder" - "github.com/spf13/viper" ) const ( @@ -242,14 +241,14 @@ func CompleteAndBroadcastTxREST(w http.ResponseWriter, r *http.Request, cliCtx c return } - PostProcessResponse(w, cdc, res) + PostProcessResponse(w, cdc, res, cliCtx.Indent) } -func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response interface{}) { +// PostProcessResponse performs post process for rest response +func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response interface{}, indent bool) { var output []byte switch response.(type) { default: - indent := viper.GetBool(client.FlagIndentResponse) var err error if indent { output, err = cdc.MarshalJSONIndent(response, "", " ") diff --git a/x/auth/client/cli/account.go b/x/auth/client/cli/account.go index 6c5d9d009..f78b5252f 100644 --- a/x/auth/client/cli/account.go +++ b/x/auth/client/cli/account.go @@ -9,8 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/spf13/viper" - "github.com/cosmos/cosmos-sdk/client" ) // GetAccountCmdDefault invokes the GetAccountCmd for the auth.BaseAccount type. @@ -61,8 +59,7 @@ func GetAccountCmd(storeName string, cdc *codec.Codec, decoder auth.AccountDecod } var output []byte - indent := viper.GetBool(client.FlagIndentResponse) - if indent { + if cliCtx.Indent { output, err = cdc.MarshalJSONIndent(acc, "", " ") } else { output, err = cdc.MarshalJSON(acc) diff --git a/x/auth/client/cli/sign.go b/x/auth/client/cli/sign.go index 0c586233b..30704a500 100644 --- a/x/auth/client/cli/sign.go +++ b/x/auth/client/cli/sign.go @@ -58,8 +58,7 @@ func makeSignCmd(cdc *amino.Codec, decoder auth.AccountDecoder) func(cmd *cobra. return err } var json []byte - indent := viper.GetBool(client.FlagIndentResponse) - if indent { + if cliCtx.Indent { json, err = cdc.MarshalJSONIndent(newTx, "", " ") } else { json, err = cdc.MarshalJSON(newTx) diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index 8d5763915..ccd3a4bf7 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -65,7 +65,7 @@ func QueryAccountRequestHandlerFn( return } - utils.PostProcessResponse(w, cdc, account) + utils.PostProcessResponse(w, cdc, account, cliCtx.Indent) } } @@ -104,6 +104,6 @@ func QueryBalancesRequestHandlerFn( return } - utils.PostProcessResponse(w, cdc, account.GetCoins()) + utils.PostProcessResponse(w, cdc, account.GetCoins(), cliCtx.Indent) } } diff --git a/x/auth/client/rest/sign.go b/x/auth/client/rest/sign.go index dd93d8979..9e9b92b5a 100644 --- a/x/auth/client/rest/sign.go +++ b/x/auth/client/rest/sign.go @@ -52,6 +52,6 @@ func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Ha return } - utils.PostProcessResponse(w, cdc, signedTx) + utils.PostProcessResponse(w, cdc, signedTx, cliCtx.Indent) } } diff --git a/x/bank/client/rest/broadcast.go b/x/bank/client/rest/broadcast.go index e590f19ec..c52961caf 100644 --- a/x/bank/client/rest/broadcast.go +++ b/x/bank/client/rest/broadcast.go @@ -33,7 +33,7 @@ func BroadcastTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) ht return } - utils.PostProcessResponse(w, cdc, res) + utils.PostProcessResponse(w, cdc, res, cliCtx.Indent) } }