getters.gno
13.29 Kb · 379 lines
1package governance
2
3import (
4 rotree "gno.land/p/nt/bptree/rotree/v0"
5)
6
7// ==================================
8// Store Data Getters
9// ==================================
10
11// GetLatestConfigVersion returns the current governance configuration version.
12//
13// Returns:
14// - int64: latest configuration version stored by governance
15func GetLatestConfigVersion() int64 {
16 return getImplementation().GetLatestConfigVersion()
17}
18
19// GetCurrentProposalID returns the current proposal ID counter.
20//
21// Returns:
22// - int64: current proposal ID counter used for newly created proposals
23func GetCurrentProposalID() int64 {
24 return getImplementation().GetCurrentProposalID()
25}
26
27// GetMaxSmoothingPeriod returns the maximum smoothing period for delegation history cleanup.
28//
29// Returns:
30// - int64: maximum permitted smoothing period in seconds
31func GetMaxSmoothingPeriod() int64 {
32 return getImplementation().GetMaxSmoothingPeriod()
33}
34
35// ==================================
36// Config Getters
37// ==================================
38
39// GetLatestConfig returns the latest governance configuration.
40//
41// Returns:
42// - Config: latest stored configuration for the current version
43// - error: nil on success, or an error when the current configuration is missing
44func GetLatestConfig() (Config, error) {
45 return getImplementation().GetLatestConfig()
46}
47
48// GetConfig returns a specific governance configuration by version.
49//
50// Parameters:
51// - configVersion: configuration version to retrieve
52//
53// Returns:
54// - Config: configuration stored under configVersion
55// - error: nil on success, or an error when configVersion is not found
56func GetConfig(configVersion int64) (Config, error) {
57 return getImplementation().GetConfig(configVersion)
58}
59
60// ==================================
61// Proposal Getters
62// ==================================
63
64// GetProposals returns a read-only view of every proposal, keyed by the decimal
65// string form of the proposal ID. Callers paginate it themselves through
66// IterateByOffset. Reading an entry yields a clone, so the view cannot mutate
67// realm state.
68//
69// Returns:
70// - *rotree.ReadOnlyTree: read-only proposal tree keyed by decimal proposal ID
71func GetProposals() *rotree.ReadOnlyTree {
72 return getImplementation().GetProposals()
73}
74
75// ExistsProposal checks whether a proposal is stored.
76//
77// Parameters:
78// - proposalID: proposal identifier to look up
79//
80// Returns:
81// - bool: true when proposalID is stored, otherwise false
82func ExistsProposal(proposalID int64) bool {
83 return getImplementation().ExistsProposal(proposalID)
84}
85
86// GetProposerByProposalId returns the proposer address of a proposal.
87//
88// Parameters:
89// - proposalId: proposal identifier to look up
90//
91// Returns:
92// - address: address that submitted the proposal
93// - error: nil on success, or an error when the proposal does not exist
94func GetProposerByProposalId(proposalId int64) (address, error) {
95 return getImplementation().GetProposerByProposalId(proposalId)
96}
97
98// GetProposalTypeByProposalId returns the type of a proposal.
99//
100// Parameters:
101// - proposalId: proposal identifier to look up
102//
103// Returns:
104// - ProposalType: type recorded for the proposal
105// - error: nil on success, or an error when the proposal does not exist
106func GetProposalTypeByProposalId(proposalId int64) (ProposalType, error) {
107 return getImplementation().GetProposalTypeByProposalId(proposalId)
108}
109
110// GetYeaByProposalId returns the yes vote weight of a proposal.
111//
112// Parameters:
113// - proposalId: proposal identifier to inspect
114//
115// Returns:
116// - int64: total voting weight recorded for yes votes
117// - error: nil on success, or an error when the proposal does not exist
118func GetYeaByProposalId(proposalId int64) (int64, error) {
119 return getImplementation().GetYeaByProposalId(proposalId)
120}
121
122// GetNayByProposalId returns the no vote weight of a proposal.
123//
124// Parameters:
125// - proposalId: proposal identifier to inspect
126//
127// Returns:
128// - int64: total voting weight recorded for no votes
129// - error: nil on success, or an error when the proposal does not exist
130func GetNayByProposalId(proposalId int64) (int64, error) {
131 return getImplementation().GetNayByProposalId(proposalId)
132}
133
134// GetConfigVersionByProposalId returns the config version used by a proposal.
135//
136// Parameters:
137// - proposalId: proposal identifier to inspect
138//
139// Returns:
140// - int64: governance configuration version captured by the proposal
141// - error: nil on success, or an error when the proposal does not exist
142func GetConfigVersionByProposalId(proposalId int64) (int64, error) {
143 return getImplementation().GetConfigVersionByProposalId(proposalId)
144}
145
146// GetQuorumAmountByProposalId returns the quorum requirement for a proposal.
147//
148// Parameters:
149// - proposalId: proposal identifier to inspect
150//
151// Returns:
152// - int64: minimum voting weight required for the proposal's quorum
153// - error: nil on success, or an error when the proposal does not exist
154func GetQuorumAmountByProposalId(proposalId int64) (int64, error) {
155 return getImplementation().GetQuorumAmountByProposalId(proposalId)
156}
157
158// GetTitleByProposalId returns the title of a proposal.
159//
160// Parameters:
161// - proposalId: proposal identifier to inspect
162//
163// Returns:
164// - string: proposal title
165// - error: nil on success, or an error when the proposal does not exist
166func GetTitleByProposalId(proposalId int64) (string, error) {
167 return getImplementation().GetTitleByProposalId(proposalId)
168}
169
170// GetDescriptionByProposalId returns the description of a proposal.
171//
172// Parameters:
173// - proposalId: proposal identifier to inspect
174//
175// Returns:
176// - string: proposal description
177// - error: nil on success, or an error when the proposal does not exist
178func GetDescriptionByProposalId(proposalId int64) (string, error) {
179 return getImplementation().GetDescriptionByProposalId(proposalId)
180}
181
182// GetProposalStatusByProposalId returns the current status of a proposal.
183//
184// Parameters:
185// - proposalId: proposal identifier to inspect
186//
187// Returns:
188// - string: status computed from the proposal and the current Unix time
189// - error: nil on success, or an error when the proposal does not exist
190func GetProposalStatusByProposalId(proposalId int64) (string, error) {
191 return getImplementation().GetProposalStatusByProposalId(proposalId)
192}
193
194// GetProposalCreatedAt returns the creation timestamp of a proposal.
195//
196// Parameters:
197// - proposalId: proposal identifier to look up
198//
199// Returns:
200// - int64: Unix timestamp at which the proposal was created
201// - error: nil on success, or an error when the proposal does not exist
202func GetProposalCreatedAt(proposalId int64) (int64, error) {
203 return getImplementation().GetProposalCreatedAt(proposalId)
204}
205
206// GetProposalCreatedHeight returns the creation block height of a proposal.
207//
208// Parameters:
209// - proposalId: proposal identifier to look up
210//
211// Returns:
212// - int64: block height at which the proposal was created
213// - error: nil on success, or an error when the proposal does not exist
214func GetProposalCreatedHeight(proposalId int64) (int64, error) {
215 return getImplementation().GetProposalCreatedHeight(proposalId)
216}
217
218// ==================================
219// Vote Getters
220// ==================================
221
222// GetVoteStatus returns the vote status of a proposal.
223//
224// Parameters:
225// - proposalId: proposal identifier to inspect
226//
227// Returns:
228// - quorum: minimum vote weight required for the proposal to pass
229// - maxVotingWeight: maximum possible voting weight recorded for the proposal
230// - yesWeight: total weight of yes votes
231// - noWeight: total weight of no votes
232// - err: nil on success, or an error when the proposal does not exist
233func GetVoteStatus(proposalId int64) (quorum, maxVotingWeight, yesWeight, noWeight int64, err error) {
234 return getImplementation().GetVoteStatus(proposalId)
235}
236
237// GetVotingInfos returns a read-only view of a proposal's value-backed voting
238// infos, keyed by voter address. Existing proposals have an empty view before
239// the first vote; nil is returned only when the stored voting-info tree is absent.
240//
241// Parameters:
242// - proposalID: proposal identifier whose voting information is requested
243//
244// Returns:
245// - *rotree.ReadOnlyTree: read-only voting-info tree keyed by voter address, or nil when no tree is stored
246func GetVotingInfos(proposalID int64) *rotree.ReadOnlyTree {
247 return getImplementation().GetVotingInfos(proposalID)
248}
249
250// ExistsVotingInfo checks whether voting information exists for a user on a proposal.
251//
252// Parameters:
253// - proposalID: proposal identifier to inspect
254// - addr: voter address to look up within proposalID
255//
256// Returns:
257// - bool: true when voting information exists for the proposal and address
258func ExistsVotingInfo(proposalID int64, addr address) bool {
259 return getImplementation().ExistsVotingInfo(proposalID, addr)
260}
261
262// GetVoteWeight returns the voting weight of an address for a proposal.
263//
264// Parameters:
265// - proposalID: proposal identifier to inspect
266// - addr: voter address whose recorded vote weight is requested
267//
268// Returns:
269// - int64: weight recorded for addr's vote
270// - error: nil on success, or an error when no voting information exists for the proposal and address
271func GetVoteWeight(proposalID int64, addr address) (int64, error) {
272 return getImplementation().GetVoteWeight(proposalID, addr)
273}
274
275// GetVotedHeight returns the block height when an address voted on a proposal.
276//
277// Parameters:
278// - proposalID: proposal identifier to inspect
279// - addr: voter address whose vote height is requested
280//
281// Returns:
282// - int64: block height recorded for addr's vote
283// - error: nil on success, or an error when no voting information exists for the proposal and address
284func GetVotedHeight(proposalID int64, addr address) (int64, error) {
285 return getImplementation().GetVotedHeight(proposalID, addr)
286}
287
288// GetVotedAt returns the timestamp when an address voted on a proposal.
289//
290// Parameters:
291// - proposalID: proposal identifier to inspect
292// - addr: voter address whose vote timestamp is requested
293//
294// Returns:
295// - int64: Unix timestamp recorded for addr's vote
296// - error: nil on success, or an error when no voting information exists for the proposal and address
297func GetVotedAt(proposalID int64, addr address) (int64, error) {
298 return getImplementation().GetVotedAt(proposalID, addr)
299}
300
301// GetProposalCommunityPoolSpendInfo returns a cloned copy of the community pool spend info for a proposal.
302//
303// Parameters:
304// - proposalID: proposal identifier to inspect
305//
306// Returns:
307// - *CommunityPoolSpendInfo: cloned community-pool spend details, or nil when an error occurs
308// - error: nil on success, or an error when the proposal is missing or has no spend data
309func GetProposalCommunityPoolSpendInfo(proposalID int64) (*CommunityPoolSpendInfo, error) {
310 info, err := getImplementation().GetProposalCommunityPoolSpendInfo(proposalID)
311 if err != nil {
312 return nil, err
313 }
314
315 return info.Clone(), nil
316}
317
318// GetProposalExecutionInfo returns a cloned copy of the execution info for a proposal.
319//
320// Parameters:
321// - proposalID: proposal identifier to inspect
322//
323// Returns:
324// - *ExecutionInfo: cloned parameter-change execution messages and count, or nil when an error occurs
325// - error: nil on success, or an error when the proposal is missing or has no execution data
326func GetProposalExecutionInfo(proposalID int64) (*ExecutionInfo, error) {
327 info, err := getImplementation().GetProposalExecutionInfo(proposalID)
328 if err != nil {
329 return nil, err
330 }
331
332 return info.Clone(), nil
333}
334
335// ==================================
336// User Proposal Getters
337// ==================================
338
339// GetUserProposals returns a read-only view of the proposals created per user,
340// keyed by creator address with the creator's proposal IDs as the value.
341// Reading an entry yields a copy of the ID slice, so the view cannot mutate
342// realm state.
343//
344// Returns:
345// - *rotree.ReadOnlyTree: read-only user-proposal tree keyed by creator address
346func GetUserProposals() *rotree.ReadOnlyTree {
347 return getImplementation().GetUserProposals()
348}
349
350// ==================================
351// Active Proposal Query
352// ==================================
353
354// GetOldestActiveProposalSnapshotTime returns the oldest active proposal's
355// timestamp anchor. An empty index returns no active proposal; a stale or
356// missing first entry returns an error so cleanup cannot silently skip it.
357//
358// Returns:
359// - int64: snapshot timestamp of the oldest active proposal, or zero when the index is empty or an error occurs
360// - bool: true when an active proposal was found at the oldest index entry, otherwise false
361// - error: nil for an empty index or active entry, or an error when the entry is missing or inactive
362func GetOldestActiveProposalSnapshotTime() (int64, bool, error) {
363 return getImplementation().GetOldestActiveProposalSnapshotTime()
364}
365
366// ==================================
367// Voting weight snapshot getters
368// ==================================
369
370// GetCurrentVotingWeightSnapshot returns the current total voting weight and its
371// timestamp anchor computed with the configured smoothing duration.
372//
373// Returns:
374// - int64: total voting weight averaged over the configured smoothing window
375// - int64: Unix timestamp used as the snapshot history anchor
376// - error: nil on success, or an error when the current configuration or snapshot data cannot be retrieved
377func GetCurrentVotingWeightSnapshot() (int64, int64, error) {
378 return getImplementation().GetCurrentVotingWeightSnapshot()
379}