Skip to content

Commit

Permalink
added cli queries
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 committed Dec 7, 2023
1 parent f4888b4 commit df1dc01
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
58 changes: 58 additions & 0 deletions x/uibc/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion x/uibc/quota/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df1dc01

Please sign in to comment.