Skip to content

Commit

Permalink
added tally query route to gov
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnya97 committed Aug 17, 2018
1 parent 94cb35f commit 307fff1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions x/gov/queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,25 @@ type QueryTallyParams struct {
func queryTally(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper) (res []byte, err sdk.Error) {
// TODO: Dependant on #1914

// var proposalID int64
// err2 := keeper.cdc.UnmarshalBinary(req.Data, proposalID)
// if err2 != nil {
// return []byte{}, sdk.ErrUnknownRequest()
// }

// proposal := keeper.GetProposal(ctx, proposalID)
// if proposal == nil {
// return []byte{}, ErrUnknownProposal(DefaultCodespace, proposalID)
// }
// _, tallyResult, _ := tally(ctx, keeper, proposal)
return nil, nil
var proposalID int64
err2 := keeper.cdc.UnmarshalBinary(req.Data, proposalID)
if err2 != nil {
return []byte{}, sdk.ErrUnknownRequest("incorrectly formatted request data")
}

proposal := keeper.GetProposal(ctx, proposalID)
if proposal == nil {
return []byte{}, ErrUnknownProposal(DefaultCodespace, proposalID)
}

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
}

0 comments on commit 307fff1

Please sign in to comment.