From 50dd53fec3bbb7694b7addb2511f948cee90c411 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Fri, 17 Aug 2018 00:40:30 -0700 Subject: [PATCH] added tally query route to gov --- x/gov/queryable.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/x/gov/queryable.go b/x/gov/queryable.go index 13bdfd08d..28e32eb67 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -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() - // } + 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) - // } - // _, tallyResult, _ := tally(ctx, keeper, proposal) - return nil, nil + 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 }