0g-chain/x/issuance/client/cli/query.go
Kevin Davis e14466547d
Issuance module (#599)
* wip: issuance module

* add keeper and module methods

* add begin blocker

* add client

* update events

* add simulations

* ignore v0.8 migration tests for now

* ignore migration tests in ci

* add test suite

* update spec to match implementation details

* add unblock method

* address review comments

* fix typos
2020-08-17 13:09:02 -04:00

56 lines
1.4 KiB
Go

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/issuance/types"
)
// GetQueryCmd returns the cli query commands for the issuance module
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
issuanceQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
}
issuanceQueryCmd.AddCommand(flags.GetCommands(
queryParamsCmd(queryRoute, cdc),
)...)
return issuanceQueryCmd
}
func queryParamsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "params",
Short: fmt.Sprintf("get the %s module parameters", types.ModuleName),
Long: "Get the current global issuance module parameters.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
// Query
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetParams)
res, height, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}
cliCtx = cliCtx.WithHeight(height)
// Decode and print results
var params types.Params
if err := cdc.UnmarshalJSON(res, &params); err != nil {
return fmt.Errorf("failed to unmarshal params: %w", err)
}
return cliCtx.PrintOutput(params)
},
}
}