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_status.gno

4.15 Kb · 127 lines
  1package governance
  2
  3// ProposalStatusType represents the current status of a proposal in its lifecycle.
  4// These statuses determine what actions are available for a proposal.
  5type ProposalStatusType int
  6
  7const (
  8	_                ProposalStatusType = iota
  9	StatusUpcoming                      // Proposal created but voting hasn't started yet
 10	StatusActive                        // Proposal is in voting period
 11	StatusPassed                        // Proposal has passed but hasn't been executed (or is text proposal)
 12	StatusRejected                      // Proposal failed to meet voting requirements
 13	StatusExecutable                    // Proposal can be executed (passed and in execution window)
 14	StatusExecuted                      // Proposal has been successfully executed
 15	StatusExpired                       // Proposal execution window has passed
 16	StatusCanceled                      // Proposal has been canceled
 17)
 18
 19// String returns the string representation of ProposalStatusType for display purposes.
 20//
 21// Returns:
 22//   - string: lowercase status name, or "unknown" for an unrecognized value
 23func (s ProposalStatusType) String() string {
 24	switch s {
 25	case StatusUpcoming:
 26		return "upcoming"
 27	case StatusActive:
 28		return "active"
 29	case StatusPassed:
 30		return "passed"
 31	case StatusRejected:
 32		return "rejected"
 33	case StatusExecutable:
 34		return "executable"
 35	case StatusExecuted:
 36		return "executed"
 37	case StatusExpired:
 38		return "expired"
 39	case StatusCanceled:
 40		return "canceled"
 41	default:
 42		return "unknown"
 43	}
 44}
 45
 46// ProposalStatus manages the complete status of a proposal including scheduling, voting, and actions.
 47// This is the central status tracking structure that coordinates different aspects of proposal state.
 48type ProposalStatus struct {
 49	schedule     *ProposalScheduleStatus // Time-based scheduling information
 50	actionStatus *ProposalActionStatus   // Execution and cancellation status
 51	voteStatus   *ProposalVoteStatus     // Voting tallies and requirements
 52}
 53
 54// NewProposalStatusBy combines schedule, action, and vote state into a proposal status.
 55//
 56// Parameters:
 57//   - schedule: time-based lifecycle schedule for the proposal
 58//   - actionStatus: execution and cancellation state for the proposal
 59//   - voteStatus: vote tallies and voting requirements for the proposal
 60//
 61// Returns:
 62//   - *ProposalStatus: status object containing the supplied lifecycle components
 63func NewProposalStatusBy(
 64	schedule *ProposalScheduleStatus,
 65	actionStatus *ProposalActionStatus,
 66	voteStatus *ProposalVoteStatus,
 67) *ProposalStatus {
 68	return &ProposalStatus{
 69		schedule:     schedule,
 70		actionStatus: actionStatus,
 71		voteStatus:   voteStatus,
 72	}
 73}
 74
 75/* Getter methods */
 76// Schedule returns the proposal's time-based scheduling state.
 77//
 78// Returns:
 79//   - *ProposalScheduleStatus: schedule containing proposal lifecycle timestamps
 80func (s *ProposalStatus) Schedule() *ProposalScheduleStatus { return s.schedule }
 81
 82// ActionStatus returns the proposal's execution and cancellation state.
 83//
 84// Returns:
 85//   - *ProposalActionStatus: action state associated with the proposal
 86func (s *ProposalStatus) ActionStatus() *ProposalActionStatus { return s.actionStatus }
 87
 88// VoteStatus returns the proposal's vote tallies and voting requirements.
 89//
 90// Returns:
 91//   - *ProposalVoteStatus: vote state associated with the proposal
 92func (s *ProposalStatus) VoteStatus() *ProposalVoteStatus { return s.voteStatus }
 93
 94/* Delegation getters for vote data */
 95
 96// YesWeight returns the total weight of "yes" votes.
 97//
 98// Returns:
 99//   - int64: total "yes" vote weight
100func (s *ProposalStatus) YesWeight() int64 {
101	return s.voteStatus.YesWeight()
102}
103
104// NoWeight returns the total weight of "no" votes.
105//
106// Returns:
107//   - int64: total "no" vote weight
108func (s *ProposalStatus) NoWeight() int64 {
109	return s.voteStatus.NoWeight()
110}
111
112// Clone creates a deep copy of the ProposalStatus, or nil when the
113// receiver is nil.
114//
115// Returns:
116//   - *ProposalStatus: independent copy of the status, or nil for a nil receiver
117func (s *ProposalStatus) Clone() *ProposalStatus {
118	if s == nil {
119		return nil
120	}
121
122	return &ProposalStatus{
123		schedule:     s.schedule.Clone(),
124		actionStatus: s.actionStatus.Clone(),
125		voteStatus:   s.voteStatus.Clone(),
126	}
127}