planetmint-go/x/dao/client/cli/query_challenge.go
Julian Strobl cb230f1615
refactor: cli queries (#288)
Signed-off-by: Julian Strobl <jmastr@mailbox.org>
2024-01-18 12:06:21 +01:00

51 lines
976 B
Go

package cli
import (
"strconv"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/planetmint/planetmint-go/x/dao/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdGetChallenge() *cobra.Command {
cmd := &cobra.Command{
Use: "challenge [height]",
Short: "Query for challenge by height",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqHeight, err := cast.ToInt64E(args[0])
if err != nil {
return err
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryGetChallengeRequest{
Height: reqHeight,
}
res, err := queryClient.GetChallenge(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}