Search Apps Documentation Source Content File Folder Download Copy Actions Download

proposal_vote_status.gno

2.43 Kb ยท 82 lines
 1package governance
 2
 3// ProposalVoteStatus tracks the voting tallies and requirements for a proposal.
 4// This structure manages vote counting, quorum calculation, and voting outcome determination.
 5type ProposalVoteStatus struct {
 6	yea             int64 // Total weight of "yes" votes collected
 7	nay             int64 // Total weight of "no" votes collected
 8	maxVotingWeight int64 // The max voting weight at the time of proposal creation
 9	quorumAmount    int64 // How many total votes must be collected for the proposal to be valid
10}
11
12/* Getter methods */
13func (p *ProposalVoteStatus) MaxVotingWeight() int64 { return p.maxVotingWeight }
14func (p *ProposalVoteStatus) QuorumAmount() int64    { return p.quorumAmount }
15
16// YesWeight returns the total weight of "yes" votes.
17//
18// Returns:
19//   - int64: total "yes" vote weight
20func (p *ProposalVoteStatus) YesWeight() int64 {
21	return p.yea
22}
23
24// NoWeight returns the total weight of "no" votes.
25//
26// Returns:
27//   - int64: total "no" vote weight
28func (p *ProposalVoteStatus) NoWeight() int64 {
29	return p.nay
30}
31
32/* Setter methods */
33func (p *ProposalVoteStatus) SetYesWeight(yes int64) {
34	p.yea = yes
35}
36
37func (p *ProposalVoteStatus) SetNoWeight(no int64) {
38	p.nay = no
39}
40
41func (p *ProposalVoteStatus) SetMaxVotingWeight(maxVotingWeight int64) {
42	p.maxVotingWeight = maxVotingWeight
43}
44
45func (p *ProposalVoteStatus) SetQuorumAmount(quorumAmount int64) {
46	p.quorumAmount = quorumAmount
47}
48
49// NewProposalVoteStatus creates a new vote status for a proposal.
50// Initializes vote tallies to zero and calculates the quorum requirement.
51//
52// Parameters:
53//   - maxVotingWeight: maximum possible voting weight for this proposal
54//   - quorumAmount: quorum amount required for passage
55//
56// Returns:
57//   - *ProposalVoteStatus: new vote status instance
58func NewProposalVoteStatus(
59	maxVotingWeight int64,
60	quorumAmount int64,
61) *ProposalVoteStatus {
62	return &ProposalVoteStatus{
63		yea:             0,               // Start with no "yes" votes
64		nay:             0,               // Start with no "no" votes
65		maxVotingWeight: maxVotingWeight, // Set maximum possible votes
66		quorumAmount:    quorumAmount,    // Set required votes for passage
67	}
68}
69
70// Clone creates a deep copy of the ProposalVoteStatus.
71func (p *ProposalVoteStatus) Clone() *ProposalVoteStatus {
72	if p == nil {
73		return nil
74	}
75
76	return &ProposalVoteStatus{
77		yea:             p.yea,
78		nay:             p.nay,
79		maxVotingWeight: p.maxVotingWeight,
80		quorumAmount:    p.quorumAmount,
81	}
82}