diff --git a/cmd/flags.go b/cmd/flags.go index 5ae8072c8..54d73420f 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -47,12 +47,20 @@ const ( flagMemo = "memo" flagFilterRule = "filter-rule" flagFilterChannels = "filter-channels" + flagSrcChainID = "src-chain-id" + flagDstChainID = "dst-chain-id" + flagSrcClientID = "src-client-id" + flagDstClientID = "dst-client-id" + flagSrcConnID = "src-connection-id" + flagDstConnID = "dst-connection-id" ) const ( // 7597 is "RLYR" on a telephone keypad. // It also happens to be unassigned in the IANA port list. defaultDebugAddr = "localhost:7597" + + blankValue = "blank" ) func ibcDenomFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command { @@ -155,12 +163,37 @@ func fileFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command { } func pathFilterFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command { - cmd.Flags().String(flagFilterRule, "", `filter rule ("allowlist", "denylist", or "" for no filtering)`) - if err := v.BindPFlag(flagFilterRule, cmd.Flags().Lookup(flagFilterRule)); err != nil { + flags := cmd.Flags() + flags.String(flagFilterRule, blankValue, `filter rule ("allowlist", "denylist", or "" for no filtering)`) + if err := v.BindPFlag(flagFilterRule, flags.Lookup(flagFilterRule)); err != nil { + panic(err) + } + flags.String(flagFilterChannels, blankValue, "channels from source chain perspective to filter") + if err := v.BindPFlag(flagFilterRule, flags.Lookup(flagFilterRule)); err != nil { + panic(err) + } + flags.String(flagSrcChainID, "", "chain ID for source chain") + if err := v.BindPFlag(flagSrcChainID, flags.Lookup(flagSrcChainID)); err != nil { + panic(err) + } + flags.String(flagDstChainID, "", "chain ID for destination chain") + if err := v.BindPFlag(flagDstChainID, flags.Lookup(flagDstChainID)); err != nil { + panic(err) + } + flags.String(flagSrcClientID, "", "client ID for source chain") + if err := v.BindPFlag(flagSrcClientID, flags.Lookup(flagSrcClientID)); err != nil { + panic(err) + } + flags.String(flagDstClientID, "", "client ID for destination chain") + if err := v.BindPFlag(flagDstClientID, flags.Lookup(flagDstClientID)); err != nil { + panic(err) + } + flags.String(flagSrcConnID, "", "connection ID for source chain") + if err := v.BindPFlag(flagSrcConnID, flags.Lookup(flagSrcConnID)); err != nil { panic(err) } - cmd.Flags().String(flagFilterChannels, "", "channels from source chain perspective to filter") - if err := v.BindPFlag(flagFilterRule, cmd.Flags().Lookup(flagFilterRule)); err != nil { + flags.String(flagDstConnID, "", "connection ID for destination chain") + if err := v.BindPFlag(flagDstConnID, flags.Lookup(flagDstConnID)); err != nil { panic(err) } return cmd diff --git a/cmd/paths.go b/cmd/paths.go index 090ac919a..46fc5aec8 100644 --- a/cmd/paths.go +++ b/cmd/paths.go @@ -266,39 +266,85 @@ func pathsUpdateCmd(a *appState) *cobra.Command { cmd := &cobra.Command{ Use: "update path_name", Aliases: []string{"n"}, - Short: `Update a path such as the filter rule ("allowlist", "denylist", or "" for no filtering) and channels`, + Short: `Update a path such as the filter rule ("allowlist", "denylist", or "" for no filtering), filter channels, and src/dst chain, client, or connection IDs`, Args: withUsage(cobra.ExactArgs(1)), Example: strings.TrimSpace(fmt.Sprintf(` $ %s paths update demo-path --filter-rule allowlist --filter-channels channel-0,channel-1 -$ %s paths update demo-path --filter-rule denylist --filter-channels channel-0,channel-1`, - appName, appName)), +$ %s paths update demo-path --filter-rule denylist --filter-channels channel-0,channel-1 +$ %s paths update demo-path --src-chain-id chain-1 --dst-chain-id chain-2 +$ %s paths update demo-path --src-client-id 07-tendermint-02 --dst-client-id 07-tendermint-04 +$ %s paths update demo-path --src-connection-id connection-02 --dst-connection-id connection-04`, + appName, appName, appName, appName, appName)), RunE: func(cmd *cobra.Command, args []string) error { name := args[0] - filterRule, err := cmd.Flags().GetString(flagFilterRule) - if err != nil { - return err + flags := cmd.Flags() + + p := a.Config.Paths.MustGet(name) + + actionTaken := false + + filterRule, _ := flags.GetString(flagFilterRule) + if filterRule != blankValue { + if filterRule != "" && filterRule != processor.RuleAllowList && filterRule != processor.RuleDenyList { + return fmt.Errorf( + `invalid filter rule : "%s". valid rules: ("", "%s", "%s")`, + filterRule, processor.RuleAllowList, processor.RuleDenyList) + } + p.Filter.Rule = filterRule + actionTaken = true + } + + filterChannels, _ := flags.GetString(flagFilterChannels) + if filterChannels != blankValue { + var channelList []string + + if filterChannels != "" { + channelList = strings.Split(filterChannels, ",") + } + + p.Filter.ChannelList = channelList + actionTaken = true } - if filterRule != "" && filterRule != processor.RuleAllowList && filterRule != processor.RuleDenyList { - return fmt.Errorf(`invalid filter rule : "%s". valid rules: ("", "%s", "%s")`, filterRule, processor.RuleAllowList, processor.RuleDenyList) + + srcChainID, _ := flags.GetString(flagSrcChainID) + if srcChainID != "" { + p.Src.ChainID = srcChainID + actionTaken = true } - filterChannels, err := cmd.Flags().GetString(flagFilterChannels) - if err != nil { - return err + dstChainID, _ := flags.GetString(flagDstChainID) + if dstChainID != "" { + p.Dst.ChainID = dstChainID + actionTaken = true } - var channelList []string + srcClientID, _ := flags.GetString(flagSrcClientID) + if srcClientID != "" { + p.Src.ClientID = srcClientID + actionTaken = true + } - if filterChannels != "" { - channelList = strings.Split(filterChannels, ",") + dstClientID, _ := flags.GetString(flagDstClientID) + if dstClientID != "" { + p.Dst.ClientID = dstClientID + actionTaken = true } - p := a.Config.Paths.MustGet(name) + srcConnID, _ := flags.GetString(flagSrcConnID) + if srcConnID != "" { + p.Src.ConnectionID = srcConnID + actionTaken = true + } + + dstConnID, _ := flags.GetString(flagDstConnID) + if dstConnID != "" { + p.Dst.ConnectionID = dstConnID + actionTaken = true + } - p.Filter = relayer.ChannelFilter{ - Rule: filterRule, - ChannelList: channelList, + if !actionTaken { + return fmt.Errorf("at least one flag must be provided") } return a.OverwriteConfig(a.Config)