cosmos-sdk/x/mint/client/cli/query.go
atheeshp 3123d07ad9
Update x/{mint,slashing,evidence} cli to use gRPC query client (#6704)
* changes cli to use gRPC in mint, slashing

* added command for signing infos

* gRPC query client migration of evidence

* review changes

* added unpack any

* fixed build error

* fixed failing tests issue

* added read flags

* added pagination flags

* updated docs

* fixed tests issue

* failing tests

* fixed tests

* review changes

* review changes

Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
2020-07-19 06:16:57 -04:00

127 lines
3.1 KiB
Go

package cli
import (
"context"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/x/mint/types"
)
// GetQueryCmd returns the cli query commands for the minting module.
func GetQueryCmd() *cobra.Command {
mintingQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the minting module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
mintingQueryCmd.AddCommand(
GetCmdQueryParams(),
GetCmdQueryInflation(),
GetCmdQueryAnnualProvisions(),
)
return mintingQueryCmd
}
// GetCmdQueryParams implements a command to return the current minting
// parameters.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current minting parameters",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryParamsRequest{}
res, err := queryClient.Params(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintOutput(res.Params)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetCmdQueryInflation implements a command to return the current minting
// inflation value.
func GetCmdQueryInflation() *cobra.Command {
cmd := &cobra.Command{
Use: "inflation",
Short: "Query the current minting inflation value",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryInflationRequest{}
res, err := queryClient.Inflation(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintOutput(res.Inflation)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetCmdQueryAnnualProvisions implements a command to return the current minting
// annual provisions value.
func GetCmdQueryAnnualProvisions() *cobra.Command {
cmd := &cobra.Command{
Use: "annual-provisions",
Short: "Query the current minting annual provisions value",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.ReadQueryCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryAnnualProvisionsRequest{}
res, err := queryClient.AnnualProvisions(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintOutput(res.AnnualProvisions)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}