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