x/ibc: refactor CLI (#6639)

* x/ibc: refactor CLI

* refactor client CLI

* rename version ClientName

* Update x/ibc/09-localhost/client/cli/cli.go

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>

* address comments from review

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
This commit is contained in:
Federico Kunze 2020-07-08 11:57:59 +02:00 committed by GitHub
parent e50c8df10c
commit e6bb2e7ed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 281 additions and 242 deletions

View File

@ -8,8 +8,8 @@ import (
)
// NewTxCmd returns the transaction commands for IBC fungible token transfer
func NewTxCmd(clientCtx client.Context) *cobra.Command {
ics20TransferTxCmd := &cobra.Command{
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: "ibc-transfer",
Short: "IBC fungible token transfer transaction subcommands",
DisableFlagParsing: true,
@ -17,9 +17,9 @@ func NewTxCmd(clientCtx client.Context) *cobra.Command {
RunE: client.ValidateCmd,
}
ics20TransferTxCmd.AddCommand(flags.PostCommands(
NewTransferTxCmd(clientCtx),
txCmd.AddCommand(flags.PostCommands(
NewTransferTxCmd(),
)...)
return ics20TransferTxCmd
return txCmd
}

View File

@ -18,14 +18,18 @@ const (
)
// NewTransferTxCmd returns the command to create a NewMsgTransfer transaction
func NewTransferTxCmd(clientCtx client.Context) *cobra.Command {
func NewTransferTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "transfer [src-port] [src-channel] [receiver] [amount]",
Short: "Transfer a fungible token through IBC",
Example: fmt.Sprintf("%s tx ibc-transfer transfer [src-port] [src-channel] [receiver] [amount]", version.AppName),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
sender := clientCtx.GetFromAddress()
srcPort := args[0]
@ -47,7 +51,7 @@ func NewTransferTxCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

View File

@ -71,8 +71,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
}
// GetTxCmd implements AppModuleBasic interface
func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.NewTxCmd(clientCtx)
func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command {
return cli.NewTxCmd()
}
// GetQueryCmd implements AppModuleBasic interface

View File

@ -24,7 +24,6 @@ func GetQueryCmd(clientCtx client.Context) *cobra.Command {
GetCmdQueryConsensusState(clientCtx),
GetCmdQueryHeader(clientCtx),
GetCmdNodeConsensusState(clientCtx),
GetCmdQueryPath(clientCtx),
)...)
return ics02ClientQueryCmd
}

View File

@ -12,25 +12,24 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/utils"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// GetCmdQueryClientStates defines the command to query all the light clients
// that this chain mantains.
func GetCmdQueryClientStates(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "states",
Short: "Query all available light clients",
Long: strings.TrimSpace(
fmt.Sprintf(`Query all available light clients
Example:
$ %s query ibc client states
`, version.AppName),
),
Example: fmt.Sprintf("%s query ibc client states", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
Use: "states",
Short: "Query all available light clients",
Long: "Query all available light clients",
Example: fmt.Sprintf("%s query %s %s states", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
page, _ := cmd.Flags().GetInt(flags.FlagPage)
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
@ -55,18 +54,16 @@ $ %s query ibc client states
// a given id as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#query
func GetCmdQueryClientState(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "state [client-id]",
Short: "Query a client state",
Long: strings.TrimSpace(
fmt.Sprintf(`Query stored client state
Example:
$ %s query ibc client state [client-id]
`, version.AppName),
),
Args: cobra.ExactArgs(1),
Use: "state [client-id]",
Short: "Query a client state",
Long: "Query stored client state",
Example: fmt.Sprintf("%s query %s %s state [client-id]", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
clientID := args[0]
if strings.TrimSpace(clientID) == "" {
@ -96,10 +93,13 @@ func GetCmdQueryConsensusState(clientCtx client.Context) *cobra.Command {
Use: "consensus-state [client-id] [height]",
Short: "Query the consensus state of a client at a given height",
Long: "Query the consensus state for a particular light client at a given height",
Example: fmt.Sprintf("%s query ibc client consensus-state [client-id] [height]", version.AppName),
Example: fmt.Sprintf("%s query %s %s consensus-state [client-id] [height]", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
clientID := args[0]
if strings.TrimSpace(clientID) == "" {
@ -133,9 +133,12 @@ func GetCmdQueryHeader(clientCtx client.Context) *cobra.Command {
Use: "header",
Short: "Query the latest header of the running chain",
Long: "Query the latest Tendermint header of the running chain",
Example: fmt.Sprintf("%s query ibc client header", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
Example: fmt.Sprintf("%s query %s %s header", version.AppName, host.ModuleName, types.SubModuleName),
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
header, height, err := utils.QueryTendermintHeader(clientCtx)
if err != nil {
@ -152,18 +155,16 @@ func GetCmdQueryHeader(clientCtx client.Context) *cobra.Command {
// The result is feed to client creation
func GetCmdNodeConsensusState(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "node-state",
Short: "Query a node consensus state",
Long: strings.TrimSpace(
fmt.Sprintf(`Query a node consensus state. This result is feed to the client creation transaction.
Example:
$ %s query ibc client node-state
`, version.AppName),
),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
Use: "node-state",
Short: "Query a node consensus state",
Long: "Query a node consensus state. This result is feed to the client creation transaction.",
Example: fmt.Sprintf("%s query %s %s node-state", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
state, height, err := utils.QueryNodeConsensusState(clientCtx)
if err != nil {
@ -175,17 +176,3 @@ $ %s query ibc client node-state
},
}
}
// GetCmdQueryPath defines the command to query the commitment path.
func GetCmdQueryPath(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "path",
Short: "Query the commitment path of the running chain",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
path := commitmenttypes.NewMerklePrefix([]byte("ibc"))
return clientCtx.PrintOutput(path)
},
}
}

View File

@ -27,7 +27,7 @@ func GetQueryCmd(clientCtx client.Context) *cobra.Command {
}
// NewTxCmd returns a CLI command handler for all x/ibc connection transaction commands.
func NewTxCmd(clientCtx client.Context) *cobra.Command {
func NewTxCmd() *cobra.Command {
ics03ConnectionTxCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC connection transaction subcommands",
@ -37,10 +37,10 @@ func NewTxCmd(clientCtx client.Context) *cobra.Command {
}
ics03ConnectionTxCmd.AddCommand(flags.PostCommands(
NewConnectionOpenInitCmd(clientCtx),
NewConnectionOpenTryCmd(clientCtx),
NewConnectionOpenAckCmd(clientCtx),
NewConnectionOpenConfirmCmd(clientCtx),
NewConnectionOpenInitCmd(),
NewConnectionOpenTryCmd(),
NewConnectionOpenAckCmd(),
NewConnectionOpenConfirmCmd(),
)...)
return ics03ConnectionTxCmd

View File

@ -25,7 +25,11 @@ func GetCmdQueryConnections(clientCtx client.Context) *cobra.Command {
Example: fmt.Sprintf("%s query %s %s connections", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx = clientCtx.Init()
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
offset, _ := cmd.Flags().GetInt(flags.FlagPage)
@ -61,14 +65,14 @@ func GetCmdQueryConnection(clientCtx client.Context) *cobra.Command {
Example: fmt.Sprintf("%s query %s %s end [connection-id]", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
connectionID := args[0]
prove, err := cmd.Flags().GetBool(flags.FlagProve)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
connectionID := args[0]
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
connRes, err := utils.QueryConnection(clientCtx, connectionID, prove)
if err != nil {
return err
@ -78,7 +82,6 @@ func GetCmdQueryConnection(clientCtx client.Context) *cobra.Command {
return clientCtx.PrintOutput(connRes)
},
}
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
return cmd
@ -86,21 +89,21 @@ func GetCmdQueryConnection(clientCtx client.Context) *cobra.Command {
// GetCmdQueryClientConnections defines the command to query a client connections
func GetCmdQueryClientConnections(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "path [client-id]",
Short: "Query stored client connection paths",
Long: "Query stored client connection paths",
Example: fmt.Sprintf("%s query %s %s path [client-id]", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
clientID := args[0]
prove, err := cmd.Flags().GetBool(flags.FlagProve)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
clientID := args[0]
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
connPathsRes, err := utils.QueryClientConnections(clientCtx, clientID, prove)
if err != nil {
return err
@ -110,4 +113,7 @@ func GetCmdQueryClientConnections(clientCtx client.Context) *cobra.Command {
return clientCtx.PrintOutput(connPathsRes)
},
}
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
return cmd
}

View File

@ -16,7 +16,7 @@ import (
// NewConnectionOpenInitCmd defines the command to initialize a connection on
// chain A with a given counterparty chain B
func NewConnectionOpenInitCmd(clientCtx client.Context) *cobra.Command {
func NewConnectionOpenInitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]",
Short: "Initialize connection on chain A",
@ -27,7 +27,11 @@ func NewConnectionOpenInitCmd(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
connectionID := args[0]
clientID := args[1]
@ -48,7 +52,7 @@ func NewConnectionOpenInitCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
@ -57,7 +61,7 @@ func NewConnectionOpenInitCmd(clientCtx client.Context) *cobra.Command {
// NewConnectionOpenTryCmd defines the command to relay a try open a connection on
// chain B
func NewConnectionOpenTryCmd(clientCtx client.Context) *cobra.Command {
func NewConnectionOpenTryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: strings.TrimSpace(`open-try [connection-id] [client-id]
[counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]
@ -72,7 +76,11 @@ func NewConnectionOpenTryCmd(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(8),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
connectionID := args[0]
clientID := args[1]
@ -113,7 +121,7 @@ func NewConnectionOpenTryCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
@ -122,7 +130,7 @@ func NewConnectionOpenTryCmd(clientCtx client.Context) *cobra.Command {
// NewConnectionOpenAckCmd defines the command to relay the acceptance of a
// connection open attempt from chain B to chain A
func NewConnectionOpenAckCmd(clientCtx client.Context) *cobra.Command {
func NewConnectionOpenAckCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "open-ack [connection-id] [path/to/proof_try.json] [path/to/proof_consensus.json] [version]",
Short: "relay the acceptance of a connection open attempt",
@ -133,7 +141,11 @@ func NewConnectionOpenAckCmd(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
connectionID := args[0]
@ -164,7 +176,7 @@ func NewConnectionOpenAckCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
@ -173,7 +185,7 @@ func NewConnectionOpenAckCmd(clientCtx client.Context) *cobra.Command {
// NewConnectionOpenConfirmCmd defines the command to initialize a connection on
// chain A with a given counterparty chain B
func NewConnectionOpenConfirmCmd(clientCtx client.Context) *cobra.Command {
func NewConnectionOpenConfirmCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "open-confirm [connection-id] [path/to/proof_ack.json]",
Short: "confirm to chain B that connection is open on chain A",
@ -184,7 +196,11 @@ func NewConnectionOpenConfirmCmd(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
connectionID := args[0]
@ -206,7 +222,7 @@ func NewConnectionOpenConfirmCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

View File

@ -17,8 +17,8 @@ func Name() string {
}
// GetTxCmd returns the root tx command for the IBC connections.
func GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.NewTxCmd(clientCtx)
func GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
// GetQueryCmd returns the root query command for the IBC connections.

View File

@ -34,7 +34,7 @@ func GetQueryCmd(clientCtx client.Context) *cobra.Command {
}
// NewTxCmd returns a CLI command handler for all x/ibc channel transaction commands.
func NewTxCmd(clientCtx client.Context) *cobra.Command {
func NewTxCmd() *cobra.Command {
ics04ChannelTxCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC channel transaction subcommands",
@ -44,12 +44,12 @@ func NewTxCmd(clientCtx client.Context) *cobra.Command {
}
ics04ChannelTxCmd.AddCommand(flags.PostCommands(
NewChannelOpenInitCmd(clientCtx),
NewChannelOpenTryCmd(clientCtx),
NewChannelOpenAckCmd(clientCtx),
NewChannelOpenConfirmCmd(clientCtx),
NewChannelCloseInitCmd(clientCtx),
NewChannelCloseConfirmCmd(clientCtx),
NewChannelOpenInitCmd(),
NewChannelOpenTryCmd(),
NewChannelOpenAckCmd(),
NewChannelOpenConfirmCmd(),
NewChannelCloseInitCmd(),
NewChannelCloseConfirmCmd(),
)...)
return ics04ChannelTxCmd

View File

@ -28,7 +28,10 @@ func GetCmdQueryChannels(clientCtx client.Context) *cobra.Command {
Example: fmt.Sprintf("%s query %s %s channels", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx = clientCtx.Init()
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
offset, _ := cmd.Flags().GetInt(flags.FlagPage)
@ -67,15 +70,15 @@ func GetCmdQueryChannel(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
portID := args[0]
channelID := args[1]
prove, err := cmd.Flags().GetBool(flags.FlagProve)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
channelRes, err := utils.QueryChannel(clientCtx, portID, channelID, prove)
if err != nil {
return err
@ -99,7 +102,10 @@ func GetCmdQueryConnectionChannels(clientCtx client.Context) *cobra.Command {
Example: fmt.Sprintf("%s query %s %s connections [connection-id]", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
offset, _ := cmd.Flags().GetInt(flags.FlagPage)
@ -136,8 +142,11 @@ func GetCmdQueryChannelClientState(clientCtx client.Context) *cobra.Command {
Long: "Query the client state associated with a channel, by providing its port and channel identifiers.",
Example: fmt.Sprintf("%s query ibc channel client-state [port-id] [channel-id]", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
@ -164,7 +173,10 @@ func GetCmdQueryPacketCommitments(clientCtx client.Context) *cobra.Command {
Example: fmt.Sprintf("%s query %s %s packet-commitments [port-id] [channel-id]", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
offset, _ := cmd.Flags().GetInt(flags.FlagPage)
@ -205,15 +217,15 @@ func GetCmdQueryPacketCommitment(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
portID := args[0]
channelID := args[1]
prove, err := cmd.Flags().GetBool(flags.FlagProve)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
seq, err := strconv.ParseUint(args[2], 10, 64)
if err != nil {
return err
@ -245,7 +257,10 @@ An unrelayed packet corresponds to:
Example: fmt.Sprintf("%s query %s %s unrelayed-packets [port-id] [channel-id] --sequences=1,2,3", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
seqSlice, err := cmd.Flags().GetInt64Slice(flagSequences)
@ -298,15 +313,15 @@ func GetCmdQueryNextSequenceReceive(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()
portID := args[0]
channelID := args[1]
prove, err := cmd.Flags().GetBool(flags.FlagProve)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
sequenceRes, err := utils.QueryNextSequenceReceive(clientCtx, portID, channelID, prove)
if err != nil {
return err
@ -317,5 +332,6 @@ func GetCmdQueryNextSequenceReceive(clientCtx client.Context) *cobra.Command {
},
}
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
return cmd
}

View File

@ -20,13 +20,17 @@ const (
)
// NewChannelOpenInitCmd returns the command to create a MsgChannelOpenInit transaction
func NewChannelOpenInitCmd(clientCtx client.Context) *cobra.Command {
func NewChannelOpenInitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "open-init [port-id] [channel-id] [counterparty-port-id] [counterparty-channel-id] [connection-hops]",
Short: "Creates and sends a ChannelOpenInit message",
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
@ -44,24 +48,27 @@ func NewChannelOpenInitCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().Bool(FlagOrdered, true, "Pass flag for opening ordered channels")
cmd.Flags().String(FlagIBCVersion, "1.0.0", "supported IBC version")
cmd.Flags().String(FlagIBCVersion, types.DefaultChannelVersion, "supported IBC version")
return cmd
}
// NewChannelOpenTryCmd returns the command to create a MsgChannelOpenTry transaction
func NewChannelOpenTryCmd(clientCtx client.Context) *cobra.Command {
func NewChannelOpenTryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "open-try [port-id] [channel-id] [counterparty-port-id] [counterparty-channel-id] [connection-hops] [/path/to/proof_init.json] [proof-height]",
Short: "Creates and sends a ChannelOpenTry message",
Args: cobra.ExactArgs(7),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
@ -92,24 +99,27 @@ func NewChannelOpenTryCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().Bool(FlagOrdered, true, "Pass flag for opening ordered channels")
cmd.Flags().String(FlagIBCVersion, "1.0.0", "supported IBC version")
cmd.Flags().String(FlagIBCVersion, types.DefaultChannelVersion, "supported IBC version")
return cmd
}
// NewChannelOpenAckCmd returns the command to create a MsgChannelOpenAck transaction
func NewChannelOpenAckCmd(clientCtx client.Context) *cobra.Command {
func NewChannelOpenAckCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "open-ack [port-id] [channel-id] [/path/to/proof_try.json] [proof-height]",
Short: "Creates and sends a ChannelOpenAck message",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
@ -134,23 +144,26 @@ func NewChannelOpenAckCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(FlagIBCVersion, "1.0.0", "supported IBC version")
cmd.Flags().String(FlagIBCVersion, types.DefaultChannelVersion, "supported IBC version")
return cmd
}
// NewChannelOpenConfirmCmd returns the command to create a MsgChannelOpenConfirm transaction
func NewChannelOpenConfirmCmd(clientCtx client.Context) *cobra.Command {
func NewChannelOpenConfirmCmd() *cobra.Command {
return &cobra.Command{
Use: "open-confirm [port-id] [channel-id] [/path/to/proof_ack.json] [proof-height]",
Short: "Creates and sends a ChannelOpenConfirm message",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
@ -172,19 +185,23 @@ func NewChannelOpenConfirmCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}
// NewChannelCloseInitCmd returns the command to create a MsgChannelCloseInit transaction
func NewChannelCloseInitCmd(clientCtx client.Context) *cobra.Command {
func NewChannelCloseInitCmd() *cobra.Command {
return &cobra.Command{
Use: "close-init [port-id] [channel-id]",
Short: "Creates and sends a ChannelCloseInit message",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
@ -194,19 +211,23 @@ func NewChannelCloseInitCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}
// NewChannelCloseConfirmCmd returns the command to create a MsgChannelCloseConfirm transaction
func NewChannelCloseConfirmCmd(clientCtx client.Context) *cobra.Command {
func NewChannelCloseConfirmCmd() *cobra.Command {
return &cobra.Command{
Use: "close-confirm [port-id] [channel-id] [/path/to/proof_init.json] [proof-height]",
Short: "Creates and sends a ChannelCloseConfirm message",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
portID := args[0]
channelID := args[1]
@ -228,7 +249,7 @@ func NewChannelCloseConfirmCmd(clientCtx client.Context) *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}

View File

@ -17,8 +17,8 @@ func Name() string {
}
// GetTxCmd returns the root tx command for IBC channels.
func GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.NewTxCmd(clientCtx)
func GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}
// GetQueryCmd returns the root query command for IBC channels.

View File

@ -13,6 +13,9 @@ var (
_ exported.CounterpartyI = (*Counterparty)(nil)
)
// DefaultChannelVersion defines the default channel version used during handshake.
const DefaultChannelVersion = "1.0.0"
// NewChannel creates a new Channel instance
func NewChannel(
state State, ordering Order, counterparty Counterparty,

View File

@ -4,23 +4,23 @@ import (
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
)
// GetTxCmd returns the transaction commands for IBC clients
func GetTxCmd(cdc *codec.Codec, storeKey string) *cobra.Command {
ics07TendermintTxCmd := &cobra.Command{
Use: "tendermint",
Short: "Tendermint transaction subcommands",
// NewTxCmd returns a root CLI command handler for all x/bank transaction commands.
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "Tendermint client transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}
ics07TendermintTxCmd.AddCommand(flags.PostCommands(
GetCmdCreateClient(cdc),
GetCmdUpdateClient(cdc),
GetCmdSubmitMisbehaviour(cdc),
txCmd.AddCommand(flags.PostCommands(
NewCreateClientCmd(),
NewUpdateClientCmd(),
NewSubmitMisbehaviourCmd(),
)...)
return ics07TendermintTxCmd
return txCmd
}

View File

@ -1,7 +1,6 @@
package cli
import (
"bufio"
"fmt"
"io/ioutil"
"strconv"
@ -17,12 +16,8 @@ import (
lite "github.com/tendermint/tendermint/lite2"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/version"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
@ -33,9 +28,9 @@ const (
flagProofSpecs = "proof-specs"
)
// GetCmdCreateClient defines the command to create a new IBC Client as defined
// NewCreateClientCmd defines the command to create a new IBC Client as defined
// in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#create
func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
func NewCreateClientCmd() *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",
@ -45,20 +40,22 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
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 --proof-specs [path/to/proof-specs.json] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, 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))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc).WithBroadcastMode(flags.BroadcastBlock)
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
clientID := args[0]
var header ibctmtypes.Header
if err := cdc.UnmarshalJSON([]byte(args[1]), &header); err != nil {
if err := clientCtx.Codec.UnmarshalJSON([]byte(args[1]), &header); err != nil {
// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[1])
if err != nil {
return errors.New("neither JSON input nor path to .json file were provided for consensus header")
}
if err := cdc.UnmarshalJSON(contents, &header); err != nil {
if err := clientCtx.Codec.UnmarshalJSON(contents, &header); err != nil {
return errors.Wrap(err, "error unmarshalling consensus header file")
}
}
@ -66,7 +63,6 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
var (
trustLevel tmmath.Fraction
specs []*ics23.ProofSpec
err error
)
lvl, _ := cmd.Flags().GetString(flagTrustLevel)
@ -98,13 +94,13 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
spc, _ := cmd.Flags().GetString(flagProofSpecs)
if spc == "default" {
specs = commitmenttypes.GetSDKSpecs()
} else if err := cdc.UnmarshalJSON([]byte(spc), &specs); err != nil {
} else if err := clientCtx.Codec.UnmarshalJSON([]byte(spc), &specs); err != nil {
// check for file path if JSON input not provided
contents, err := ioutil.ReadFile(spc)
if err != nil {
return errors.New("neither JSON input nor path to .json file was provided for proof specs flag")
}
if err := cdc.UnmarshalJSON(contents, &specs); err != nil {
if err := clientCtx.Codec.UnmarshalJSON(contents, &specs); err != nil {
return errors.Wrap(err, "error unmarshalling proof specs file")
}
}
@ -117,7 +113,7 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
@ -127,9 +123,9 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
return cmd
}
// GetCmdUpdateClient defines the command to update a client as defined in
// NewUpdateClientCmd 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 {
func NewUpdateClientCmd() *cobra.Command {
return &cobra.Command{
Use: "update [client-id] [path/to/header.json]",
Short: "update existing client with a header",
@ -140,20 +136,22 @@ func GetCmdUpdateClient(cdc *codec.Codec) *cobra.Command {
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
clientID := args[0]
var header ibctmtypes.Header
if err := cdc.UnmarshalJSON([]byte(args[1]), &header); err != nil {
if err := clientCtx.Codec.UnmarshalJSON([]byte(args[1]), &header); err != nil {
// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[1])
if err != nil {
return errors.New("neither JSON input nor path to .json file were provided")
}
if err := cdc.UnmarshalJSON(contents, &header); err != nil {
if err := clientCtx.Codec.UnmarshalJSON(contents, &header); err != nil {
return errors.Wrap(err, "error unmarshalling header file")
}
}
@ -163,15 +161,15 @@ func GetCmdUpdateClient(cdc *codec.Codec) *cobra.Command {
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}
// GetCmdSubmitMisbehaviour defines the command to submit a misbehaviour to invalidate
// NewSubmitMisbehaviourCmd 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 {
func NewSubmitMisbehaviourCmd() *cobra.Command {
return &cobra.Command{
Use: "misbehaviour [path/to/evidence.json]",
Short: "submit a client misbehaviour",
@ -182,18 +180,20 @@ func GetCmdSubmitMisbehaviour(cdc *codec.Codec) *cobra.Command {
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
var ev evidenceexported.Evidence
if err := cdc.UnmarshalJSON([]byte(args[0]), &ev); err != nil {
if err := clientCtx.Codec.UnmarshalJSON([]byte(args[0]), &ev); err != nil {
// check for file path if JSON input is not provided
contents, err := ioutil.ReadFile(args[0])
if err != nil {
return errors.New("neither JSON input nor path to .json file were provided")
}
if err := cdc.UnmarshalJSON(contents, &ev); err != nil {
if err := clientCtx.Codec.UnmarshalJSON(contents, &ev); err != nil {
return errors.Wrap(err, "error unmarshalling evidence file")
}
}
@ -203,7 +203,7 @@ func GetCmdSubmitMisbehaviour(cdc *codec.Codec) *cobra.Command {
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
}

View File

@ -1,13 +1,10 @@
package tendermint
import (
"fmt"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/client/cli"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/client/rest"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
@ -24,6 +21,6 @@ func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
}
// GetTxCmd returns the root tx command for the IBC client
func GetTxCmd(cdc *codec.Codec, storeKey string) *cobra.Command {
return cli.GetTxCmd(cdc, fmt.Sprintf("%s/%s", storeKey, types.SubModuleName))
func GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

View File

@ -4,22 +4,21 @@ import (
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
)
// GetTxCmd returns the transaction commands for IBC
func GetTxCmd(cdc *codec.Codec, storeKey string) *cobra.Command {
ics09LocalhostTxCmd := &cobra.Command{
// NewTxCmd returns a root CLI command handler for all ibc localhost transaction commands.
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "Localhost transaction subcommands",
Short: "Localhost client transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}
ics09LocalhostTxCmd.AddCommand(flags.PostCommands(
GetCmdCreateClient(cdc),
txCmd.AddCommand(flags.PostCommands(
NewCreateClientCmd(),
)...)
return ics09LocalhostTxCmd
return txCmd
}

View File

@ -1,45 +1,39 @@
package cli
import (
"bufio"
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/version"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// GetCmdCreateClient defines the command to create a new IBC Client as defined
// NewCreateClientCmd defines the command to create a new IBC Loopback Client as defined
// in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#create
func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
func NewCreateClientCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "create new localhost client",
Long: strings.TrimSpace(fmt.Sprintf(`create new localhost (loopback) client:
Example:
$ %s tx ibc client localhost create --from node0 --home ../node0/<app>cli --chain-id $CID
`, version.AppName),
),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc).WithBroadcastMode(flags.BroadcastBlock)
Use: "create",
Short: "create new localhost client",
Long: "create new localhost (loopback) client",
Example: fmt.Sprintf("%s tx %s %s create --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, host.ModuleName, types.SubModuleName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadTxCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
msg := types.NewMsgCreateClient(clientCtx.GetFromAddress())
if err := msg.ValidateBasic(); err != nil {
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
return cmd

View File

@ -1,13 +1,10 @@
package localhost
import (
"fmt"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/client/cli"
"github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/client/rest"
"github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
@ -24,6 +21,6 @@ func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
}
// GetTxCmd returns the root tx command for the IBC localhost client
func GetTxCmd(cdc *codec.Codec, storeKey string) *cobra.Command {
return cli.GetTxCmd(cdc, fmt.Sprintf("%s/%s", storeKey, types.SubModuleName))
func GetTxCmd() *cobra.Command {
return cli.NewTxCmd()
}

View File

@ -8,13 +8,13 @@ import (
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
tmclient "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/client/cli"
tendermint "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint"
localhost "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd(clientCtx client.Context) *cobra.Command {
func GetTxCmd() *cobra.Command {
ibcTxCmd := &cobra.Command{
Use: host.ModuleName,
Short: "IBC transaction subcommands",
@ -24,10 +24,10 @@ func GetTxCmd(clientCtx client.Context) *cobra.Command {
}
ibcTxCmd.AddCommand(flags.PostCommands(
tmclient.GetTxCmd(clientCtx.Codec, host.StoreKey),
localhost.GetTxCmd(clientCtx.Codec, host.StoreKey),
connection.GetTxCmd(clientCtx),
channel.GetTxCmd(clientCtx),
tendermint.GetTxCmd(),
localhost.GetTxCmd(),
connection.GetTxCmd(),
channel.GetTxCmd(),
)...)
return ibcTxCmd
}

View File

@ -69,8 +69,8 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
}
// GetTxCmd returns the root tx command for the ibc module.
func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.GetTxCmd(clientCtx)
func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command {
return cli.GetTxCmd()
}
// GetQueryCmd returns no root query command for the ibc module.