github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/transfer/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  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/transfer/types"
    13  	"github.com/spf13/cobra"
    14  )
    15  
    16  // GetCmdQueryDenomTrace defines the command to query a a denomination trace from a given hash.
    17  func GetCmdQueryDenomTrace(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    18  	cmd := &cobra.Command{
    19  		Use:     "denom-trace [hash]",
    20  		Short:   "Query the denom trace info from a given trace hash",
    21  		Long:    "Query the denom trace info from a given trace hash",
    22  		Example: fmt.Sprintf("%s query ibc-transfer denom-trace [hash]", version.ServerName),
    23  		Args:    cobra.ExactArgs(1),
    24  		RunE: func(cmd *cobra.Command, args []string) error {
    25  			clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg)
    26  			queryClient := types.NewQueryClient(clientCtx)
    27  
    28  			req := &types.QueryDenomTraceRequest{
    29  				Hash: args[0],
    30  			}
    31  
    32  			res, err := queryClient.DenomTrace(cmd.Context(), req)
    33  			if err != nil {
    34  				return err
    35  			}
    36  
    37  			return clientCtx.PrintProto(res)
    38  		},
    39  	}
    40  
    41  	flags.AddQueryFlagsToCmd(cmd)
    42  	return cmd
    43  }
    44  
    45  // GetCmdQueryDenomTraces defines the command to query all the denomination trace infos
    46  // that this chain mantains.
    47  func GetCmdQueryDenomTraces(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    48  	cmd := &cobra.Command{
    49  		Use:     "denom-traces",
    50  		Short:   "Query the trace info for all token denominations",
    51  		Long:    "Query the trace info for all token denominations",
    52  		Example: fmt.Sprintf("%s query ibc-transfer denom-traces", version.ServerName),
    53  		Args:    cobra.NoArgs,
    54  		RunE: func(cmd *cobra.Command, _ []string) error {
    55  			clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg)
    56  			queryClient := types.NewQueryClient(clientCtx)
    57  
    58  			pageReq, err := client.ReadPageRequest(cmd.Flags())
    59  			if err != nil {
    60  				return err
    61  			}
    62  
    63  			req := &types.QueryDenomTracesRequest{
    64  				Pagination: pageReq,
    65  			}
    66  
    67  			res, err := queryClient.DenomTraces(cmd.Context(), req)
    68  			if err != nil {
    69  				return err
    70  			}
    71  
    72  			return clientCtx.PrintProto(res)
    73  		},
    74  	}
    75  	flags.AddQueryFlagsToCmd(cmd)
    76  	flags.AddPaginationFlagsToCmd(cmd, "denominations trace")
    77  
    78  	return cmd
    79  }
    80  
    81  // GetCmdParams returns the command handler for ibc-transfer parameter querying.
    82  func GetCmdParams(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    83  	cmd := &cobra.Command{
    84  		Use:     "params",
    85  		Short:   "Query the current ibc-transfer parameters",
    86  		Long:    "Query the current ibc-transfer parameters",
    87  		Args:    cobra.NoArgs,
    88  		Example: fmt.Sprintf("%s query ibc-transfer params", version.ServerName),
    89  		RunE: func(cmd *cobra.Command, _ []string) error {
    90  			clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg)
    91  			queryClient := types.NewQueryClient(clientCtx)
    92  
    93  			res, _ := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
    94  			return clientCtx.PrintProto(res.Params)
    95  		},
    96  	}
    97  
    98  	flags.AddQueryFlagsToCmd(cmd)
    99  
   100  	return cmd
   101  }
   102  
   103  // GetCmdParams returns the command handler for ibc-transfer parameter querying.
   104  func GetCmdQueryEscrowAddress(m *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
   105  	cmd := &cobra.Command{
   106  		Use:     "escrow-address",
   107  		Short:   "Get the escrow address for a channel",
   108  		Long:    "Get the escrow address for a channel",
   109  		Args:    cobra.ExactArgs(2),
   110  		Example: fmt.Sprintf("%s query ibc-transfer escrow-address [port] [channel-id]", version.ServerName),
   111  		RunE: func(cmd *cobra.Command, args []string) error {
   112  			clientCtx := context.NewCLIContext().WithProxy(m).WithInterfaceRegistry(reg)
   113  			port := args[0]
   114  			channel := args[1]
   115  			addr := types.GetEscrowAddress(port, channel)
   116  			return clientCtx.PrintOutput(fmt.Sprintf("%s\n", addr.String()))
   117  		},
   118  	}
   119  
   120  	flags.AddQueryFlagsToCmd(cmd)
   121  
   122  	return cmd
   123  }