added tally query route to gov

This commit is contained in:
Sunny Aggarwal 2018-08-17 00:40:30 -07:00
parent 44bf69e564
commit 50dd53fec3
1 changed files with 20 additions and 11 deletions

View File

@ -156,16 +156,25 @@ type QueryTallyParams struct {
func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) { func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) {
// TODO: Dependant on #1914 // TODO: Dependant on #1914
// var proposalID int64 var proposalID int64
// err2 := keeper.cdc.UnmarshalBinary(req.Data, proposalID) err2 := keeper.cdc.UnmarshalBinary(req.Data, proposalID)
// if err2 != nil { if err2 != nil {
// return []byte{}, sdk.ErrUnknownRequest() return []byte{}, sdk.ErrUnknownRequest("incorrectly formatted request data")
// } }
// proposal := keeper.GetProposal(ctx, proposalID) proposal := keeper.GetProposal(ctx, proposalID)
// if proposal == nil { if proposal == nil {
// return []byte{}, ErrUnknownProposal(DefaultCodespace, proposalID) return []byte{}, ErrUnknownProposal(DefaultCodespace, proposalID)
// } }
// _, tallyResult, _ := tally(ctx, keeper, proposal)
return nil, nil if proposal.GetStatus() == StatusDepositPeriod {
return keeper.cdc.MustMarshalBinaryBare(EmptyTallyResult()), nil
}
if proposal.GetStatus() == StatusPassed || proposal.GetStatus() == StatusRejected {
return keeper.cdc.MustMarshalBinaryBare(proposal.GetTallyResult()), nil
}
_, tallyResult, _ := tally(ctx, keeper, proposal)
return keeper.cdc.MustMarshalBinaryBare(tallyResult), nil
} }