z_readme_filetest.gno
1.43 Kb · 61 lines
1// PKGPATH: gno.land/r/definition/test
2package test
3
4import (
5 "chain/runtime"
6 "errors"
7 "time"
8
9 "gno.land/p/nt/commondao/v0"
10 "gno.land/p/nt/commondao/v0/exts/definition"
11)
12
13var dao = commondao.New()
14
15// CreateMemberProposal creates a new example proposal to add a DAO member.
16func CreateMemberProposal(member address) uint64 {
17 if !member.IsValid() {
18 panic("invalid member address")
19 }
20
21 // Define a function to validate that member doesn't exist within the DAO
22 validate := func() error {
23 if dao.Members().Has(member) {
24 return errors.New("member already exists within the DAO")
25 }
26 return nil
27 }
28
29 // Define a custom tally function that approves proposals without votes
30 tally := func(commondao.VotingContext) (bool, error) {
31 return true, nil
32 }
33
34 // Define an executor to add the new member to the DAO
35 executor := func(realm) error {
36 dao.Members().Add(member)
37 return nil
38 }
39
40 // Create a custom proposal definition for an example proposal type
41 def := definition.MustNew(
42 "Example Proposal",
43 "This is a simple proposal example",
44 definition.WithVotingPeriod(time.Hour*24*2), // 2 days
45 definition.WithTally(tally),
46 definition.WithValidation(validate),
47 definition.WithExecutor(executor),
48 )
49
50 // Create a new proposal
51 p := dao.MustPropose(runtime.PreviousRealm().Address(), def)
52 return p.ID()
53}
54
55func main() {
56 proposalID := CreateMemberProposal("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
57 println(proposalID)
58}
59
60// Output:
61// 1