Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

utils.gno

3.99 Kb Β· 86 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	// Safe here only because cur is THIS realm's own, minted by this crossing
39	// function. CallerID is not the entry-point gate: copied somewhere that
40	// passes a realm it received from elsewhere, this becomes the donation bug
41	// the DAO entry points exist to refuse. If you need the gate, go through
42	// Propose/Vote/Execute.
43	id := daoPrivate.CallerID(daoPrivate, cur)
44	daoPrivate.Members.AddMember(id, make([]string, 0))
45}
46
47// Creates a Proposal to create a new blog post.
48// This demonstrates the custom resource functionality of the DAO.
49// Parameters:
50//   - title: The title of the blog post
51//   - content: The content of the blog post
52func ProposeNewPost(cur realm, title, content string) {
53	// Calling the custom action
54	action := NewPostAction(title, content)
55
56	req := daokit.ProposalRequest{
57		Title:       ufmt.Sprintf("Create new blog post: %s", title),
58		Description: ufmt.Sprintf("This proposal will create a new blog post with title '%s' and content: %s", title, content),
59		Action:      action,
60	}
61	Propose(cur, req)
62}
63
64func renderDemo() string {
65	s := ""
66	s += "# πŸ”§ Custom Resource Demo\n\n"
67	s += "This showcases how to extend your DAO with custom actions.\n\n"
68	s += "## ℹ️ How it Works\n\n"
69	s += "1. **Join the DAO** using the " + md.Link("AddMember", txlink.Call("AddMember")) + " function.\n\n"
70	s += "2. **Create a blog post Proposal** using " + md.Link("ProposeNewPost", txlink.Call("ProposeNewPost")) + " function with these parameters:\n\n"
71	s += "- `title`: The title of the blog post\n"
72	s += "- `content`: The content of the blog post\n\n"
73	s += "3. " + md.Link("Vote", txlink.Call("Vote")) + " on proposals using their ID.\n\n"
74	s += "4. " + md.Link("Execute", txlink.Call("Execute")) + " proposals that have passed (met the required voting conditions).\n\n"
75	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"
76	s += "## πŸ“‹ Available Actions\n\n"
77	s += "### Member Management\n"
78	s += "- " + md.Link("πŸ”— Add Yourself as Member", txlink.Call("AddMember")) + " - Join the DAO to participate in governance\n"
79	s += "### Custom Resource Actions\n"
80	s += "- " + md.Link("πŸ”— Propose New Blog Post", txlink.Call("ProposeNewPost")) + " - Create a proposal to publish a new blog post (demonstrates custom resource)\n\n"
81	s += "### Other Demos\n"
82	s += "- " + md.Link("πŸ”— Simple DAO Demo", "/r/samcrew/daodemo/simple_dao") + " - Basic DAO functionality\n"
83	s += "- " + md.Link("πŸ”— Custom Condition Demo", "/r/samcrew/daodemo/custom_condition") + " - Custom governance conditions\n\n"
84	s += "*This is a demonstration DAO built with gno.land and daokit*"
85	return s
86}