commondao_options.gno
1.85 Kb · 74 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// WithPurpose assigns a purpose to the DAO. Purpose and description
21// together form the DAO's Charter (docs/CONSTITUTION.md :1485).
22func WithPurpose(purpose string) Option {
23 return func(dao *CommonDAO) {
24 dao.purpose = purpose
25 }
26}
27
28// WithDescription assigns a description to the DAO.
29func WithDescription(description string) Option {
30 return func(dao *CommonDAO) {
31 dao.description = description
32 }
33}
34
35// WithAddress assigns a treasury address to the DAO. Hosting realms
36// derive it, typically as a realm sub-identity address
37// (chain.DerivePkgSubAddr) so each DAO owns a distinct account.
38func WithAddress(addr address) Option {
39 return func(dao *CommonDAO) {
40 dao.addr = addr
41 }
42}
43
44// WithParent assigns a parent DAO and registers the DAO as one of the
45// parent's children, keeping both sides of the tree wired in one step.
46func WithParent(p *CommonDAO) Option {
47 return func(dao *CommonDAO) {
48 dao.parent = p
49 if p != nil {
50 p.children.Append(dao)
51 }
52 }
53}
54
55// WithCouncilMember assigns a council member to the DAO.
56func WithCouncilMember(addr address) Option {
57 return func(dao *CommonDAO) {
58 dao.council.Add(addr)
59 }
60}
61
62// WithProposalKind registers a proposal kind on the DAO.
63// It panics when the kind is nil, has an empty name, or its name is
64// already registered.
65//
66// The package ships one concrete kind, ExecutionKind; seed it with
67// WithProposalKind(ExecutionKind{}).
68func WithProposalKind(k ProposalKind) Option {
69 return func(dao *CommonDAO) {
70 if err := dao.RegisterKind(k); err != nil {
71 panic(err)
72 }
73 }
74}