getters.gno
8.33 Kb ยท 248 lines
1package governance
2
3import "gno.land/p/nt/ufmt"
4
5// ==================================
6// Store Data Getters
7// ==================================
8
9// GetLatestConfigVersion returns the current config version.
10func GetLatestConfigVersion() int64 {
11 return getImplementation().GetLatestConfigVersion()
12}
13
14// GetCurrentProposalID returns the current proposal ID counter.
15func GetCurrentProposalID() int64 {
16 return getImplementation().GetCurrentProposalID()
17}
18
19// GetMaxSmoothingPeriod returns the maximum smoothing period for delegation history cleanup.
20func GetMaxSmoothingPeriod() int64 {
21 return getImplementation().GetMaxSmoothingPeriod()
22}
23
24// ==================================
25// Config Getters
26// ==================================
27
28// GetLatestConfig returns the latest governance configuration.
29func GetLatestConfig() Config {
30 return getImplementation().GetLatestConfig()
31}
32
33// GetConfig returns a specific governance configuration by version.
34func GetConfig(configVersion int64) (Config, error) {
35 return getImplementation().GetConfig(configVersion)
36}
37
38// ==================================
39// Proposal Getters
40// ==================================
41
42// GetProposalCount returns the total number of proposals.
43func GetProposalCount() int {
44 return getImplementation().GetProposalCount()
45}
46
47// GetProposalIDs returns a paginated list of proposal IDs.
48func GetProposalIDs(offset, count int) []int64 {
49 return getImplementation().GetProposalIDs(offset, count)
50}
51
52// ExistsProposal checks if a proposal exists.
53func ExistsProposal(proposalID int64) bool {
54 return getImplementation().ExistsProposal(proposalID)
55}
56
57// GetProposal returns a proposal by ID.
58// Returns a clone to prevent external modification.
59func GetProposal(proposalID int64) (*Proposal, error) {
60 proposal, err := getImplementation().GetProposal(proposalID)
61 if err != nil {
62 return nil, err
63 }
64 return proposal.Clone(), nil
65}
66
67// GetProposerByProposalId returns the proposer address of a proposal.
68func GetProposerByProposalId(proposalId int64) (address, error) {
69 return getImplementation().GetProposerByProposalId(proposalId)
70}
71
72// GetProposalTypeByProposalId returns the type of a proposal.
73func GetProposalTypeByProposalId(proposalId int64) (ProposalType, error) {
74 return getImplementation().GetProposalTypeByProposalId(proposalId)
75}
76
77// GetYeaByProposalId returns the yes vote weight of a proposal.
78func GetYeaByProposalId(proposalId int64) (int64, error) {
79 return getImplementation().GetYeaByProposalId(proposalId)
80}
81
82// GetNayByProposalId returns the no vote weight of a proposal.
83func GetNayByProposalId(proposalId int64) (int64, error) {
84 return getImplementation().GetNayByProposalId(proposalId)
85}
86
87// GetConfigVersionByProposalId returns the config version used by a proposal.
88func GetConfigVersionByProposalId(proposalId int64) (int64, error) {
89 return getImplementation().GetConfigVersionByProposalId(proposalId)
90}
91
92// GetQuorumAmountByProposalId returns the quorum requirement for a proposal.
93func GetQuorumAmountByProposalId(proposalId int64) (int64, error) {
94 return getImplementation().GetQuorumAmountByProposalId(proposalId)
95}
96
97// GetTitleByProposalId returns the title of a proposal.
98func GetTitleByProposalId(proposalId int64) (string, error) {
99 return getImplementation().GetTitleByProposalId(proposalId)
100}
101
102// GetDescriptionByProposalId returns the description of a proposal.
103func GetDescriptionByProposalId(proposalId int64) (string, error) {
104 return getImplementation().GetDescriptionByProposalId(proposalId)
105}
106
107// GetProposalStatusByProposalId returns the current status of a proposal.
108func GetProposalStatusByProposalId(proposalId int64) (string, error) {
109 return getImplementation().GetProposalStatusByProposalId(proposalId)
110}
111
112// GetProposalCreatedAt returns the creation timestamp of a proposal.
113func GetProposalCreatedAt(proposalId int64) (int64, error) {
114 proposal, err := getImplementation().GetProposal(proposalId)
115 if err != nil {
116 return 0, err
117 }
118
119 return proposal.CreatedAt(), nil
120}
121
122// GetProposalCreatedHeight returns the creation block height of a proposal.
123func GetProposalCreatedHeight(proposalId int64) (int64, error) {
124 proposal, err := getImplementation().GetProposal(proposalId)
125 if err != nil {
126 return 0, err
127 }
128
129 return proposal.createdHeight, nil
130}
131
132// ==================================
133// Vote Getters
134// ==================================
135
136// GetVoteStatus returns the vote status of a proposal.
137//
138// Returns:
139// - quorum: minimum vote weight required for proposal to pass
140// - maxVotingWeight: maximum possible voting weight
141// - yesWeight: total weight of "yes" votes
142// - noWeight: total weight of "no" votes
143func GetVoteStatus(proposalId int64) (quorum, maxVotingWeight, yesWeight, noWeight int64, err error) {
144 return getImplementation().GetVoteStatus(proposalId)
145}
146
147// GetVotingInfoCount returns the number of voters for a proposal.
148func GetVotingInfoCount(proposalID int64) int {
149 return getImplementation().GetVotingInfoCount(proposalID)
150}
151
152// GetVotingInfoAddresses returns a paginated list of voter addresses for a proposal.
153func GetVotingInfoAddresses(proposalID int64, offset, count int) []address {
154 return getImplementation().GetVotingInfoAddresses(proposalID, offset, count)
155}
156
157// ExistsVotingInfo checks if a voting info exists for a user on a proposal.
158func ExistsVotingInfo(proposalID int64, addr address) bool {
159 return getImplementation().ExistsVotingInfo(proposalID, addr)
160}
161
162// GetVotingInfo returns the voting info for a user on a proposal.
163// Returns a clone to prevent external modification.
164func GetVotingInfo(proposalID int64, addr address) (*VotingInfo, error) {
165 votingInfo, err := getImplementation().GetVotingInfo(proposalID, addr)
166 if err != nil {
167 return nil, err
168 }
169 return votingInfo.Clone(), nil
170}
171
172// GetVoteWeight returns the voting weight of an address for a proposal.
173func GetVoteWeight(proposalID int64, addr address) (int64, error) {
174 return getImplementation().GetVoteWeight(proposalID, addr)
175}
176
177// GetVotedHeight returns the block height when an address voted on a proposal.
178func GetVotedHeight(proposalID int64, addr address) (int64, error) {
179 return getImplementation().GetVotedHeight(proposalID, addr)
180}
181
182// GetVotedAt returns the timestamp when an address voted on a proposal.
183func GetVotedAt(proposalID int64, addr address) (int64, error) {
184 return getImplementation().GetVotedAt(proposalID, addr)
185}
186
187// GetProposalCommunityPoolSpendInfo returns the community pool spend info for a proposal.
188func GetProposalCommunityPoolSpendInfo(proposalID int64) (*CommunityPoolSpendInfo, error) {
189 proposal, err := getImplementation().GetProposal(proposalID)
190 if err != nil {
191 return nil, err
192 }
193
194 proposalData := proposal.Data()
195 if proposalData == nil || proposalData.CommunityPoolSpend() == nil {
196 return nil, ufmt.Errorf("proposal is not a community pool spend proposal")
197 }
198
199 return proposalData.CommunityPoolSpend().Clone(), nil
200}
201
202// GetProposalExecutionInfo returns the execution info for a proposal.
203func GetProposalExecutionInfo(proposalID int64) (*ExecutionInfo, error) {
204 proposal, err := getImplementation().GetProposal(proposalID)
205 if err != nil {
206 return nil, err
207 }
208
209 proposalData := proposal.Data()
210
211 if proposalData == nil || proposalData.Execution() == nil {
212 return nil, ufmt.Errorf("proposal is not a parameter change proposal")
213 }
214
215 return proposalData.Execution().Clone(), nil
216}
217
218// ==================================
219// User Proposal Getters
220// ==================================
221
222// GetUserProposalCount returns the number of proposals created by a user.
223func GetUserProposalCount(user address) int {
224 return getImplementation().GetUserProposalCount(user)
225}
226
227// GetUserProposalIDs returns a paginated list of proposal IDs created by a user.
228func GetUserProposalIDs(user address, offset, count int) []int64 {
229 return getImplementation().GetUserProposalIDs(user, offset, count)
230}
231
232// ==================================
233// Active Proposal Query
234// ==================================
235
236// GetOldestActiveProposalSnapshotTime returns the oldest snapshot time among active proposals.
237func GetOldestActiveProposalSnapshotTime() (int64, bool) {
238 return getImplementation().GetOldestActiveProposalSnapshotTime()
239}
240
241// ==================================
242// Voting weight snapshot getters
243// ==================================
244
245// GetCurrentVotingWeightSnapshot returns the current voting weight snapshot.
246func GetCurrentVotingWeightSnapshot() (int64, int64, error) {
247 return getImplementation().GetCurrentVotingWeightSnapshot()
248}