guestbook.gno
0.68 Kb · 31 lines
1package guestbook
2
3import "strconv"
4
5var entries []string
6
7// Sign adds a message to the on-chain guestbook.
8func Sign(cur realm, msg string) {
9 if msg == "" {
10 panic("message required")
11 }
12 if len(msg) > 200 {
13 panic("message too long")
14 }
15 entries = append(entries, msg)
16}
17
18// Render draws the public guestbook page.
19func Render(path string) string {
20 out := "# Guestbook\n\n"
21 out += "A simple on-chain guestbook. Call `Sign(\"your message\")` to add an entry.\n\n"
22 out += "## Entries (" + strconv.Itoa(len(entries)) + ")\n\n"
23 if len(entries) == 0 {
24 out += "_No entries yet._\n"
25 return out
26 }
27 for i := len(entries) - 1; i >= 0; i-- {
28 out += "- " + entries[i] + "\n"
29 }
30 return out
31}