proposal_action_status.gno
4.29 Kb ยท 141 lines
1package governance
2
3import (
4 "errors"
5)
6
7var (
8 errProposalNotExecutable = errors.New("proposal not executable")
9)
10
11// ProposalActionStatus tracks the execution and cancellation status of a proposal.
12// This structure manages the action-related state including who performed actions and when.
13type ProposalActionStatus struct {
14 canceled bool // Whether the proposal has been canceled
15 canceledAt int64 // Timestamp when proposal was canceled
16 canceledHeight int64 // Block height when proposal was canceled
17 canceledBy address // Who canceled the proposal
18
19 executed bool // Whether the proposal has been executed
20 executedAt int64 // Timestamp when proposal was executed
21 executedHeight int64 // Block height when proposal was executed
22 executedBy address // Who executed the proposal
23
24 executable bool // Whether this proposal type supports execution
25}
26
27/* Getter methods */
28func (p *ProposalActionStatus) Canceled() bool { return p.canceled }
29func (p *ProposalActionStatus) CanceledAt() int64 { return p.canceledAt }
30func (p *ProposalActionStatus) CanceledHeight() int64 { return p.canceledHeight }
31func (p *ProposalActionStatus) Executed() bool { return p.executed }
32func (p *ProposalActionStatus) ExecutedAt() int64 { return p.executedAt }
33func (p *ProposalActionStatus) ExecutedHeight() int64 { return p.executedHeight }
34func (p *ProposalActionStatus) Executable() bool { return p.executable }
35
36/* Setter methods */
37func (p *ProposalActionStatus) SetCanceled(canceled bool) {
38 p.canceled = canceled
39}
40
41func (p *ProposalActionStatus) SetCanceledAt(canceledAt int64) {
42 p.canceledAt = canceledAt
43}
44
45func (p *ProposalActionStatus) SetCanceledHeight(canceledHeight int64) {
46 p.canceledHeight = canceledHeight
47}
48
49func (p *ProposalActionStatus) SetCanceledBy(canceledBy address) {
50 p.canceledBy = canceledBy
51}
52
53func (p *ProposalActionStatus) SetExecuted(executed bool) {
54 p.executed = executed
55}
56
57func (p *ProposalActionStatus) SetExecutedAt(executedAt int64) {
58 p.executedAt = executedAt
59}
60
61func (p *ProposalActionStatus) SetExecutedHeight(executedHeight int64) {
62 p.executedHeight = executedHeight
63}
64
65func (p *ProposalActionStatus) SetExecutedBy(executedBy address) {
66 p.executedBy = executedBy
67}
68
69func (p *ProposalActionStatus) SetExecutable(executable bool) {
70 p.executable = executable
71}
72
73// CanceledBy returns the address that canceled the proposal.
74// Only meaningful if IsCanceled() returns true.
75//
76// Returns:
77// - std.Address: address of the canceller
78func (p *ProposalActionStatus) CanceledBy() address {
79 return p.canceledBy
80}
81
82// IsExecuted returns whether the proposal has been executed.
83//
84// Returns:
85// - bool: true if proposal has been executed
86func (p *ProposalActionStatus) IsExecuted() bool {
87 return p.executed
88}
89
90// ExecutedBy returns the address that executed the proposal.
91// Only meaningful if IsExecuted() returns true.
92//
93// Returns:
94// - std.Address: address of the executor
95func (p *ProposalActionStatus) ExecutedBy() address {
96 return p.executedBy
97}
98
99// IsExecutable returns whether this proposal type can be executed.
100// Text proposals return false, while other types return true.
101//
102// Returns:
103// - bool: true if proposal type supports execution
104func (p *ProposalActionStatus) IsExecutable() bool {
105 return p.executable
106}
107
108// NewProposalActionStatus creates a new action status for a proposal.
109// Initializes the status with default values and the executable flag.
110//
111// Parameters:
112// - executable: whether this proposal type can be executed
113//
114// Returns:
115// - *ProposalActionStatus: new action status instance
116func NewProposalActionStatus(executable bool) *ProposalActionStatus {
117 return &ProposalActionStatus{
118 canceled: false, // Proposal starts as not canceled
119 executed: false, // Proposal starts as not executed
120 executable: executable, // Set based on proposal type
121 }
122}
123
124// Clone creates a deep copy of the ProposalActionStatus.
125func (p *ProposalActionStatus) Clone() *ProposalActionStatus {
126 if p == nil {
127 return nil
128 }
129
130 return &ProposalActionStatus{
131 canceled: p.canceled,
132 canceledAt: p.canceledAt,
133 canceledHeight: p.canceledHeight,
134 canceledBy: p.canceledBy,
135 executed: p.executed,
136 executedAt: p.executedAt,
137 executedHeight: p.executedHeight,
138 executedBy: p.executedBy,
139 executable: p.executable,
140 }
141}