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