package cli import ( "fmt" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" "github.com/kava-labs/kava/x/validator-vesting/types" ) // GetQueryCmd returns the cli query commands for the kavadist module func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { valVestingQueryCmd := &cobra.Command{ Use: types.QueryPath, Short: "Querying commands for the validator vesting module", } valVestingQueryCmd.AddCommand(flags.GetCommands( queryCirculatingSupply(queryRoute, cdc), queryTotalSupply(queryRoute, cdc), )...) return valVestingQueryCmd } func queryCirculatingSupply(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "circulating-supply", Short: "Get circulating supply", Long: "Get the current circulating supply of kava tokens", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) // Query res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryCirculatingSupply), nil) if err != nil { return err } cliCtx = cliCtx.WithHeight(height) // Decode and print results var out int64 if err := cdc.UnmarshalJSON(res, &out); err != nil { return fmt.Errorf("failed to unmarshal supply: %w", err) } return cliCtx.PrintOutput(out) }, } } func queryTotalSupply(queryRoute string, cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "total-supply", Short: "Get total supply", Long: "Get the current total supply of kava tokens", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) // Query res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryTotalSupply), nil) if err != nil { return err } cliCtx = cliCtx.WithHeight(height) // Decode and print results var out int64 if err := cdc.UnmarshalJSON(res, &out); err != nil { return fmt.Errorf("failed to unmarshal supply: %w", err) } return cliCtx.PrintOutput(out) }, } }