Skip to content

Commit

Permalink
Add cli for MsgRegisterAccount (#2136)
Browse files Browse the repository at this point in the history
## Description

Add client cmd for `MsgRegisterAccount`, similar to [inter-tx](https://github.com/cosmos/interchain-accounts-demo/blob/master/x/inter-tx/client/cli/tx.go#L36), but making appropriate changes to make it consistent with other ibc modules.

### Improvements
Maybe we can better have description for the flags as well as client help/usage statements. Do let me know if we can add more clarity here.

closes: #2061

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md).
- [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing)
- [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`)
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md`
- [ ] Re-reviewed `Files changed` in the Github PR explorer
- [ ] Review `Codecov Report` in the comment section below once CI passes

(cherry picked from commit 5e78a23)
  • Loading branch information
Anmol1696 authored and mergify[bot] committed Aug 30, 2022
1 parent bf7468e commit 25cf631
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
17 changes: 17 additions & 0 deletions modules/apps/27-interchain-accounts/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,20 @@ func GetQueryCmd() *cobra.Command {

return icaQueryCmd
}

// NewTxCmd returns the tx commands for the interchain-accounts submodule
func NewTxCmd() *cobra.Command {
icaTxCmd := &cobra.Command{
Use: "interchain-accounts",
Aliases: []string{"ica"},
Short: "interchain-accounts tx subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}

icaTxCmd.AddCommand(
controllercli.NewTxCmd(),
)

return icaTxCmd
}
70 changes: 70 additions & 0 deletions modules/apps/27-interchain-accounts/controller/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cli

import (
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"

"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
)

const (
// The controller chain channel version
flagVersion = "version"
)

// NewTxCmd creates and returns the tx command
func NewTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "controller",
Short: "ica controller transactions subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(
newRegisterAccountCmd(),
)

return cmd
}

func newRegisterAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "register [connection-id]",
Short: "Register an interchain account on the provided connection.",
Long: strings.TrimSpace(`Register an account on the counterparty chain via the
connection id from the source chain. Connection identifier should be for the source chain
and the interchain account will be created on the counterparty chain. Callers are expected to
provide the appropriate application version string via {version} flag. Generates a new
port identifier using the provided owner string, binds to the port identifier and claims
the associated capability.`),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

connectionID := args[0]
owner := clientCtx.GetFromAddress().String()
version, err := cmd.Flags().GetString(flagVersion)
if err != nil {
return err
}

msg := types.NewMsgRegisterAccount(connectionID, owner, version)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

cmd.Flags().String(flagVersion, "", "Controller chain channel version")
flags.AddTxFlagsToCmd(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r

// GetTxCmd implements AppModuleBasic interface
func (AppModuleBasic) GetTxCmd() *cobra.Command {
return nil
return cli.NewTxCmd()
}

// GetQueryCmd implements AppModuleBasic interface
Expand Down

0 comments on commit 25cf631

Please sign in to comment.