github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/03-connection/client/cli/query.go (about)

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