From bf3fa3067102b03c404169fb3672af4b6c224866 Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Fri, 22 May 2020 14:48:44 -0400 Subject: [PATCH] ibc/07-tendermint: fix CLI (#6271) --- x/ibc/07-tendermint/client/cli/tx.go | 46 +++++++++++++--------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/x/ibc/07-tendermint/client/cli/tx.go b/x/ibc/07-tendermint/client/cli/tx.go index dad4571648..ed20ffaeb6 100644 --- a/x/ibc/07-tendermint/client/cli/tx.go +++ b/x/ibc/07-tendermint/client/cli/tx.go @@ -33,11 +33,13 @@ const flagTrustLevel = "trust-level" // in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#create func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift]", - Short: "create new tendermint client", - Long: "create new tendermint client. Trust level can be a fraction (eg: '1/3') or 'default'", - Example: fmt.Sprintf("%s tx ibc client create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift] --trust-level default --from node0 --home ../node0/cli --chain-id $CID", version.ClientName), - Args: cobra.ExactArgs(6), + Use: "create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift]", + Short: "create new tendermint client", + Long: "create new tendermint client. Trust level can be a fraction (eg: '1/3') or 'default'", + Example: fmt.Sprintf( + "%s tx ibc %s create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift] --trust-level default --from node0 --home ../node0/cli --chain-id $CID", + version.ClientName, ibctmtypes.SubModuleName), + Args: cobra.ExactArgs(5), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) @@ -67,23 +69,23 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command { if lvl == "default" { trustLevel = lite.DefaultTrustLevel } else { - trustLevel, err = parseFraction(args[2]) + trustLevel, err = parseFraction(lvl) if err != nil { return err } } - trustingPeriod, err := time.ParseDuration(args[3]) + trustingPeriod, err := time.ParseDuration(args[2]) if err != nil { return err } - ubdPeriod, err := time.ParseDuration(args[4]) + ubdPeriod, err := time.ParseDuration(args[3]) if err != nil { return err } - maxClockDrift, err := time.ParseDuration(args[5]) + maxClockDrift, err := time.ParseDuration(args[4]) if err != nil { return err } @@ -106,14 +108,13 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command { // GetCmdUpdateClient defines the command to update a client as defined in // https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#update func GetCmdUpdateClient(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ + return &cobra.Command{ Use: "update [client-id] [path/to/header.json]", Short: "update existing client with a header", - Long: strings.TrimSpace(fmt.Sprintf(`update existing client with a header: - -Example: -$ %s tx ibc client update [client-id] [path/to/header.json] --from node0 --home ../node0/cli --chain-id $CID - `, version.ClientName), + Long: "update existing tendermint client with a tendermint header", + Example: fmt.Sprintf( + "$ %s tx ibc %s update [client-id] [path/to/header.json] --from node0 --home ../node0/cli --chain-id $CID", + version.ClientName, ibctmtypes.SubModuleName, ), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -143,22 +144,19 @@ $ %s tx ibc client update [client-id] [path/to/header.json] --from node0 --home return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) }, } - - return cmd } // GetCmdSubmitMisbehaviour defines the command to submit a misbehaviour to invalidate // previous state roots and prevent future updates as defined in // https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#misbehaviour func GetCmdSubmitMisbehaviour(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ + return &cobra.Command{ Use: "misbehaviour [path/to/evidence.json]", Short: "submit a client misbehaviour", - Long: strings.TrimSpace(fmt.Sprintf(`submit a client misbehaviour to invalidate to invalidate previous state roots and prevent future updates: - -Example: -$ %s tx ibc client misbehaviour [path/to/evidence.json] --from node0 --home ../node0/cli --chain-id $CID - `, version.ClientName), + Long: "submit a client misbehaviour to invalidate to invalidate previous state roots and prevent future updates", + Example: fmt.Sprintf( + "$ %s tx ibc %s misbehaviour [path/to/evidence.json] --from node0 --home ../node0/cli --chain-id $CID", + version.ClientName, ibctmtypes.SubModuleName, ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -186,8 +184,6 @@ $ %s tx ibc client misbehaviour [path/to/evidence.json] --from node0 --home ../n return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) }, } - - return cmd } func parseFraction(fraction string) (tmmath.Fraction, error) {