Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

proposal_vote_status.gno

3.51 Kb · 110 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 */
 13// MaxVotingWeight returns the maximum voting weight captured for the proposal.
 14//
 15// Returns:
 16//   - int64: maximum voting weight used when evaluating the proposal's quorum.
 17func (p *ProposalVoteStatus) MaxVotingWeight() int64 { return p.maxVotingWeight }
 18
 19// QuorumAmount returns the voting weight required for the proposal to satisfy quorum.
 20//
 21// Returns:
 22//   - int64: minimum total vote weight required by this proposal.
 23func (p *ProposalVoteStatus) QuorumAmount() int64 { return p.quorumAmount }
 24
 25// YesWeight returns the total weight of "yes" votes.
 26//
 27// Returns:
 28//   - int64: total "yes" vote weight
 29func (p *ProposalVoteStatus) YesWeight() int64 {
 30	return p.yea
 31}
 32
 33// NoWeight returns the total weight of "no" votes.
 34//
 35// Returns:
 36//   - int64: total "no" vote weight
 37func (p *ProposalVoteStatus) NoWeight() int64 {
 38	return p.nay
 39}
 40
 41/* Setter methods */
 42// SetYesWeight replaces the proposal's accumulated yes-vote weight.
 43//
 44// Parameters:
 45//   - yes: total weight to record for affirmative votes.
 46func (p *ProposalVoteStatus) SetYesWeight(yes int64) {
 47	p.yea = yes
 48}
 49
 50// SetNoWeight replaces the proposal's accumulated no-vote weight.
 51//
 52// Parameters:
 53//   - no: total weight to record for negative votes.
 54func (p *ProposalVoteStatus) SetNoWeight(no int64) {
 55	p.nay = no
 56}
 57
 58// SetMaxVotingWeight records the proposal's maximum voting-weight snapshot.
 59//
 60// Parameters:
 61//   - maxVotingWeight: maximum voting weight available when the proposal was created.
 62func (p *ProposalVoteStatus) SetMaxVotingWeight(maxVotingWeight int64) {
 63	p.maxVotingWeight = maxVotingWeight
 64}
 65
 66// SetQuorumAmount records the proposal's quorum requirement.
 67//
 68// Parameters:
 69//   - quorumAmount: minimum total vote weight required for this proposal.
 70func (p *ProposalVoteStatus) SetQuorumAmount(quorumAmount int64) {
 71	p.quorumAmount = quorumAmount
 72}
 73
 74// NewProposalVoteStatus creates a new vote status for a proposal.
 75// Initializes vote tallies to zero and calculates the quorum requirement.
 76//
 77// Parameters:
 78//   - maxVotingWeight: maximum possible voting weight for this proposal
 79//   - quorumAmount: quorum amount required for passage
 80//
 81// Returns:
 82//   - *ProposalVoteStatus: new vote status instance
 83func NewProposalVoteStatus(
 84	maxVotingWeight int64,
 85	quorumAmount int64,
 86) *ProposalVoteStatus {
 87	return &ProposalVoteStatus{
 88		yea:             0,               // Start with no "yes" votes
 89		nay:             0,               // Start with no "no" votes
 90		maxVotingWeight: maxVotingWeight, // Set maximum possible votes
 91		quorumAmount:    quorumAmount,    // Set required votes for passage
 92	}
 93}
 94
 95// Clone returns an independent copy of the vote status, or nil when the receiver is nil.
 96//
 97// Returns:
 98//   - *ProposalVoteStatus: copied vote tallies and requirements, or nil for a nil receiver.
 99func (p *ProposalVoteStatus) Clone() *ProposalVoteStatus {
100	if p == nil {
101		return nil
102	}
103
104	return &ProposalVoteStatus{
105		yea:             p.yea,
106		nay:             p.nay,
107		maxVotingWeight: p.maxVotingWeight,
108		quorumAmount:    p.quorumAmount,
109	}
110}