added cli support
This commit is contained in:
parent
5f89ff6bed
commit
9cc384c2f0
|
@ -201,6 +201,11 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
|
||||||
vote := executeGetVote(t, fmt.Sprintf("gaiacli gov query-vote --proposalID=1 --voter=%s --output=json %v", fooAddr, flags))
|
vote := executeGetVote(t, fmt.Sprintf("gaiacli gov query-vote --proposalID=1 --voter=%s --output=json %v", fooAddr, flags))
|
||||||
require.Equal(t, int64(1), vote.ProposalID)
|
require.Equal(t, int64(1), vote.ProposalID)
|
||||||
require.Equal(t, gov.OptionYes, vote.Option)
|
require.Equal(t, gov.OptionYes, vote.Option)
|
||||||
|
|
||||||
|
votes := executeGetVotes(t, fmt.Sprintf("gaiacli gov query-votes --proposalID=1 --output=json %v", flags))
|
||||||
|
require.Len(t, votes, 1)
|
||||||
|
require.Equal(t, int64(1), votes[0].ProposalID)
|
||||||
|
require.Equal(t, gov.OptionYes, votes[0].Option)
|
||||||
}
|
}
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
//___________________________________________________________________________________
|
||||||
|
@ -305,3 +310,12 @@ func executeGetVote(t *testing.T, cmdStr string) gov.Vote {
|
||||||
require.NoError(t, err, "out %v\n, err %v", out, err)
|
require.NoError(t, err, "out %v\n, err %v", out, err)
|
||||||
return vote
|
return vote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func executeGetVotes(t *testing.T, cmdStr string) []gov.Vote {
|
||||||
|
out := tests.ExecuteT(t, cmdStr)
|
||||||
|
var votes []gov.Vote
|
||||||
|
cdc := app.MakeCodec()
|
||||||
|
err := cdc.UnmarshalJSON([]byte(out), &votes)
|
||||||
|
require.NoError(t, err, "out %v\n, err %v", out, err)
|
||||||
|
return votes
|
||||||
|
}
|
||||||
|
|
|
@ -112,6 +112,7 @@ func main() {
|
||||||
client.GetCommands(
|
client.GetCommands(
|
||||||
govcmd.GetCmdQueryProposal("gov", cdc),
|
govcmd.GetCmdQueryProposal("gov", cdc),
|
||||||
govcmd.GetCmdQueryVote("gov", cdc),
|
govcmd.GetCmdQueryVote("gov", cdc),
|
||||||
|
govcmd.GetCmdQueryVotes("gov", cdc),
|
||||||
)...)
|
)...)
|
||||||
govCmd.AddCommand(
|
govCmd.AddCommand(
|
||||||
client.PostCommands(
|
client.PostCommands(
|
||||||
|
|
|
@ -245,3 +245,54 @@ func GetCmdQueryVote(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Command to Get a Proposal Information
|
||||||
|
func GetCmdQueryVotes(storeName string, cdc *wire.Codec) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "query-votes",
|
||||||
|
Short: "query votes on a proposal",
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
proposalID := viper.GetInt64(flagProposalID)
|
||||||
|
|
||||||
|
ctx := context.NewCoreContextFromViper()
|
||||||
|
|
||||||
|
res, err := ctx.QueryStore(gov.KeyProposal(proposalID), storeName)
|
||||||
|
if len(res) == 0 || err != nil {
|
||||||
|
return errors.Errorf("proposalID [%d] does not exist", proposalID)
|
||||||
|
}
|
||||||
|
|
||||||
|
var proposal gov.Proposal
|
||||||
|
cdc.MustUnmarshalBinary(res, &proposal)
|
||||||
|
|
||||||
|
if proposal.GetStatus() != gov.StatusVotingPeriod {
|
||||||
|
fmt.Println("Proposal not in voting period.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
res2, err := ctx.QuerySubspace(cdc, gov.KeyVotesSubspace(proposalID), storeName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var votes []gov.Vote
|
||||||
|
for i := 0; i < len(res2); i++ {
|
||||||
|
var vote gov.Vote
|
||||||
|
cdc.MustUnmarshalBinary(res2[i].Value, &vote)
|
||||||
|
votes = append(votes, vote)
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := wire.MarshalJSONIndent(cdc, votes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(string(output))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flags().String(flagProposalID, "", "proposalID of which proposal's votes are being queried")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue