github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/27-interchain-accounts/host/client/cli/query.go (about)

     1  package cli
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  
     7  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     8  
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/version"
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/client/utils"
    11  
    12  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
    13  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/flags"
    14  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
    15  	interfacetypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec/types"
    16  	"github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/host/types"
    17  	icatypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/types"
    18  	channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types"
    19  	host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host"
    20  	"github.com/spf13/cobra"
    21  )
    22  
    23  // GetCmdParams returns the command handler for the host submodule parameter querying.
    24  func GetCmdParams(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    25  	cmd := &cobra.Command{
    26  		Use:     "params",
    27  		Short:   "Query the current interchain-accounts host submodule parameters",
    28  		Long:    "Query the current interchain-accounts host submodule parameters",
    29  		Args:    cobra.NoArgs,
    30  		Example: fmt.Sprintf("%s query interchain-accounts host params", version.ServerName),
    31  		RunE: func(cmd *cobra.Command, _ []string) error {
    32  			clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg)
    33  			queryClient := types.NewQueryClient(clientCtx)
    34  
    35  			res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
    36  			if err != nil {
    37  				return err
    38  			}
    39  
    40  			return clientCtx.PrintProto(res.Params)
    41  		},
    42  	}
    43  
    44  	flags.AddQueryFlagsToCmd(cmd)
    45  
    46  	return cmd
    47  }
    48  
    49  // GetCmdPacketEvents returns the command handler for the host packet events querying.
    50  func GetCmdPacketEvents(cdc *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command {
    51  	cmd := &cobra.Command{
    52  		Use:     "packet-events [channel-id] [sequence]",
    53  		Short:   "Query the interchain-accounts host submodule packet events",
    54  		Long:    "Query the interchain-accounts host submodule packet events for a particular channel and sequence",
    55  		Args:    cobra.ExactArgs(2),
    56  		Example: fmt.Sprintf("%s query interchain-accounts host packet-events channel-0 100", version.ServerName),
    57  		RunE: func(cmd *cobra.Command, args []string) error {
    58  			clientCtx := context.NewCLIContext().WithProxy(cdc).WithInterfaceRegistry(reg)
    59  
    60  			channelID, portID := args[0], icatypes.PortID
    61  			if err := host.ChannelIdentifierValidator(channelID); err != nil {
    62  				return err
    63  			}
    64  
    65  			seq, err := strconv.ParseUint(args[1], 10, 64)
    66  			if err != nil {
    67  				return err
    68  			}
    69  
    70  			searchEvents := []string{
    71  				fmt.Sprintf("%s.%s='%s'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeyDstChannel, channelID),
    72  				fmt.Sprintf("%s.%s='%s'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeyDstPort, portID),
    73  				fmt.Sprintf("%s.%s='%d'", channeltypes.EventTypeRecvPacket, channeltypes.AttributeKeySequence, seq),
    74  			}
    75  
    76  			result, err := utils.Query40TxsByEvents(clientCtx, searchEvents, 1, 1)
    77  			if err != nil {
    78  				return err
    79  			}
    80  
    81  			var resEvents []sdk.Event
    82  			for _, r := range result.Txs {
    83  				for _, v := range r.Events {
    84  					eve := sdk.Event{
    85  						Type:       v.Type,
    86  						Attributes: v.Attributes,
    87  					}
    88  					resEvents = append(resEvents, eve)
    89  				}
    90  			}
    91  
    92  			return clientCtx.PrintOutput(sdk.StringifyEvents(resEvents).String())
    93  		},
    94  	}
    95  
    96  	flags.AddQueryFlagsToCmd(cmd)
    97  
    98  	return cmd
    99  }