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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

render.gno

1.42 Kb · 65 lines
 1package pado
 2
 3import (
 4	"strconv"
 5	"strings"
 6)
 7
 8// Render lists the launches in this realm. Quote figures are ugnot.
 9func Render(path string) string {
10	if path != "" && path != "/" {
11		return "> [!WARNING]\n> Path not found"
12	}
13	var b strings.Builder
14	b.WriteString("# pado\n\n")
15	b.WriteString("No trade tax. Each launch keeps its own raise.\n\n")
16	if owner.IsValid() {
17		b.WriteString("* **Owner**: ")
18		b.WriteString(owner.String())
19		b.WriteString("\n")
20	}
21	b.WriteString("* **Realm**: ")
22	b.WriteString(padAddr.String())
23	b.WriteString("\n\n")
24	n := 0
25	launches.Iterate("", "", func(key string, value any) bool {
26		l, ok := value.(*launch)
27		if !ok || l == nil {
28			return false
29		}
30		n++
31		b.WriteString("## ")
32		b.WriteString(esc(l.symbol))
33		b.WriteString("\n\n")
34		b.WriteString("* **id**: ")
35		b.WriteString(esc(key))
36		b.WriteString("\n* **raise**: ")
37		b.WriteString(strconv.FormatInt(l.raiseUgnot, 10))
38		b.WriteString("\n* **raised**: ")
39		b.WriteString(strconv.FormatInt(l.raisedUgnot, 10))
40		b.WriteString("\n* **pool**: ")
41		b.WriteString(strconv.FormatInt(l.poolUgnot, 10))
42		b.WriteString("\n* **status**: ")
43		b.WriteString(strconv.Itoa(l.status))
44		b.WriteString("\n\n")
45		return false
46	})
47	if n == 0 {
48		b.WriteString("No launches.\n")
49	}
50	return b.String()
51}
52
53func esc(s string) string {
54	r := strings.NewReplacer(
55		"\n", " ",
56		"\r", " ",
57		"#", "",
58		"[", "",
59		"]", "",
60		"<", "",
61		">", "",
62		"|", "/",
63	)
64	return r.Replace(s)
65}