Skip to content

Commit

Permalink
fix gov cli to use custom query for tallying (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Sep 24, 2024
1 parent 6eea5ab commit 973f949
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions x/gov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func GetQueryCmd(ac address.Codec) *cobra.Command {
GetCmdQueryProposal(),
GetCmdQueryProposals(ac),
GetCmdQueryParams(),
GetCmdQueryTally(),
)

return govQueryCmd
Expand Down Expand Up @@ -273,3 +274,46 @@ $ %s query gov params

return cmd
}

func GetCmdQueryTally() *cobra.Command {
cmd := &cobra.Command{
Use: "tally [proposal-id]",
Args: cobra.ExactArgs(1),
Short: "Query the tally of a proposal with the given id",
Long: strings.TrimSpace(
fmt.Sprintf(`Query the tally of a proposal with the given id.
Example:
$ %s query gov tally 1
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
proposalID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("invalid proposal-id: %s", args[0])
}

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := customtypes.NewQueryClient(clientCtx)

res, err := queryClient.TallyResult(
cmd.Context(),
&customtypes.QueryTallyResultRequest{ProposalId: proposalID},
)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

0 comments on commit 973f949

Please sign in to comment.