render.gno
2.75 Kb · 80 lines
1package params
2
3import (
4 "gno.land/p/moul/md/v0"
5 "gno.land/p/moul/mdtable/v0"
6 "gno.land/p/nt/ufmt/v0"
7)
8
9// Render shows who, other than GovDAO, may currently write a chain parameter.
10//
11// This realm had no Render, so the only way to see a delegation was to know it
12// existed and query for it by name. That is the wrong shape for state that
13// grants a capability: someone auditing the chain should be able to see, in one
14// place, whether any parameter is delegated and to whom.
15//
16// Values are rendered without escaping, which is safe here because none of them
17// is free-form. A delegate path has passed assertDelegatePath, which permits
18// only lowercase letters, digits and a few separators; the addresses come from
19// the parameter itself, which the chain validates as bech32; and the valset
20// realm is a compile-time constant.
21func Render(path string) string {
22 out := md.H1("Chain parameter delegation")
23 out += md.Paragraph(
24 "Chain parameters are written by GovDAO proposal. A parameter may also " +
25 "be delegated to one other realm, which can then manage it without a " +
26 "vote. GovDAO keeps full control of every parameter and can withdraw " +
27 "a delegation at any time.",
28 )
29
30 out += md.HorizontalRule()
31 out += md.H2("run_submitters")
32 out += md.Paragraph("Addresses allowed to send MsgRun, which runs code the sender supplies.")
33
34 mgr := RunSubmittersManager()
35 table := mdtable.Table{Headers: []string{"", ""}}
36 if mgr == "" {
37 table.Append([]string{md.Bold("Delegated to"), "nobody, only GovDAO may change it"})
38 } else {
39 table.Append([]string{md.Bold("Delegated to"), md.InlineCode(mgr)})
40 }
41
42 listed := GetRunSubmitters()
43 table.Append([]string{md.Bold("Addresses allowed"), ufmt.Sprintf("%d", len(listed))})
44 out += table.String()
45
46 if mgr != "" {
47 // Which entries the delegate may remove again. Anything it did not add
48 // is GovDAO's to remove, including whatever the chain started with.
49 granted := 0
50 for _, a := range listed {
51 if RunSubmittersGrantedBy(address(a)) {
52 granted++
53 }
54 }
55 out += md.Paragraph(ufmt.Sprintf(
56 "%d of those were added by the delegate, and are the only ones it may remove.",
57 granted))
58 }
59
60 if len(listed) > 0 {
61 items := make([]string, 0, len(listed))
62 for _, a := range listed {
63 items = append(items, md.InlineCode(a))
64 }
65 out += md.BulletList(items)
66 }
67
68 out += md.HorizontalRule()
69 out += md.H2("node:valset")
70 out += md.Paragraph(
71 "Validator set parameters are written by one realm, fixed in this " +
72 "realm's source. Unlike a delegation this cannot be repointed by a " +
73 "vote, and GovDAO cannot write these keys itself.",
74 )
75 vtable := mdtable.Table{Headers: []string{"", ""}}
76 vtable.Append([]string{md.Bold("Writable only by"), md.InlineCode(valsetAuthorizedRealm)})
77 out += vtable.String()
78
79 return out
80}