ibc/07-tendermint: fix CLI (#6271)

This commit is contained in:
Federico Kunze 2020-05-22 14:48:44 -04:00 committed by GitHub
parent 37882fbf4a
commit bf3fa30671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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/<app>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/<app>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/<app>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/<app>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/<app>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/<app>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) {