github.com/Finschia/finschia-sdk@v0.48.1/x/mint/client/cli/query.go (about)

     1  package cli
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/spf13/cobra"
     7  
     8  	"github.com/Finschia/finschia-sdk/client"
     9  	"github.com/Finschia/finschia-sdk/client/flags"
    10  	"github.com/Finschia/finschia-sdk/x/mint/types"
    11  )
    12  
    13  // GetQueryCmd returns the cli query commands for the minting module.
    14  func GetQueryCmd() *cobra.Command {
    15  	mintingQueryCmd := &cobra.Command{
    16  		Use:                        types.ModuleName,
    17  		Short:                      "Querying commands for the minting module",
    18  		DisableFlagParsing:         true,
    19  		SuggestionsMinimumDistance: 2,
    20  		RunE:                       client.ValidateCmd,
    21  	}
    22  
    23  	mintingQueryCmd.AddCommand(
    24  		GetCmdQueryParams(),
    25  		GetCmdQueryInflation(),
    26  		GetCmdQueryAnnualProvisions(),
    27  	)
    28  
    29  	return mintingQueryCmd
    30  }
    31  
    32  // GetCmdQueryParams implements a command to return the current minting
    33  // parameters.
    34  func GetCmdQueryParams() *cobra.Command {
    35  	cmd := &cobra.Command{
    36  		Use:   "params",
    37  		Short: "Query the current minting parameters",
    38  		Args:  cobra.NoArgs,
    39  		RunE: func(cmd *cobra.Command, args []string) error {
    40  			clientCtx, err := client.GetClientQueryContext(cmd)
    41  			if err != nil {
    42  				return err
    43  			}
    44  			queryClient := types.NewQueryClient(clientCtx)
    45  
    46  			params := &types.QueryParamsRequest{}
    47  			res, err := queryClient.Params(cmd.Context(), params)
    48  			if err != nil {
    49  				return err
    50  			}
    51  
    52  			return clientCtx.PrintProto(&res.Params)
    53  		},
    54  	}
    55  
    56  	flags.AddQueryFlagsToCmd(cmd)
    57  
    58  	return cmd
    59  }
    60  
    61  // GetCmdQueryInflation implements a command to return the current minting
    62  // inflation value.
    63  func GetCmdQueryInflation() *cobra.Command {
    64  	cmd := &cobra.Command{
    65  		Use:   "inflation",
    66  		Short: "Query the current minting inflation value",
    67  		Args:  cobra.NoArgs,
    68  		RunE: func(cmd *cobra.Command, args []string) error {
    69  			clientCtx, err := client.GetClientQueryContext(cmd)
    70  			if err != nil {
    71  				return err
    72  			}
    73  			queryClient := types.NewQueryClient(clientCtx)
    74  
    75  			params := &types.QueryInflationRequest{}
    76  			res, err := queryClient.Inflation(cmd.Context(), params)
    77  			if err != nil {
    78  				return err
    79  			}
    80  
    81  			return clientCtx.PrintString(fmt.Sprintf("%s\n", res.Inflation))
    82  		},
    83  	}
    84  
    85  	flags.AddQueryFlagsToCmd(cmd)
    86  
    87  	return cmd
    88  }
    89  
    90  // GetCmdQueryAnnualProvisions implements a command to return the current minting
    91  // annual provisions value.
    92  func GetCmdQueryAnnualProvisions() *cobra.Command {
    93  	cmd := &cobra.Command{
    94  		Use:   "annual-provisions",
    95  		Short: "Query the current minting annual provisions value",
    96  		Args:  cobra.NoArgs,
    97  		RunE: func(cmd *cobra.Command, args []string) error {
    98  			clientCtx, err := client.GetClientQueryContext(cmd)
    99  			if err != nil {
   100  				return err
   101  			}
   102  			queryClient := types.NewQueryClient(clientCtx)
   103  
   104  			params := &types.QueryAnnualProvisionsRequest{}
   105  			res, err := queryClient.AnnualProvisions(cmd.Context(), params)
   106  			if err != nil {
   107  				return err
   108  			}
   109  
   110  			return clientCtx.PrintString(fmt.Sprintf("%s\n", res.AnnualProvisions))
   111  		},
   112  	}
   113  
   114  	flags.AddQueryFlagsToCmd(cmd)
   115  
   116  	return cmd
   117  }