github.com/okex/exchain@v1.8.0/libs/ibc-go/modules/core/03-connection/client/cli/query.go (about)

     1  package cli
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/okex/exchain/libs/cosmos-sdk/version"
     6  	"github.com/okex/exchain/libs/cosmos-sdk/client"
     7  	"github.com/okex/exchain/libs/cosmos-sdk/client/context"
     8  	"github.com/okex/exchain/libs/cosmos-sdk/client/flags"
     9  	"github.com/okex/exchain/libs/cosmos-sdk/codec"
    10  	interfacetypes "github.com/okex/exchain/libs/cosmos-sdk/codec/types"
    11  	utils "github.com/okex/exchain/libs/ibc-go/modules/core/03-connection/client/utils"
    12  	"github.com/okex/exchain/libs/ibc-go/modules/core/03-connection/types"
    13  	host "github.com/okex/exchain/libs/ibc-go/modules/core/24-host"
    14  	"github.com/spf13/cobra"
    15  )
    16  
    17  // GetCmdQueryConnections defines the command to query all the connection ends
    18  // that this chain mantains.
    19  func GetCmdQueryConnections(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    20  	cmd := &cobra.Command{
    21  		Use:     "connections",
    22  		Short:   "Query all connections",
    23  		Long:    "Query all connections ends from a chain",
    24  		Example: fmt.Sprintf("%s query %s %s connections", version.ServerName, host.ModuleName, types.SubModuleName),
    25  		Args:    cobra.NoArgs,
    26  		RunE: func(cmd *cobra.Command, _ []string) error {
    27  			clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg)
    28  			queryClient := types.NewQueryClient(clientCtx)
    29  			pageReq, err := client.ReadPageRequest(cmd.Flags())
    30  			if err != nil {
    31  				return err
    32  			}
    33  
    34  			req := &types.QueryConnectionsRequest{
    35  				Pagination: pageReq,
    36  			}
    37  
    38  			res, err := queryClient.Connections(cmd.Context(), req)
    39  			if err != nil {
    40  				return err
    41  			}
    42  
    43  			return clientCtx.PrintProto(res)
    44  		},
    45  	}
    46  
    47  	flags.AddQueryFlagsToCmd(cmd)
    48  	flags.AddPaginationFlagsToCmd(cmd, "connection ends")
    49  
    50  	return cmd
    51  }
    52  
    53  // GetCmdQueryConnection defines the command to query a connection end
    54  func GetCmdQueryConnection(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    55  	cmd := &cobra.Command{
    56  		Use:     "end [connection-id]",
    57  		Short:   "Query stored connection end",
    58  		Long:    "Query stored connection end",
    59  		Example: fmt.Sprintf("%s query %s %s end [connection-id]", version.ServerName, host.ModuleName, types.SubModuleName),
    60  		Args:    cobra.ExactArgs(1),
    61  		RunE: func(cmd *cobra.Command, args []string) error {
    62  			clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg)
    63  			connectionID := args[0]
    64  			prove, _ := cmd.Flags().GetBool(flags.FlagProve)
    65  			connRes, err := utils.QueryConnection(clientCtx, connectionID, prove)
    66  			if err != nil {
    67  				return err
    68  			}
    69  
    70  			clientCtx = clientCtx.WithHeight(int64(connRes.ProofHeight.RevisionHeight))
    71  			return clientCtx.PrintProto(connRes)
    72  		},
    73  	}
    74  
    75  	cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
    76  	flags.AddQueryFlagsToCmd(cmd)
    77  
    78  	return cmd
    79  }
    80  
    81  // GetCmdQueryClientConnections defines the command to query a client connections
    82  func GetCmdQueryClientConnections(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    83  	cmd := &cobra.Command{
    84  		Use:     "path [client-id]",
    85  		Short:   "Query stored client connection paths",
    86  		Long:    "Query stored client connection paths",
    87  		Example: fmt.Sprintf("%s query  %s %s path [client-id]", version.ServerName, host.ModuleName, types.SubModuleName),
    88  		Args:    cobra.ExactArgs(1),
    89  		RunE: func(cmd *cobra.Command, args []string) error {
    90  			clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg)
    91  			clientID := args[0]
    92  			prove, _ := cmd.Flags().GetBool(flags.FlagProve)
    93  
    94  			connPathsRes, err := utils.QueryClientConnections(clientCtx, clientID, prove)
    95  			if err != nil {
    96  				return err
    97  			}
    98  
    99  			clientCtx = clientCtx.WithHeight(int64(connPathsRes.ProofHeight.RevisionHeight))
   100  			return clientCtx.PrintProto(connPathsRes)
   101  		},
   102  	}
   103  
   104  	cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
   105  	flags.AddQueryFlagsToCmd(cmd)
   106  
   107  	return cmd
   108  }