From dedf31d9958b5f04fadf81fd6ddd31154eca799f Mon Sep 17 00:00:00 2001 From: vincentysc Date: Tue, 23 Jan 2024 17:02:04 +0800 Subject: [PATCH 1/2] hide proposal tally in voting period --- infrastructure/httpapi/handlers/proposals.go | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/infrastructure/httpapi/handlers/proposals.go b/infrastructure/httpapi/handlers/proposals.go index 9ee1f33d..81e498dc 100644 --- a/infrastructure/httpapi/handlers/proposals.go +++ b/infrastructure/httpapi/handlers/proposals.go @@ -63,18 +63,22 @@ func (handler *Proposals) FindById(ctx *fasthttp.RequestCtx) { return } - tally, queryTallyErr := handler.cosmosClient.ProposalTally(idParam) - if queryTallyErr != nil { - if !errors.Is(queryTallyErr, cosmosapp.ErrProposalNotFound) { - handler.logger.Errorf("error retrieving proposal tally: %v", queryTallyErr) - httpapi.InternalServerError(ctx) - return - } - tally = cosmosapp.Tally{ - Yes: "0", - Abstain: "0", - No: "0", - NoWithVeto: "0", + tally := cosmosapp.Tally{ + Yes: "0", + Abstain: "0", + No: "0", + NoWithVeto: "0", + } + + var queryTallyErr error + if proposal.Status == proposal_view.PROPOSAL_STATUS_VOTING_PERIOD { + tally, queryTallyErr = handler.cosmosClient.ProposalTally(idParam) + if queryTallyErr != nil { + if !errors.Is(queryTallyErr, cosmosapp.ErrProposalNotFound) { + handler.logger.Errorf("error retrieving proposal tally: %v", queryTallyErr) + httpapi.InternalServerError(ctx) + return + } } } From 2412107c41383dea8570d6ae7e21df90cd836ba9 Mon Sep 17 00:00:00 2001 From: vincentysc Date: Tue, 23 Jan 2024 17:27:38 +0800 Subject: [PATCH 2/2] update votedPowerResult --- infrastructure/httpapi/handlers/proposals.go | 63 +++++++++++--------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/infrastructure/httpapi/handlers/proposals.go b/infrastructure/httpapi/handlers/proposals.go index 81e498dc..6cfc3249 100644 --- a/infrastructure/httpapi/handlers/proposals.go +++ b/infrastructure/httpapi/handlers/proposals.go @@ -63,15 +63,10 @@ func (handler *Proposals) FindById(ctx *fasthttp.RequestCtx) { return } - tally := cosmosapp.Tally{ - Yes: "0", - Abstain: "0", - No: "0", - NoWithVeto: "0", - } + tally := cosmosapp.Tally{} var queryTallyErr error - if proposal.Status == proposal_view.PROPOSAL_STATUS_VOTING_PERIOD { + if proposal.Status != proposal_view.PROPOSAL_STATUS_VOTING_PERIOD { tally, queryTallyErr = handler.cosmosClient.ProposalTally(idParam) if queryTallyErr != nil { if !errors.Is(queryTallyErr, cosmosapp.ErrProposalNotFound) { @@ -79,6 +74,12 @@ func (handler *Proposals) FindById(ctx *fasthttp.RequestCtx) { httpapi.InternalServerError(ctx) return } + tally = cosmosapp.Tally{ + Yes: "0", + Abstain: "0", + No: "0", + NoWithVeto: "0", + } } } @@ -117,21 +118,32 @@ func (handler *Proposals) FindById(ctx *fasthttp.RequestCtx) { } requiredVotingPower := new(big.Float).Mul(totalBonded, quorum) + var votedPowerResult *ProposalVotedPowerResult totalVotedPower := big.NewInt(0) - for _, votedPowerStr := range []string{ - tally.Yes, - tally.No, - tally.NoWithVeto, - tally.Abstain, - } { - votedPower, parseVotedPowerOk := new(big.Int).SetString(votedPowerStr, 10) - if !parseVotedPowerOk { - handler.logger.Error("error parsing voted power") - httpapi.InternalServerError(ctx) - return + + if proposal.Status != proposal_view.PROPOSAL_STATUS_VOTING_PERIOD { + for _, votedPowerStr := range []string{ + tally.Yes, + tally.No, + tally.NoWithVeto, + tally.Abstain, + } { + votedPower, parseVotedPowerOk := new(big.Int).SetString(votedPowerStr, 10) + if !parseVotedPowerOk { + handler.logger.Error("error parsing voted power") + httpapi.InternalServerError(ctx) + return + } + + totalVotedPower = new(big.Int).Add(totalVotedPower, votedPower) } - totalVotedPower = new(big.Int).Add(totalVotedPower, votedPower) + votedPowerResult = &ProposalVotedPowerResult{ + Yes: tally.Yes, + Abstain: tally.Abstain, + No: tally.No, + NoWithVeto: tally.NoWithVeto, + } } proposalDetails := ProposalDetails{ @@ -139,12 +151,7 @@ func (handler *Proposals) FindById(ctx *fasthttp.RequestCtx) { requiredVotingPower.Text('f', 0), totalVotedPower.Text(10), - ProposalVotedPowerResult{ - Yes: tally.Yes, - Abstain: tally.Abstain, - No: tally.No, - NoWithVeto: tally.NoWithVeto, - }, + votedPowerResult, } httpapi.Success(ctx, proposalDetails) @@ -275,9 +282,9 @@ func (handler *Proposals) ListDepositorsById(ctx *fasthttp.RequestCtx) { type ProposalDetails struct { *proposal_view.ProposalWithMonikerRow - RequiredVotingPower string `json:"requiredVotingPower"` - TotalVotedPower string `json:"totalVotedPower"` - VotedPowerResult ProposalVotedPowerResult `json:"votedPowerResult"` + RequiredVotingPower string `json:"requiredVotingPower"` + TotalVotedPower string `json:"totalVotedPower"` + VotedPowerResult *ProposalVotedPowerResult `json:"votedPowerResult"` } type ProposalVotedPowerResult struct {