0g-chain/x/validator-vesting/client/cli/query.go
John Maheswaran 51fc70b5ac
[R4R] This is the implementation of the total circulating supply (#376)
* adding empty query files where we will implement the cli and rest interfaces

* adding querier file

* adding aliases, querier, expected keepers, types, module updates

* starting to work on query

* adding alias for QueryCirculatingSupply

* adding TotalCirculatingSupply type

* adding alias for TotalCirculatingSupply type

* adding QueryCirculatingSupplyCmd to clieng query file

* adding register routes function

* adding rest query handling function, register endpoint

* fix types include statement

* remove unused mux include

* another import fix

* remove unused variable

* adding rest to module

* fix missing variable names

* another missing variable fix

* remove dead code comment

* fix typo in circulating-supply

* fix import

* fix querierroute return to return the module name instead of empty string

* rename function, fix build issue

* return error instead of nil if there is an error

* import types from cosmos sdk, fix return type

* set querier route to module name in key.go

* adding query and rest updates

* aliasing new querying circulating supply function

* directly write output

* fix routes

* adding total supply functionality

* converting from microkava to kava

* Update x/validator-vesting/client/cli/query.go

typo fix

Co-Authored-By: Kevin Davis <karzak@users.noreply.github.com>

Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
2020-02-25 10:29:54 -05:00

73 lines
2.1 KiB
Go

package cli
import (
"fmt"
"github.com/kava-labs/kava/x/validator-vesting/internal/types"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
// Group nameservice queries under a subcommand
queryValidatorVestingCmd := &cobra.Command{
Use: "validator-vesting",
Short: "Querying commands for the validator vesting module",
}
queryValidatorVestingCmd.AddCommand(client.GetCommands(
QueryCirculatingSupplyCmd(queryRoute, cdc),
QueryTotalSupplyCmd(queryRoute, cdc),
)...)
return queryValidatorVestingCmd
}
// QueryCirculatingSupplyCmd queries the total circulating supply
func QueryCirculatingSupplyCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "circulating-supply",
Short: "Query circulating supply information",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryCirculatingSupply), nil)
if err != nil {
fmt.Printf("could not get total circulating supply\n")
return err
}
var out sdk.Dec
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}
// QueryTotalSupplyCmd queries the total supply of ukava
func QueryTotalSupplyCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "total-supply",
Short: "Query total supply information",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryTotalSupply), nil)
if err != nil {
fmt.Printf("could not get total supply\n")
return err
}
var out sdk.Dec
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}