cosmos-sdk/x/ibc/03-connection/client/cli/query.go
Aditya 4f9e31ea21
x/ibc: implement Height interface (#7211)
* change interfaces

* fix tendermint client interfaces

* fix other clients interfaces

* fix queries

* fix tendermint build

* fix builds of clients

* fix 02-build

* start fixing connection and make queries non-nullable

* fix connection keepers and queries

* fix connection build

* fix channel build

* fix all non-test files

* fix testing build

* cleanup

* lint

* fix timeout height interface

* fix tendermint tests

* fix rest of clients

* fix connection tests

* fix client tests

* fix channel tests

* fix all ibc tests

* fix transfer tests:

* docs

* fix connection query

* Apply suggestions from code review

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* wrap-up review

Co-authored-by: Jack Zampolin <jack.zampolin@gmail.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
2020-09-03 16:23:20 -04:00

126 lines
3.6 KiB
Go

package cli
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// GetCmdQueryConnections defines the command to query all the connection ends
// that this chain mantains.
func GetCmdQueryConnections() *cobra.Command {
cmd := &cobra.Command{
Use: "connections",
Short: "Query all connections",
Long: "Query all connections ends from a chain",
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
}
queryClient := types.NewQueryClient(clientCtx)
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
req := &types.QueryConnectionsRequest{
Pagination: pageReq,
}
res, err := queryClient.Connections(context.Background(), req)
if err != nil {
return err
}
return clientCtx.PrintOutput(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "connection ends")
return cmd
}
// GetCmdQueryConnection defines the command to query a connection end
func GetCmdQueryConnection() *cobra.Command {
cmd := &cobra.Command{
Use: "end [connection-id]",
Short: "Query stored connection end",
Long: "Query stored connection end",
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
}
connectionID := args[0]
prove, _ := cmd.Flags().GetBool(flags.FlagProve)
connRes, err := utils.QueryConnection(clientCtx, connectionID, prove)
if err != nil {
return err
}
clientCtx = clientCtx.WithHeight(int64(connRes.ProofHeight.EpochHeight))
return clientCtx.PrintOutput(connRes)
},
}
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetCmdQueryClientConnections defines the command to query a client connections
func GetCmdQueryClientConnections() *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 := client.GetClientContextFromCmd(cmd)
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
}
clientCtx = clientCtx.WithHeight(int64(connPathsRes.ProofHeight.EpochHeight))
return clientCtx.PrintOutput(connPathsRes)
},
}
cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}