proposal_data.gno
5.75 Kb ยท 203 lines
1package governance
2
3import (
4 "strings"
5)
6
7// ProposalMetadata contains descriptive information about a proposal.
8// This includes the title and description that are displayed to voters.
9type ProposalMetadata struct {
10 title string // Proposal title (max 255 characters)
11 description string // Detailed proposal description (max 10,000 characters)
12}
13
14// Title returns the proposal title.
15//
16// Returns:
17// - string: proposal title
18func (p *ProposalMetadata) Title() string {
19 return p.title
20}
21
22// Description returns the proposal description.
23//
24// Returns:
25// - string: proposal description
26func (p *ProposalMetadata) Description() string {
27 return p.description
28}
29
30// NewProposalMetadata creates a new proposal metadata instance with trimmed input.
31//
32// Parameters:
33// - title: proposal title
34// - description: proposal description
35//
36// Returns:
37// - *ProposalMetadata: new metadata instance with trimmed whitespace
38func NewProposalMetadata(title string, description string) *ProposalMetadata {
39 return &ProposalMetadata{
40 title: strings.TrimSpace(title),
41 description: strings.TrimSpace(description),
42 }
43}
44
45// ProposalData contains the type-specific data for a proposal.
46// This structure holds different data depending on the proposal type.
47type ProposalData struct {
48 proposalType ProposalType // Type of proposal (Text, CommunityPoolSpend, ParameterChange)
49 communityPoolSpend *CommunityPoolSpendInfo // Data for community pool spending proposals
50 execution *ExecutionInfo // Data for parameter change proposals
51}
52
53// ProposalType returns the type of this proposal.
54//
55// Returns:
56// - ProposalType: the proposal type
57func (p *ProposalData) ProposalType() ProposalType {
58 return p.proposalType
59}
60
61// CommunityPoolSpend returns the community pool spending information.
62//
63// Returns:
64// - *CommunityPoolSpendInfo: community pool spending details
65func (p *ProposalData) CommunityPoolSpend() *CommunityPoolSpendInfo {
66 return p.communityPoolSpend
67}
68
69// Execution returns the execution information for parameter changes.
70//
71// Returns:
72// - *ExecutionInfo: parameter change execution details
73func (p *ProposalData) Execution() *ExecutionInfo {
74 return p.execution
75}
76
77// NewProposalData creates a new proposal data instance with the specified components.
78//
79// Parameters:
80// - proposalType: type of the proposal
81// - communityPoolSpend: community pool spending information
82// - execution: parameter change execution information
83//
84// Returns:
85// - *ProposalData: new proposal data instance
86func NewProposalData(proposalType ProposalType, communityPoolSpend *CommunityPoolSpendInfo, execution *ExecutionInfo) *ProposalData {
87 return &ProposalData{
88 proposalType: proposalType,
89 communityPoolSpend: communityPoolSpend,
90 execution: execution,
91 }
92}
93
94// CommunityPoolSpendInfo contains information for community pool spending proposals.
95type CommunityPoolSpendInfo struct {
96 to address // Recipient address for token transfer
97 tokenPath string // Path of the token to transfer
98 amount int64 // Amount of tokens to transfer
99}
100
101func NewCommunityPoolSpendInfo(to address, tokenPath string, amount int64) *CommunityPoolSpendInfo {
102 return &CommunityPoolSpendInfo{
103 to: to,
104 tokenPath: tokenPath,
105 amount: amount,
106 }
107}
108
109/* Getter methods */
110func (i *CommunityPoolSpendInfo) To() address { return i.to }
111func (i *CommunityPoolSpendInfo) TokenPath() string { return i.tokenPath }
112func (i *CommunityPoolSpendInfo) Amount() int64 { return i.amount }
113
114// ExecutionInfo contains information for parameter change execution.
115// Messages are encoded strings that specify function calls and parameters.
116type ExecutionInfo struct {
117 num int64 // Number of parameter changes to execute
118 msgs []string // Execution messages separated by messageSeparator (*GOV*)
119}
120
121func NewExecutionInfo(num int64, msgs []string) *ExecutionInfo {
122 return &ExecutionInfo{
123 num: num,
124 msgs: msgs,
125 }
126}
127
128/* Getter methods */
129func (i *ExecutionInfo) Num() int64 { return i.num }
130func (i *ExecutionInfo) Msgs() []string { return i.msgs }
131
132// ParameterChangeInfo represents a single parameter change to be executed.
133type ParameterChangeInfo struct {
134 pkgPath string // Package path of the target contract
135 function string // Function name to call
136 params []string // Parameters to pass to the function
137}
138
139func NewParameterChangeInfo(pkgPath string, function string, params []string) ParameterChangeInfo {
140 return ParameterChangeInfo{
141 pkgPath: pkgPath,
142 function: function,
143 params: params,
144 }
145}
146
147/* Getter methods */
148func (i *ParameterChangeInfo) PkgPath() string { return i.pkgPath }
149func (i *ParameterChangeInfo) Function() string { return i.function }
150func (i *ParameterChangeInfo) Params() []string { return i.params }
151
152// Clone creates a deep copy of the ProposalMetadata.
153func (p *ProposalMetadata) Clone() *ProposalMetadata {
154 if p == nil {
155 return nil
156 }
157
158 return &ProposalMetadata{
159 title: p.title,
160 description: p.description,
161 }
162}
163
164// Clone creates a deep copy of the CommunityPoolSpendInfo.
165func (i *CommunityPoolSpendInfo) Clone() *CommunityPoolSpendInfo {
166 if i == nil {
167 return nil
168 }
169
170 return &CommunityPoolSpendInfo{
171 to: i.to,
172 tokenPath: i.tokenPath,
173 amount: i.amount,
174 }
175}
176
177// Clone creates a deep copy of the ExecutionInfo.
178func (i *ExecutionInfo) Clone() *ExecutionInfo {
179 if i == nil {
180 return nil
181 }
182
183 clonedMsgs := make([]string, len(i.msgs))
184 copy(clonedMsgs, i.msgs)
185
186 return &ExecutionInfo{
187 num: i.num,
188 msgs: clonedMsgs,
189 }
190}
191
192// Clone creates a deep copy of the ProposalData.
193func (p *ProposalData) Clone() *ProposalData {
194 if p == nil {
195 return nil
196 }
197
198 return &ProposalData{
199 proposalType: p.proposalType,
200 communityPoolSpend: p.communityPoolSpend.Clone(),
201 execution: p.execution.Clone(),
202 }
203}