From df1dc012866cdcff571e9b6d0fc968e034b6d400 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Thu, 7 Dec 2023 22:34:13 +0530 Subject: [PATCH] added cli queries --- x/uibc/client/cli/query.go | 58 ++++++++++++++++++++++++++++++++++++++ x/uibc/quota/grpc_query.go | 3 +- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/x/uibc/client/cli/query.go b/x/uibc/client/cli/query.go index 0aa3a91610..a76f87034e 100644 --- a/x/uibc/client/cli/query.go +++ b/x/uibc/client/cli/query.go @@ -23,11 +23,69 @@ func GetQueryCmd() *cobra.Command { cmd.AddCommand( QueryParams(), GetOutflows(), + GetInflows(), + GetAllInflows(), ) return cmd } +// GetAllInflows returns registered IBC denoms inflows in the current quota period. +func GetAllInflows() *cobra.Command { + cmd := &cobra.Command{ + Use: "all-inflows [denom]", + Args: cobra.MaximumNArgs(1), + Short: "Get the ibc inflows of the registered tokens.", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := uibc.NewQueryClient(clientCtx) + + req := &uibc.QueryAllInflows{} + if len(args[0]) != 0 { + req.Denom = args[0] + } + + resp, err := queryClient.AllInflows(cmd.Context(), req) + return cli.PrintOrErr(resp, err, clientCtx) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// GetInflows returns total inflow sum, if denom specified it will return quota inflow of the denom. +func GetInflows() *cobra.Command { + cmd := &cobra.Command{ + Use: "inflows [denom]", + Args: cobra.MaximumNArgs(1), + Short: "Get the total ibc inflow sum of registered tokens.", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := uibc.NewQueryClient(clientCtx) + + req := &uibc.QueryInflows{} + if len(args[0]) != 0 { + req.Denom = args[0] + } + + resp, err := queryClient.Inflows(cmd.Context(), req) + return cli.PrintOrErr(resp, err, clientCtx) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + // QueryParams creates a Cobra command to query for the x/uibc // module parameters. func QueryParams() *cobra.Command { diff --git a/x/uibc/quota/grpc_query.go b/x/uibc/quota/grpc_query.go index 6c8f402ef3..d1894fd1c8 100644 --- a/x/uibc/quota/grpc_query.go +++ b/x/uibc/quota/grpc_query.go @@ -79,7 +79,8 @@ func (q Querier) AllInflows(goCtx context.Context, req *uibc.QueryAllInflows) (* return &uibc.QueryAllInflowsResponse{Inflows: inflows}, nil } -// Inflows implements uibc.QueryServer. +// Inflows returns registered IBC denoms inflows in the current quota period. +// If denom is not specified, returns sum of all registered inflows. func (q Querier) Inflows(goCtx context.Context, req *uibc.QueryInflows) (*uibc.QueryInflowsResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) var amount sdk.Dec