proposal_status.gno
3.12 Kb ยท 100 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: human-readable status name
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
54func NewProposalStatusBy(
55 schedule *ProposalScheduleStatus,
56 actionStatus *ProposalActionStatus,
57 voteStatus *ProposalVoteStatus,
58) *ProposalStatus {
59 return &ProposalStatus{
60 schedule: schedule,
61 actionStatus: actionStatus,
62 voteStatus: voteStatus,
63 }
64}
65
66/* Getter methods */
67func (s *ProposalStatus) Schedule() *ProposalScheduleStatus { return s.schedule }
68func (s *ProposalStatus) ActionStatus() *ProposalActionStatus { return s.actionStatus }
69func (s *ProposalStatus) VoteStatus() *ProposalVoteStatus { return s.voteStatus }
70
71/* Delegation getters for vote data */
72
73// YesWeight returns the total weight of "yes" votes.
74//
75// Returns:
76// - int64: total "yes" vote weight
77func (s *ProposalStatus) YesWeight() int64 {
78 return s.voteStatus.YesWeight()
79}
80
81// NoWeight returns the total weight of "no" votes.
82//
83// Returns:
84// - int64: total "no" vote weight
85func (s *ProposalStatus) NoWeight() int64 {
86 return s.voteStatus.NoWeight()
87}
88
89// Clone creates a deep copy of the ProposalStatus.
90func (s *ProposalStatus) Clone() *ProposalStatus {
91 if s == nil {
92 return nil
93 }
94
95 return &ProposalStatus{
96 schedule: s.schedule.Clone(),
97 actionStatus: s.actionStatus.Clone(),
98 voteStatus: s.voteStatus.Clone(),
99 }
100}