proposal_text.gno
1.60 Kb · 62 lines
1package commondao
2
3import (
4 "strings"
5 "time"
6
7 "gno.land/p/nt/commondao/v0"
8)
9
10const (
11 maxTextBody = 15_000
12 maxTextTitle = 255
13 minTextVotingPeriod = time.Hour * 24
14)
15
16// newTextPropDefinition creates a new general text proposal definition.
17func newTextPropDefinition(title, body string, votingPeriod time.Duration) textPropDefinition {
18 title = strings.TrimSpace(title)
19 if title == "" {
20 panic("proposal title is empty")
21 }
22
23 if len(title) > maxTextTitle {
24 panic("proposal title is too long, max length is 255 chars")
25 }
26
27 body = strings.TrimSpace(body)
28 if body == "" {
29 panic("proposal body is empty")
30 }
31
32 if len(body) > maxTextBody {
33 panic("proposal body is too long, max length is 15000 chars")
34 }
35
36 if votingPeriod < minTextVotingPeriod {
37 panic("minimum proposal voting period is one day")
38 }
39
40 return textPropDefinition{
41 title: title,
42 body: body,
43 votingPeriod: votingPeriod,
44 }
45}
46
47// textPropDefinition defines a proposal type for general text proposals.
48// These type of proposals are not executable so nothing happens when they pass.
49type textPropDefinition struct {
50 title, body string
51 votingPeriod time.Duration
52}
53
54func (p textPropDefinition) Title() string { return p.title }
55func (p textPropDefinition) Body() string { return p.body }
56func (p textPropDefinition) VotingPeriod() time.Duration { return p.votingPeriod }
57
58// Threshold returns the tally threshold: text proposals are decided by the
59// constitution's default supermajority rule.
60func (textPropDefinition) Threshold() commondao.Threshold {
61 return commondao.ThresholdSupermajority
62}