commondao_options.gno
3.08 Kb ยท 105 lines
1package commondao
2
3// Option configures the CommonDAO.
4type Option func(*CommonDAO)
5
6// WithID assigns a unique identifier to the DAO.
7func WithID(id uint64) Option {
8 return func(dao *CommonDAO) {
9 dao.id = id
10 }
11}
12
13// WithName assigns a name to the DAO.
14func WithName(name string) Option {
15 return func(dao *CommonDAO) {
16 dao.name = name
17 }
18}
19
20// WithDescription assigns a description to the DAO.
21func WithDescription(description string) Option {
22 return func(dao *CommonDAO) {
23 dao.description = description
24 }
25}
26
27// WithSlug assigns a URL slug to the DAO.
28func WithSlug(slug string) Option {
29 return func(dao *CommonDAO) {
30 dao.slug = slug
31 }
32}
33
34// WithParent assigns a parent DAO.
35func WithParent(p *CommonDAO) Option {
36 return func(dao *CommonDAO) {
37 dao.parent = p
38 }
39}
40
41// WithChildren assigns one or more direct child SubDAOs to the DAO.
42func WithChildren(children ...*CommonDAO) Option {
43 return func(dao *CommonDAO) {
44 for _, subDAO := range children {
45 dao.children.Append(subDAO)
46 }
47 }
48}
49
50// WithMember assigns a member to the DAO.
51func WithMember(addr address) Option {
52 return func(dao *CommonDAO) {
53 dao.members.Add(addr)
54 }
55}
56
57// WithMemberStorage assigns a custom member storage to the DAO.
58// An empty member storage is used by default if the specified storage is nil.
59func WithMemberStorage(s MemberStorage) Option {
60 return func(dao *CommonDAO) {
61 if s == nil {
62 s = NewMemberStorage()
63 }
64 dao.members = s
65 }
66}
67
68// WithActiveProposalStorage assigns a custom storage for active proposals.
69// A default empty proposal storage is used when the custopm storage is nil.
70// Custom storage implementations can be used to store proposals in a different location.
71func WithActiveProposalStorage(s ProposalStorage) Option {
72 return func(dao *CommonDAO) {
73 if s == nil {
74 s = NewProposalStorage()
75 }
76 dao.activeProposals = s
77 }
78}
79
80// WithFinishedProposalStorage assigns a custom storage for finished proposals.
81// A default empty proposal storage is used when the custopm storage is nil.
82// Custom storage implementations can be used to store proposals in a different location.
83func WithFinishedProposalStorage(s ProposalStorage) Option {
84 return func(dao *CommonDAO) {
85 if s == nil {
86 s = NewProposalStorage()
87 }
88 dao.finishedProposals = s
89 }
90}
91
92// DisableVotingDeadlineCheck disables voting deadline check when voting or executing proposals.
93// By default CommonDAO checks that the proposal voting deadline has not been met when a new vote
94// is submitted, before registering the vote, and on proposal execution it also checks that voting
95// deadline has been met before executing a proposal.
96//
97// Disabling these checks can be useful in different use cases, moving the responsibility to check
98// the deadline to the commondao package caller. One example where this could be useful would be
99// in case where 100% or a required number of members of a DAO vote on a proposal and reach consensus
100// before the deadline is met, otherwise proposal would have to wait until deadline to be executed.
101func DisableVotingDeadlineCheck() Option {
102 return func(dao *CommonDAO) {
103 dao.disableVotingDeadlineCheck = true
104 }
105}