x/ibc: update CLI queries (#6647)

This commit is contained in:
Federico Kunze 2020-07-08 16:57:42 +02:00 committed by GitHub
parent 67be012e3f
commit 3fc5a4dfc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 79 additions and 63 deletions

View File

@ -76,7 +76,7 @@ func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command {
}
// GetQueryCmd implements AppModuleBasic interface
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
func (AppModuleBasic) GetQueryCmd(_ client.Context) *cobra.Command {
return nil
}

View File

@ -9,8 +9,8 @@ import (
)
// GetQueryCmd returns the query commands for IBC clients
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
ics02ClientQueryCmd := &cobra.Command{
func GetQueryCmd() *cobra.Command {
queryCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC client query subcommands",
DisableFlagParsing: true,
@ -18,12 +18,12 @@ func GetQueryCmd(clientCtx client.Context) *cobra.Command {
RunE: client.ValidateCmd,
}
ics02ClientQueryCmd.AddCommand(flags.GetCommands(
GetCmdQueryClientStates(clientCtx),
GetCmdQueryClientState(clientCtx),
GetCmdQueryConsensusState(clientCtx),
GetCmdQueryHeader(clientCtx),
GetCmdNodeConsensusState(clientCtx),
queryCmd.AddCommand(flags.GetCommands(
GetCmdQueryClientStates(),
GetCmdQueryClientState(),
GetCmdQueryConsensusState(),
GetCmdQueryHeader(),
GetCmdNodeConsensusState(),
)...)
return ics02ClientQueryCmd
return queryCmd
}

View File

@ -18,7 +18,7 @@ import (
// GetCmdQueryClientStates defines the command to query all the light clients
// that this chain mantains.
func GetCmdQueryClientStates(clientCtx client.Context) *cobra.Command {
func GetCmdQueryClientStates() *cobra.Command {
cmd := &cobra.Command{
Use: "states",
Short: "Query all available light clients",
@ -26,6 +26,7 @@ func GetCmdQueryClientStates(clientCtx client.Context) *cobra.Command {
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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -52,7 +53,7 @@ func GetCmdQueryClientStates(clientCtx client.Context) *cobra.Command {
// GetCmdQueryClientState defines the command to query the state of a client with
// 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 {
func GetCmdQueryClientState() *cobra.Command {
cmd := &cobra.Command{
Use: "state [client-id]",
Short: "Query a client state",
@ -60,6 +61,7 @@ func GetCmdQueryClientState(clientCtx client.Context) *cobra.Command {
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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -88,7 +90,7 @@ func GetCmdQueryClientState(clientCtx client.Context) *cobra.Command {
// GetCmdQueryConsensusState defines the command to query the consensus state of
// the chain as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#query
func GetCmdQueryConsensusState(clientCtx client.Context) *cobra.Command {
func GetCmdQueryConsensusState() *cobra.Command {
cmd := &cobra.Command{
Use: "consensus-state [client-id] [height]",
Short: "Query the consensus state of a client at a given height",
@ -96,6 +98,7 @@ func GetCmdQueryConsensusState(clientCtx client.Context) *cobra.Command {
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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -128,13 +131,14 @@ func GetCmdQueryConsensusState(clientCtx client.Context) *cobra.Command {
}
// GetCmdQueryHeader defines the command to query the latest header on the chain
func GetCmdQueryHeader(clientCtx client.Context) *cobra.Command {
func GetCmdQueryHeader() *cobra.Command {
return &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 %s %s header", version.AppName, host.ModuleName, types.SubModuleName),
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -153,7 +157,7 @@ func GetCmdQueryHeader(clientCtx client.Context) *cobra.Command {
// GetCmdNodeConsensusState defines the command to query the latest consensus state of a node
// The result is feed to client creation
func GetCmdNodeConsensusState(clientCtx client.Context) *cobra.Command {
func GetCmdNodeConsensusState() *cobra.Command {
return &cobra.Command{
Use: "node-state",
Short: "Query a node consensus state",
@ -161,6 +165,7 @@ func GetCmdNodeConsensusState(clientCtx client.Context) *cobra.Command {
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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err

View File

@ -21,6 +21,6 @@ func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
}
// GetQueryCmd returns no root query command for the IBC client
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx)
func GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

View File

@ -9,26 +9,26 @@ import (
)
// GetQueryCmd returns the query commands for IBC connections
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
ics03ConnectionQueryCmd := &cobra.Command{
func GetQueryCmd() *cobra.Command {
queryCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC connection query subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}
ics03ConnectionQueryCmd.AddCommand(flags.GetCommands(
GetCmdQueryConnections(clientCtx),
GetCmdQueryConnection(clientCtx),
GetCmdQueryClientConnections(clientCtx),
queryCmd.AddCommand(flags.GetCommands(
GetCmdQueryConnections(),
GetCmdQueryConnection(),
GetCmdQueryClientConnections(),
)...)
return ics03ConnectionQueryCmd
return queryCmd
}
// NewTxCmd returns a CLI command handler for all x/ibc connection transaction commands.
func NewTxCmd() *cobra.Command {
ics03ConnectionTxCmd := &cobra.Command{
txCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC connection transaction subcommands",
DisableFlagParsing: true,
@ -36,12 +36,12 @@ func NewTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}
ics03ConnectionTxCmd.AddCommand(flags.PostCommands(
txCmd.AddCommand(flags.PostCommands(
NewConnectionOpenInitCmd(),
NewConnectionOpenTryCmd(),
NewConnectionOpenAckCmd(),
NewConnectionOpenConfirmCmd(),
)...)
return ics03ConnectionTxCmd
return txCmd
}

View File

@ -17,7 +17,7 @@ import (
// GetCmdQueryConnections defines the command to query all the connection ends
// that this chain mantains.
func GetCmdQueryConnections(clientCtx client.Context) *cobra.Command {
func GetCmdQueryConnections() *cobra.Command {
cmd := &cobra.Command{
Use: "connections",
Short: "Query all connections",
@ -25,6 +25,7 @@ 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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -57,7 +58,7 @@ func GetCmdQueryConnections(clientCtx client.Context) *cobra.Command {
}
// GetCmdQueryConnection defines the command to query a connection end
func GetCmdQueryConnection(clientCtx client.Context) *cobra.Command {
func GetCmdQueryConnection() *cobra.Command {
cmd := &cobra.Command{
Use: "end [connection-id]",
Short: "Query stored connection end",
@ -65,6 +66,7 @@ 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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -88,7 +90,7 @@ func GetCmdQueryConnection(clientCtx client.Context) *cobra.Command {
}
// GetCmdQueryClientConnections defines the command to query a client connections
func GetCmdQueryClientConnections(clientCtx client.Context) *cobra.Command {
func GetCmdQueryClientConnections() *cobra.Command {
cmd := &cobra.Command{
Use: "path [client-id]",
Short: "Query stored client connection paths",
@ -96,6 +98,7 @@ func GetCmdQueryClientConnections(clientCtx client.Context) *cobra.Command {
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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err

View File

@ -22,8 +22,8 @@ func GetTxCmd() *cobra.Command {
}
// GetQueryCmd returns the root query command for the IBC connections.
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx)
func GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
// RegisterRESTRoutes registers the REST routes for the IBC connections.

View File

@ -9,8 +9,8 @@ import (
)
// GetQueryCmd returns the query commands for IBC channels
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
ics04ChannelQueryCmd := &cobra.Command{
func GetQueryCmd() *cobra.Command {
queryCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC channel query subcommands",
DisableFlagParsing: true,
@ -18,24 +18,24 @@ func GetQueryCmd(clientCtx client.Context) *cobra.Command {
RunE: client.ValidateCmd,
}
ics04ChannelQueryCmd.AddCommand(flags.GetCommands(
GetCmdQueryChannels(clientCtx),
GetCmdQueryChannel(clientCtx),
GetCmdQueryConnectionChannels(clientCtx),
GetCmdQueryChannelClientState(clientCtx),
GetCmdQueryPacketCommitment(clientCtx),
GetCmdQueryPacketCommitments(clientCtx),
GetCmdQueryUnrelayedPackets(clientCtx),
GetCmdQueryNextSequenceReceive(clientCtx),
queryCmd.AddCommand(flags.GetCommands(
GetCmdQueryChannels(),
GetCmdQueryChannel(),
GetCmdQueryConnectionChannels(),
GetCmdQueryChannelClientState(),
GetCmdQueryPacketCommitment(),
GetCmdQueryPacketCommitments(),
GetCmdQueryUnrelayedPackets(),
GetCmdQueryNextSequenceReceive(),
// TODO: next sequence Send ?
)...)
return ics04ChannelQueryCmd
return queryCmd
}
// NewTxCmd returns a CLI command handler for all x/ibc channel transaction commands.
func NewTxCmd() *cobra.Command {
ics04ChannelTxCmd := &cobra.Command{
txCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC channel transaction subcommands",
DisableFlagParsing: true,
@ -43,7 +43,7 @@ func NewTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}
ics04ChannelTxCmd.AddCommand(flags.PostCommands(
txCmd.AddCommand(flags.PostCommands(
NewChannelOpenInitCmd(),
NewChannelOpenTryCmd(),
NewChannelOpenAckCmd(),
@ -52,5 +52,5 @@ func NewTxCmd() *cobra.Command {
NewChannelCloseConfirmCmd(),
)...)
return ics04ChannelTxCmd
return txCmd
}

View File

@ -20,7 +20,7 @@ const flagSequences = "sequences"
// GetCmdQueryChannels defines the command to query all the channels ends
// that this chain mantains.
func GetCmdQueryChannels(clientCtx client.Context) *cobra.Command {
func GetCmdQueryChannels() *cobra.Command {
cmd := &cobra.Command{
Use: "channels",
Short: "Query all channels",
@ -28,6 +28,7 @@ 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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -60,7 +61,7 @@ func GetCmdQueryChannels(clientCtx client.Context) *cobra.Command {
}
// GetCmdQueryChannel defines the command to query a channel end
func GetCmdQueryChannel(clientCtx client.Context) *cobra.Command {
func GetCmdQueryChannel() *cobra.Command {
cmd := &cobra.Command{
Use: "end [port-id] [channel-id]",
Short: "Query a channel end",
@ -70,6 +71,7 @@ func GetCmdQueryChannel(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -94,7 +96,7 @@ func GetCmdQueryChannel(clientCtx client.Context) *cobra.Command {
// GetCmdQueryConnectionChannels defines the command to query all the channels associated with a
// connection
func GetCmdQueryConnectionChannels(clientCtx client.Context) *cobra.Command {
func GetCmdQueryConnectionChannels() *cobra.Command {
cmd := &cobra.Command{
Use: "connections [connection-id]",
Short: "Query all channels associated with a connection",
@ -102,6 +104,7 @@ 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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -135,7 +138,7 @@ func GetCmdQueryConnectionChannels(clientCtx client.Context) *cobra.Command {
}
// GetCmdQueryChannelClientState defines the command to query a client state from a channel
func GetCmdQueryChannelClientState(clientCtx client.Context) *cobra.Command {
func GetCmdQueryChannelClientState() *cobra.Command {
cmd := &cobra.Command{
Use: "client-state [port-id] [channel-id]",
Short: "Query the client state associated with a channel",
@ -143,6 +146,7 @@ func GetCmdQueryChannelClientState(clientCtx client.Context) *cobra.Command {
Example: fmt.Sprintf("%s query ibc channel client-state [port-id] [channel-id]", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -165,7 +169,7 @@ func GetCmdQueryChannelClientState(clientCtx client.Context) *cobra.Command {
// GetCmdQueryPacketCommitments defines the command to query all packet commitments associated with
// a channel
func GetCmdQueryPacketCommitments(clientCtx client.Context) *cobra.Command {
func GetCmdQueryPacketCommitments() *cobra.Command {
cmd := &cobra.Command{
Use: "packet-commitments [port-id] [channel-id]",
Short: "Query all packet commitments associated with a channel",
@ -173,6 +177,7 @@ 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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -207,7 +212,7 @@ func GetCmdQueryPacketCommitments(clientCtx client.Context) *cobra.Command {
}
// GetCmdQueryPacketCommitment defines the command to query a channel end
func GetCmdQueryPacketCommitment(clientCtx client.Context) *cobra.Command {
func GetCmdQueryPacketCommitment() *cobra.Command {
cmd := &cobra.Command{
Use: "packet-commitment [port-id] [channel-id] [sequence]",
Short: "Query a packet commitment",
@ -217,6 +222,7 @@ func GetCmdQueryPacketCommitment(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -245,7 +251,7 @@ func GetCmdQueryPacketCommitment(clientCtx client.Context) *cobra.Command {
}
// GetCmdQueryUnrelayedPackets defines the command to query all the unrelayed packets.
func GetCmdQueryUnrelayedPackets(clientCtx client.Context) *cobra.Command {
func GetCmdQueryUnrelayedPackets() *cobra.Command {
cmd := &cobra.Command{
Use: "unrelayed-packets [port-id] [channel-id]",
Short: "Query all the unrelayed packets associated with a channel",
@ -257,6 +263,7 @@ 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 := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
@ -303,7 +310,7 @@ An unrelayed packet corresponds to:
}
// GetCmdQueryNextSequenceReceive defines the command to query a next receive sequence for a given channel
func GetCmdQueryNextSequenceReceive(clientCtx client.Context) *cobra.Command {
func GetCmdQueryNextSequenceReceive() *cobra.Command {
cmd := &cobra.Command{
Use: "next-sequence-receive [port-id] [channel-id]",
Short: "Query a next receive sequence",
@ -313,6 +320,7 @@ func GetCmdQueryNextSequenceReceive(clientCtx client.Context) *cobra.Command {
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err

View File

@ -22,8 +22,8 @@ func GetTxCmd() *cobra.Command {
}
// GetQueryCmd returns the root query command for IBC channels.
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx)
func GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}
// RegisterRESTRoutes registers the REST routes for IBC channels.

View File

@ -33,7 +33,7 @@ func GetTxCmd() *cobra.Command {
}
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
func GetQueryCmd() *cobra.Command {
// Group ibc queries under a subcommand
ibcQueryCmd := &cobra.Command{
Use: host.ModuleName,
@ -44,9 +44,9 @@ func GetQueryCmd(clientCtx client.Context) *cobra.Command {
}
ibcQueryCmd.AddCommand(flags.GetCommands(
ibcclient.GetQueryCmd(clientCtx),
connection.GetQueryCmd(clientCtx),
channel.GetQueryCmd(clientCtx),
ibcclient.GetQueryCmd(),
connection.GetQueryCmd(),
channel.GetQueryCmd(),
)...)
return ibcQueryCmd
}

View File

@ -74,8 +74,8 @@ func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command {
}
// GetQueryCmd returns no root query command for the ibc module.
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx)
func (AppModuleBasic) GetQueryCmd(_ client.Context) *cobra.Command {
return cli.GetQueryCmd()
}
// RegisterInterfaceTypes registers module concrete types into protobuf Any.