proposal_vote_status.gno
1.63 Kb · 57 lines
1package v1
2
3import (
4 "gno.land/r/gnoswap/gov/governance"
5)
6
7type ProposalVoteStatusResolver struct {
8 *governance.ProposalVoteStatus
9}
10
11func NewProposalVoteStatusResolver(voteStatus *governance.ProposalVoteStatus) *ProposalVoteStatusResolver {
12 return &ProposalVoteStatusResolver{voteStatus}
13}
14
15// TotalVoteWeight returns the total weight of all votes cast (yes + no).
16//
17// Returns:
18// - int64: combined weight of all votes
19func (p *ProposalVoteStatusResolver) TotalVoteWeight() int64 {
20 return safeAddInt64(p.YesWeight(), p.NoWeight())
21}
22
23// IsPassed determines if the proposal has passed the voting requirements.
24// A proposal passes when quorum is reached and "yes" votes strictly exceed "no" votes.
25func (p *ProposalVoteStatusResolver) IsPassed() bool {
26 if p.TotalVoteWeight() < p.QuorumAmount() {
27 return false
28 }
29
30 return p.YesWeight() > p.NoWeight()
31}
32
33// addYesVoteWeight adds the specified weight to the "yes" vote tally.
34// This is called when a user votes "yes" on the proposal.
35//
36// Parameters:
37// - yea: vote weight to add to "yes" votes
38//
39// Returns:
40// - error: always nil (reserved for future validation)
41func (p *ProposalVoteStatusResolver) AddYesVoteWeight(yea int64) error {
42 p.SetYesWeight(safeAddInt64(p.YesWeight(), yea))
43 return nil
44}
45
46// addNoVoteWeight adds the specified weight to the "no" vote tally.
47// This is called when a user votes "no" on the proposal.
48//
49// Parameters:
50// - nay: vote weight to add to "no" votes
51//
52// Returns:
53// - error: always nil (reserved for future validation)
54func (p *ProposalVoteStatusResolver) AddNoVoteWeight(nay int64) error {
55 p.SetNoWeight(safeAddInt64(p.NoWeight(), nay))
56 return nil
57}