2020-06-15 16:01:58 +00:00
|
|
|
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),
|
2020-11-12 21:48:20 +00:00
|
|
|
queryCirculatingSupplyHARD(queryRoute, cdc),
|
|
|
|
queryCirculatingSupplyUSDX(queryRoute, cdc),
|
2021-09-01 15:21:31 +00:00
|
|
|
queryCirculatingSupplySWP(queryRoute, cdc),
|
2020-11-12 21:48:20 +00:00
|
|
|
queryTotalSupplyHARD(queryRoute, cdc),
|
|
|
|
queryTotalSupplyUSDX(queryRoute, cdc),
|
2020-06-15 16:01:58 +00:00
|
|
|
)...)
|
|
|
|
|
|
|
|
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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 21:48:20 +00:00
|
|
|
|
|
|
|
func queryCirculatingSupplyHARD(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "circulating-supply-hard",
|
|
|
|
Short: "Get HARD circulating supply",
|
|
|
|
Long: "Get the current circulating supply of HARD 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.QueryCirculatingSupplyHARD), 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 queryCirculatingSupplyUSDX(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "circulating-supply-usdx",
|
|
|
|
Short: "Get USDX circulating supply",
|
|
|
|
Long: "Get the current circulating supply of USDX 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.QueryCirculatingSupplyUSDX), 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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-01 15:21:31 +00:00
|
|
|
func queryCirculatingSupplySWP(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "circulating-supply-swp",
|
|
|
|
Short: "Get SWP circulating supply",
|
|
|
|
Long: "Get the current circulating supply of SWP 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.QueryCirculatingSupplySWP), 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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:48:20 +00:00
|
|
|
func queryTotalSupplyHARD(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "total-supply-hard",
|
|
|
|
Short: "Get HARD total supply",
|
|
|
|
Long: "Get the current total supply of HARD 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.QueryTotalSupplyHARD), 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 queryTotalSupplyUSDX(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "total-supply-usdx",
|
|
|
|
Short: "Get USDX total supply",
|
|
|
|
Long: "Get the current total supply of USDX 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.QueryTotalSupplyUSDX), 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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|