Search Apps Documentation Source Content File Folder Download Copy Actions Download

utils.gno

3.65 Kb Β· 81 lines
 1package custom_resource
 2
 3import (
 4	"gno.land/p/mason/md"
 5	"gno.land/p/moul/txlink"
 6	"gno.land/p/nt/ufmt/v0"
 7	"gno.land/p/samcrew/daokit"
 8)
 9
10// initBlogProposals creates initial blog post proposals to demonstrate custom resource functionality
11func initBlogProposals() {
12	blogPosts := []struct {
13		title    string
14		content  string
15		proposer string
16	}{
17		{"Welcome to our DAO Blog", "This is our first blog post created through DAO governance!", "g1demo1234567890abcdefghijklmnopqrstuvw1"},
18		{"Custom Resources in Action", "This post demonstrates how custom resources work in daokit. Any custom action can be proposed and voted on!", "g1demo1234567890abcdefghijklmnopqrstuvw2"},
19		{"Community Updates", "Regular updates from our DAO community will be posted here through democratic proposals.", "g1demo1234567890abcdefghijklmnopqrstuvw3"},
20	}
21
22	for _, post := range blogPosts {
23		// Calling the custom action
24		action := NewPostAction(post.title, post.content)
25
26		req := daokit.ProposalRequest{
27			Title:       ufmt.Sprintf("Create blog post: %s", post.title),
28			Description: ufmt.Sprintf("This proposal will create a new blog post."),
29			Action:      action,
30		}
31		daoPrivate.Core.Propose(post.proposer, req)
32	}
33}
34
35// Bypass limitation by adding yourself to the DAO.
36// It is necessary to be part of the DAO to create a Proposal.
37func AddMember(cur realm) {
38	id := daoPrivate.CallerID()
39	daoPrivate.Members.AddMember(id, make([]string, 0))
40}
41
42// Creates a Proposal to create a new blog post.
43// This demonstrates the custom resource functionality of the DAO.
44// Parameters:
45//   - title: The title of the blog post
46//   - content: The content of the blog post
47func ProposeNewPost(cur realm, title, content string) {
48	// Calling the custom action
49	action := NewPostAction(title, content)
50
51	req := daokit.ProposalRequest{
52		Title:       ufmt.Sprintf("Create new blog post: %s", title),
53		Description: ufmt.Sprintf("This proposal will create a new blog post with title '%s' and content: %s", title, content),
54		Action:      action,
55	}
56	Propose(cur, req)
57}
58
59func renderDemo() string {
60	s := ""
61	s += "# πŸ”§ Custom Resource Demo\n\n"
62	s += "This showcases how to extend your DAO with custom actions.\n\n"
63	s += "## ℹ️ How it Works\n\n"
64	s += "1. **Join the DAO** using the " + md.Link("AddMember", txlink.Call("AddMember")) + " function.\n\n"
65	s += "2. **Create a blog post Proposal** using " + md.Link("ProposeNewPost", txlink.Call("ProposeNewPost")) + " function with these parameters:\n\n"
66	s += "- `title`: The title of the blog post\n"
67	s += "- `content`: The content of the blog post\n\n"
68	s += "3. " + md.Link("Vote", txlink.Call("Vote")) + " on proposals using their ID.\n\n"
69	s += "4. " + md.Link("Execute", txlink.Call("Execute")) + " proposals that have passed (met the required voting conditions).\n\n"
70	s += "   πŸ“ **Note**: Only proposals that have met the governance conditions can be executed. You need at least **10% of member approval** to execute a proposal.\n\n"
71	s += "## πŸ“‹ Available Actions\n\n"
72	s += "### Member Management\n"
73	s += "- " + md.Link("πŸ”— Add Yourself as Member", txlink.Call("AddMember")) + " - Join the DAO to participate in governance\n"
74	s += "### Custom Resource Actions\n"
75	s += "- " + md.Link("πŸ”— Propose New Blog Post", txlink.Call("ProposeNewPost")) + " - Create a proposal to publish a new blog post (demonstrates custom resource)\n\n"
76	s += "### Other Demos\n"
77	s += "- " + md.Link("πŸ”— Simple DAO Demo", "/r/samcrew/daodemo/simple_dao") + " - Basic DAO functionality\n"
78	s += "- " + md.Link("πŸ”— Custom Condition Demo", "/r/samcrew/daodemo/custom_condition") + " - Custom governance conditions\n\n"
79	s += "*This is a demonstration DAO built with gno.land and daokit*"
80	return s
81}