proposal.gno
4.76 Kb ยท 166 lines
1package governance
2
3// Proposal represents a governance proposal with all its associated data and state.
4// This is the core structure that tracks proposal lifecycle from creation to execution.
5type Proposal struct {
6 id int64 // Unique identifier for the proposal
7 proposer address // The address of the proposer
8 configVersion int64 // The version of the governance config used
9 status *ProposalStatus // Current status and voting information
10 metadata *ProposalMetadata // Title and description
11 data *ProposalData // Type-specific proposal data
12 snapshotTime int64 // Timestamp for voting weight snapshot lookup
13 createdAt int64 // Creation timestamp
14 createdHeight int64 // Block height at creation
15}
16
17// ID returns the unique identifier of the proposal.
18func (p *Proposal) ID() int64 {
19 return p.id
20}
21
22// Type returns the type of this proposal.
23func (p *Proposal) Type() ProposalType {
24 return p.data.ProposalType()
25}
26
27// Title returns the proposal title.
28func (p *Proposal) Title() string {
29 return p.metadata.Title()
30}
31
32// Description returns the proposal description.
33func (p *Proposal) Description() string {
34 return p.metadata.Description()
35}
36
37// Proposer returns the address of the proposal creator.
38func (p *Proposal) Proposer() address {
39 return p.proposer
40}
41
42// CreatedAt returns the creation timestamp of the proposal.
43func (p *Proposal) CreatedAt() int64 {
44 return p.status.schedule.createTime
45}
46
47// VotingYesWeight returns the total weight of "yes" votes.
48func (p *Proposal) VotingYesWeight() int64 {
49 return p.status.voteStatus.yea
50}
51
52// VotingNoWeight returns the total weight of "no" votes.
53func (p *Proposal) VotingNoWeight() int64 {
54 return p.status.voteStatus.nay
55}
56
57// VotingQuorumAmount returns minimum vote weight required for proposal to pass.
58func (p *Proposal) VotingQuorumAmount() int64 {
59 return p.status.voteStatus.quorumAmount
60}
61
62// VotingMaxWeight returns maximum possible voting weight for this proposal.
63func (p *Proposal) VotingMaxWeight() int64 {
64 return p.status.voteStatus.maxVotingWeight
65}
66
67// ConfigVersion returns the governance configuration version used for this proposal.
68func (p *Proposal) ConfigVersion() int64 {
69 return p.configVersion
70}
71
72// SnapshotTime returns the snapshot time for voting weight lookup.
73func (p *Proposal) SnapshotTime() int64 {
74 return p.snapshotTime
75}
76
77// Data returns the proposal data.
78func (p *Proposal) Data() *ProposalData {
79 return p.data
80}
81
82// Status returns the proposal status.
83func (p *Proposal) Status() *ProposalStatus {
84 return p.status
85}
86
87// Metadata returns the proposal metadata.
88func (p *Proposal) Metadata() *ProposalMetadata {
89 return p.metadata
90}
91
92
93// IsTextType checks if this is a text proposal.
94func (p *Proposal) IsTextType() bool {
95 return p.Type() == Text
96}
97
98// IsCommunityPoolSpendType checks if this is a community pool spend proposal.
99func (p *Proposal) IsCommunityPoolSpendType() bool {
100 return p.Type() == CommunityPoolSpend
101}
102
103// IsParameterChangeType checks if this is a parameter change proposal.
104func (p *Proposal) IsParameterChangeType() bool {
105 return p.Type() == ParameterChange
106}
107
108// IsProposer checks if the given address is the proposer of this proposal.
109func (p *Proposal) IsProposer(addr address) bool {
110 return p.proposer == addr
111}
112
113// NewProposal creates a new proposal instance with the provided parameters.
114// NewProposal is the main constructor for creating governance proposals.
115// - metadata: proposal title and description
116// - data: type-specific proposal data
117// - proposerAddress: address of the proposal creator
118// - configVersion: governance configuration version
119// - snapshotTime: timestamp for voting weight snapshot lookup
120// - createdAt: creation timestamp
121// - createdHeight: creation block height
122//
123// Returns:
124// - *Proposal: newly created proposal instance
125func NewProposal(
126 proposalID int64,
127 status *ProposalStatus,
128 metadata *ProposalMetadata,
129 data *ProposalData,
130 proposerAddress address,
131 configVersion int64,
132 snapshotTime int64,
133 createdAt int64,
134 createdHeight int64,
135) *Proposal {
136 return &Proposal{
137 id: proposalID,
138 proposer: proposerAddress,
139 status: status,
140 metadata: metadata,
141 data: data,
142 configVersion: configVersion,
143 snapshotTime: snapshotTime,
144 createdAt: createdAt,
145 createdHeight: createdHeight,
146 }
147}
148
149// Clone creates a deep copy of the Proposal.
150func (p *Proposal) Clone() *Proposal {
151 if p == nil {
152 return nil
153 }
154
155 return &Proposal{
156 id: p.id,
157 proposer: p.proposer,
158 configVersion: p.configVersion,
159 status: p.status.Clone(),
160 metadata: p.metadata.Clone(),
161 data: p.data.Clone(),
162 snapshotTime: p.snapshotTime,
163 createdAt: p.createdAt,
164 createdHeight: p.createdHeight,
165 }
166}