Skip to content

Commit

Permalink
update votedPowerResult
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentysc committed Jan 23, 2024
1 parent dedf31d commit 2412107
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions infrastructure/httpapi/handlers/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,23 @@ 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) {
handler.logger.Errorf("error retrieving proposal tally: %v", queryTallyErr)
httpapi.InternalServerError(ctx)
return
}
tally = cosmosapp.Tally{
Yes: "0",
Abstain: "0",
No: "0",
NoWithVeto: "0",
}
}
}

Expand Down Expand Up @@ -117,34 +118,40 @@ 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{
proposal,

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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2412107

Please sign in to comment.