cosmos-sdk/x/gov/client/cli/query.go
mergify[bot] 397b9ce1a9
refactor(client): use cmtservice for comet-validator-set command (backport #17187) (#17257)
Co-authored-by: zakir <80246097+zakir-code@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
2023-08-02 09:21:23 +00:00

75 lines
1.9 KiB
Go

package cli
import (
"encoding/json"
"fmt"
"strconv"
"github.com/spf13/cobra"
"cosmossdk.io/core/address"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
// GetCustomQueryCmd returns the cli query commands for this module
// These commands do not rely on gRPC and cannot be autogenerated
func GetCustomQueryCmd(ac address.Codec) *cobra.Command {
// Group gov queries under a subcommand
govQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the gov module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
govQueryCmd.AddCommand(
GetCmdQueryProposer(),
)
return govQueryCmd
}
// GetCmdQueryProposer implements the query proposer command.
func GetCmdQueryProposer() *cobra.Command {
cmd := &cobra.Command{
Use: "proposer [proposal-id]",
Args: cobra.ExactArgs(1),
Short: "Query the proposer of a governance proposal",
Long: "Query which address proposed a proposal with a given ID",
Example: fmt.Sprintf("%s query gov proposer 1", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
// validate that the proposalID is a uint
proposalID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("proposal-id %s is not a valid uint", args[0])
}
prop, err := gcutils.QueryProposerByTxQuery(clientCtx, proposalID)
if err != nil {
return err
}
output, err := json.Marshal(prop)
if err != nil {
return err
}
return clientCtx.PrintRaw(output)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}