Transaction
76F7EDEBB19C9C…EB96A645B38E
Block 221,041 · index 0 · indexed
Summary
- Hash
- 76F7EDEBB19C9CBB81BC8D29C7C5A7C4E7E37E9CF2A09E691496EB96A645B38E
- Block
- 221,041
- Size
- 30079 bytes
- Gas used
- 29,374,465 / 53,447,400
- Fee
- 534474ugnot
- Status
- success
Messages
- Attached funds
- 12000000ugnot
- Package
- gno.land/r/moul/home
Arguments · 15
- #1home
- #2README.md
- #3# `gno.land/r/moul/home` The realm behind **https://gno.land/u/moul**. A profile page whose content is data, not code: update a paragraph with one small transaction instead of redeploying a realm. ## Why this one has no `/vN` It is the only contract in this repo at an unversioned path, and that is forced, not a slip. gnoweb builds a user profile by calling `Render("")` on the realm at the **exact** path `/r/<username>/home` and embedding the result as the page body ([`gno.land/pkg/gnoweb/handler_http.go`][handler], `GetUserView`). That lookup does no version resolution, so `gno.land/r/moul/home/v0` would never be found. The bare path *is* the interface with gnoweb. Versioning moves inside instead: content lives in slots (below), and the code can be replaced in place because the package is `private`. This is also why `gnopm bump` refuses this package: it looks for a trailing `/vN` on the module line to increment and there is none. The module line stays bare, `gnopm status` and `gnopm verify` accept it, and only `bump` is off the table. A compatibility change here is a redeploy of the same path, not a new version. ### What it replaces: `gno.land/r/moul/home/v0` This directory used to hold a different realm: a hand-maintained dashboard with a todo list, a status string and a meme URL, its state mutable only by the admin and its *shape* only by redeploying. It never reached any network (`contracts.json` had it `uploaded: false` everywhere), so nothing on chain is being replaced, only the source. That version is not deleted, it is **pinned to history** in `gnomod.lock` the way `AGENTS.md` prescribes for a superseded version: ```toml [[module]] module = "gno.land/r/moul/home/v0" source = { commit = "4f2df83869b80470eb81c48a82fdbe82256b8113", dir = "r/moul/home" } ``` So it keeps resolving for anything that imports it, `gnopm sync` materializes it under `.gnopm/`, and it is still linted and tested from there. Read the code at [`r/moul/home` @ 4f2df83][v0], the last commit where this directory held it. [handler]: https://github.com/gnolang/gno/blob/master/gno.land/pkg/gnoweb/handler_http.go [v0]: https://github.com/moul/gno-contracts/tree/4f2df83869b80470eb81c48a82fdbe82256b8113/r/moul/home ## Slots The page is assembled from **slots**: named markdown fragments in an avl tree. | function | what it does | | --- | --- | | `Set(cur, slug, body)` | create or replace one slot, the ordinary update | | `Append(cur, slug, body)` | append, for a body too large for one transaction | | `Delete(cur, slug)` | remove a slot | | `Get(slug)` | read one body | | `Manifest()` | `slug⇥rev⇥len⇥sha256` per slot, the diff surface | | `Revision()` | total writes accepted, so a client can tell "nothing moved" | Writes are restricted to `g1manfred47kzduec920z88wfr64ylksmdcedlf5`. A slug is 1–64 bytes of `[a-z0-9._-]`. No `':'`, so a slug can never break out of its own `:slug:` placeholder. ## The layout is a slot too `Render("")` takes the slot named `layout` as its template and fills every `:slug:` placeholder in it with `p/moul/dynreplacer`. So the shape of the page (headings, order, what appears at all) changes without touching the code: ``` <gno-columns>  <gno-columns-sep /> # Manfred Touron :bio: :social: </gno-columns> ## Packages :packages: ``` `<gno-columns>` / `<gno-columns-sep />` are gnoweb's own extension, not HTML: raw HTML is not rendered, these are parsed. Adding a section is a **content** change, never a code one: the renderer registers one placeholder per slot by iterating the tree, so writing `content/social.md` and referencing `:social:` is the whole of it. ### Images: two gates, and neither is the one you expect An image in a slot passes **gnoweb's validator** and then the **CSP the site is served behind**. They block different things, and only the second is a domain list: - gnoweb's `AllowSvgDataImage` (`gno.land/pkg/gnoweb/render_config.go`, wired in `markdown/ext_imgvalidator.go`) rejects every `data:` URI that is not `image/svg+xml`, and blanks the `src` rather than dropping the tag. Ordinary `https://` URLs are not checked at all. - The live `content-security-policy` header on gno.land pins `img-src` to `'self' data:` plus a fixed host list: `*.githubusercontent.com`, `*.github.io`, `github.com`, `imgur.com`, `*.imgur.com`, `assets.gnoteam.com`, `sa.gno.services`, `gnolang.github.io`, `ipfs.io`, `cloudflare-ipfs.com` (read 2026-09-19). Anything else is silently not painted by the browser, with the HTML looking perfectly fine. So a GitHub avatar needs no hosting of its own: `https://avatars.githubusercontent.com/u/94029?s=400` matches `*.githubusercontent.com` and renders as-is. Verified by running this exact page through gnoweb's real goldmark pipeline, not by reading the policy. Six placeholders are computed from chain state rather than stored, and are refused as slot names so nothing can shadow them: `:owner:` `:realm:` `:chainid:` `:height:` `:rev:` `:slots:`. Three properties worth knowing: - **Lazy.** dynreplacer only invokes the callbacks whose placeholder actually occurs in the layout, so an unused slot is never read out of the tree. - **Single-pass.** A placeholder inside a slot *body* is left alone. No slot can expand into another, so no cycle exists. - **Order-independent.** Every placeholder is `:slug:` and a slug cannot contain `':'`, so no placeholder is a prefix of another and the replacer has no ambiguity to resolve. An unmatched placeholder survives into the output verbatim. That is deliberate: a missing section should be visible, not silently blank. ### Other render paths - `:slots`: the slot index (name, size, revision, height of last write) - `:slots/<slug>`: one slot's raw markdown, fenced ## Why `private` `gnomod.toml` declares `private = true`. On gno.land that means two things: 1. **No other realm may import this one.** Fine for a profile page. 2. **The creator may re-add the package at this path.** `AddPackage` waives its already-exists refusal for a private package and binds the replacement to the address in `[addpkg].creator`. ⚠️ **A redeploy re-runs `init()` and resets all realm state.** The slots are gone. That is why `content/` is the source of truth and why `gnohome tx -all` exists: after a redeploy, push every slot back. The intended path is that this never happens. Slots cover content and the layout slot covers presentation, so the code should not need to change. ## Local workflow `tools/gnohome` is the local half: it builds the slots from `content/*.md`, renders the page offline exactly as the realm would, diffs against the chain, and prints the `gnokey` commands for what is outdated, nothing else. ```sh go -C tools tool gnohome preview # see the page before anyone else does go -C tools tool gnohome status # what differs from the chain go -C tools tool gnohome tx # the commands to fix that ``` The `packages` slot is generated, not written: it is a claim about what is deployed, and `contracts.json` already tracks that per network. ```sh go -C tools tool gnohome packages > r/moul/home/content/packages.md ``` See [`tools/gnohome/README.md`](../../../tools/gnohome/README.md). ## First deploy The realm is not on chain yet. `Set` needs the package there first, and a `private` package still needs `MsgAddPackage`, which no account session can sign. **mainnet deploys in two phases.** `gnoland-1` runs `vm:p:code_submission_policy = "inert"` (read back from the chain 2026-09-19), so `MsgAddPackage` **parks** the bytes under `inert_pkg:<path>` and returns `success: true` without making the package live. `Render` still answers `package not found`, `/u/moul` is still blank, and `gnohome tx` cannot land a single slot until an approver in `vm:p:pkg_approvers` sends `MsgEnablePackage`. In practice that gate is an oracle, not a queue: `g1yaaa6rcp4ew5yjzdj4yms596wx2dtrj3a86704` enabled the four most recent parked packages after 1 to 4 blocks, 3.3 to 13.2 seconds. It can still refuse, and a refusal is easy to miss, so check rather than assume. ### The whole plan, from gnopm Deploying is not special to this realm, so it is not this realm's tool that does it. `gnopm publish` reads the chain, reports whether the package is live, parked or absent, checks that every non-test dependency is already up, sizes gas, fee and deposit from the real payload, and writes the `gnokey` commands. It never signs. ```sh gnopm publish -key moul moul/home # read the report, read the script gnopm publish -key moul moul/home | sh ``` Then the content, once the realm answers: ```sh go -C tools tool gnohome tx -all | sh ``` Run those rather than copying commands from here: anything written down goes stale, and the tools recompute from the files as they are. ### How it sizes them Deliberately no byte count here. This README **is part of the payload**, so any figure quoted in it invalidates itself the moment the file is edited. The tool reads the real numbers off the files; what follows is only the method, so a reader can judge it. **What travels.** `gnokey maketx addpkg` uploads with `MPUserAll` (`gno.land/pkg/keyscli/addpkg.go`), so every `.gno`, `.toml` and `.md` in the package directory goes on chain, **test files and this README included**. Sub-directories are skipped, which is why `content/` never ships. The README is usually the single largest file, and you pay gas and storage on it. **`-gas-wanted`, at 1,800 gas per uploaded byte.** Ten successful mainnet `add_package` transactions above h160000 cost **1,014 to 1,781 gas/byte** (median 1,393, measured 2026-09-19). The spread is the package's own `init()` work, which a byte count cannot see, so size from the top of the range. It is a ceiling and a ceiling is not charged. **`-gas-fee`, at ten times the accepted floor.** What the mempool enforces is the `gas_fee / gas_wanted` **ratio**, not the absolute (`EnsureSufficientMempoolFees`), so raising the ceiling raises the required fee and headroom is not free. The lowest ratio accepted on mainnet is **0.001 ugnot/gas**; comparable `add_package` transactions paid 0.001 to 0.00125. The tool offers 0.01. **`gas_fee` is deducted in full as offered and never refunded**, so over-offering is a real cost and not insurance: the flat `1000000ugnot` this tooling used to emit for a slot write was about ninety times the floor. **`-max-deposit`, an explicit ceiling.** Omitting it is not opting out: it falls back to `vm:p:default_deposit`, **100 GNOT of ceiling per message**. Storage locks 100ugnot per byte. Unlike the gas fee this one is **refundable** and only the measured byte delta is ever locked, so headroom here costs nothing. Re-measure before a later redeploy: gas is a function of the code, and both the gas price and the submission policy are chain parameters. <!-- BEGIN GNOCONTRACTS FOOTER (generated by `make readmes`; do not edit below) --> --- Part of **[moul/gno-contracts](https://github.com/moul/gno-contracts)** — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage. **Dependency graph:**  > ⚠️ **Disclaimer:** provided as-is, without warranty; not security-audited. Full disclaimer: [DISCLAIMER](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md). <!-- END GNOCONTRACTS FOOTER -->
- #4gnomod.toml
- #5module = "gno.land/r/moul/home" gno = "0.9" # Redeployable by its creator. See README.md § "Why private". # # A private package may be re-added at the same path by the address recorded in # [addpkg].creator (gno.land/pkg/sdk/vm/keeper.go, checkRedeployPermission), and # nothing else may import it. A redeploy RE-RUNS init() and resets realm state, # so content/ is the source of truth and tools/gnohome pushes the slots back. private = true
- #6home.gno
- #7// Package home is the realm behind https://gno.land/u/moul. // // gnoweb builds a user profile page by calling Render("") on the realm at the // exact path /r/<username>/home (gno.land/pkg/gnoweb/handler_http.go, // GetUserView) and embedding the result as the profile body. There is no // version resolution in that lookup, which is why this realm (alone in this // repo) carries no /vN suffix: the bare path IS the interface with gnoweb, // and gno.land/r/moul/home/v0 would never be found. // // # Slots // // The page is not hard-coded. It is assembled from SLOTS: named markdown // fragments in an avl tree, each written by its own Set call, so updating one // paragraph is one small transaction instead of a redeploy. // // The layout is itself a slot ("layout"), so the shape of the page (headings, // order, what appears at all) changes without touching the code. // p/moul/dynreplacer fills every :slug: placeholder found in the layout, lazily: // a slot whose placeholder is absent from the layout costs nothing to render. // // Substitution is SINGLE-PASS and non-recursive. A placeholder inside a slot // body is left alone, so no slot can expand into another and no cycle exists. // Two registered placeholders can never be prefixes of one another either // (every one is :slug: and a slug may not contain ':'), so the result does not // depend on registration order. // // A placeholder with no matching slot survives into the output verbatim. That // is deliberate: a missing section should be visible, not silently blank. // // # Versioning // // gnomod.toml declares private = true, which lets the creator re-add the // package at this path. That redeploy re-runs init() and RESETS everything // here, so the markdown under content/ is the source of truth and // tools/gnohome pushes the slots back afterwards. The intended path is that this // never happens: slots cover content, and the layout slot covers presentation. package home import ( "crypto/sha256" "encoding/hex" "strconv" "strings" "gno.land/p/nt/avl/v0" ) // admin is the only address allowed to write. Deliberately a constant and not // transferable ownership: this realm is one person's profile page, and the // same address is the only one the chain lets redeploy it. const admin = address("g1manfred47kzduec920z88wfr64ylksmdcedlf5") // layoutSlug names the slot used as the page template. const layoutSlug = "layout" // maxSlugLen bounds a slug so an index row stays readable and a key stays cheap. const maxSlugLen = 64 var ( slots = avl.NewTree() // slug -> *slot rev int // total number of writes, bumped by every mutation ) type slot struct { body string rev int // rev at the time of the last write to this slot updated int64 // block height of the last write } // reservedSlugs are placeholder names computed at render time from chain state. // A slot may not take one, because it would shadow the computed value and make // the page depend on callback registration order. var reservedSlugs = []string{"chainid", "height", "owner", "realm", "rev", "slots"} func assertAdmin(cur realm) { if cur.Previous().Address() != admin { panic("restricted to admin") } } // validSlug reports whether slug is a legal slot name: 1..maxSlugLen bytes of // [a-z0-9._-]. The character set excludes ':' so a slug can never break out of // its own :slug: placeholder, and excludes uppercase so a slot has one name. func validSlug(slug string) bool { if len(slug) == 0 || len(slug) > maxSlugLen { return false } for i := 0; i < len(slug); i++ { c := slug[i] switch { case c >= 'a' && c <= 'z', c >= '0' && c <= '9': case c == '-', c == '_', c == '.': default: return false } } return true } func assertWritableSlug(slug string) { if !validSlug(slug) { panic("invalid slug: want 1-" + strconv.Itoa(maxSlugLen) + " bytes of [a-z0-9._-], got " + strconv.Quote(slug)) } for _, r := range reservedSlugs { if slug == r { panic("reserved slug: " + slug + " is computed at render time") } } } // Set creates or replaces the slot named slug. This is the ordinary update: one // slot, one transaction. Passing the empty body keeps the slot but empties it; // use Delete to remove it. func Set(cur realm, slug, body string) { assertAdmin(cur) assertWritableSlug(slug) rev++ slots.Set(slug, &slot{body: body, rev: rev, updated: chainHeight()}) } // Append adds to the end of a slot, creating it when absent. It exists for // content too large to fit in one transaction: Set the first chunk, Append the // rest. Ordinary updates should use Set, which is idempotent. func Append(cur realm, slug, body string) { assertAdmin(cur) assertWritableSlug(slug) rev++ prev := "" if v := slots.Get(slug); v != nil { prev = v.(*slot).body } slots.Set(slug, &slot{body: prev + body, rev: rev, updated: chainHeight()}) } // Delete removes a slot. Deleting the layout slot restores the built-in // default layout. func Delete(cur realm, slug string) { assertAdmin(cur) if _, removed := slots.Remove(slug); !removed { panic("no such slot: " + slug) } rev++ } // Get returns a slot body, or "" when the slot does not exist. func Get(slug string) string { v := slots.Get(slug) if v == nil { return "" } return v.(*slot).body } // Revision returns the total number of writes this realm has accepted. It // changes on every mutation, so a client can cheaply tell "nothing moved". func Revision() int { return rev } // Manifest returns one tab-separated line per slot: // // <slug>\t<rev>\t<len>\t<sha256 of body, hex> // // It is the diff surface tools/gnohome queries with vm/qeval: one read tells it // exactly which local file is out of date, without downloading any body. func Manifest() string { var b strings.Builder slots.Iterate("", "", func(key string, value any) bool { s := value.(*slot) sum := sha256.Sum256([]byte(s.body)) b.WriteString(key) b.WriteString("\t") b.WriteString(strconv.Itoa(s.rev)) b.WriteString("\t") b.WriteString(strconv.Itoa(len(s.body))) b.WriteString("\t") b.WriteString(hex.EncodeToString(sum[:])) b.WriteString("\n") return false }) return b.String() }
- #8home_test.gno
- #9package home import ( "strings" "testing" "gno.land/p/nt/avl/v0" "gno.land/p/nt/testutils/v0" "gno.land/p/nt/uassert/v0" ) var stranger = testutils.TestAddress("mallory") // reset clears realm state. Realm globals live for the whole test binary, so // every test that reads Render or Manifest starts from a known tree. func reset() { slots = avl.NewTree() rev = 0 } // seed writes a slot without going through the admin check, for tests (and the // Example) that only care about the rendering side. func seed(slug, body string) { rev++ slots.Set(slug, &slot{body: body, rev: rev, updated: 0}) } func TestSetGetDelete(cur realm, t *testing.T) { reset() testing.SetRealm(testing.NewUserRealm(admin)) Set(cross(cur), "bio", "Building on gno.") uassert.Equal(t, "Building on gno.", Get("bio")) uassert.Equal(t, 1, Revision()) // Set is idempotent in shape: a second write replaces, never appends. Set(cross(cur), "bio", "Still building.") uassert.Equal(t, "Still building.", Get("bio")) uassert.Equal(t, 2, Revision()) Delete(cross(cur), "bio") uassert.Equal(t, "", Get("bio"), "a deleted slot reads as empty") uassert.Equal(t, 3, Revision()) uassert.AbortsWithMessage(t, cur, "no such slot: bio", func() { Delete(cross(cur), "bio") }) } func TestAppendChunks(cur realm, t *testing.T) { reset() testing.SetRealm(testing.NewUserRealm(admin)) // The escape hatch for a body too large for one transaction. Set(cross(cur), "long", "part one. ") Append(cross(cur), "long", "part two.") uassert.Equal(t, "part one. part two.", Get("long")) // Append creates the slot when it is absent. Append(cross(cur), "fresh", "hello") uassert.Equal(t, "hello", Get("fresh")) } func TestWritesAreAdminOnly(cur realm, t *testing.T) { reset() testing.SetRealm(testing.NewUserRealm(stranger)) uassert.AbortsWithMessage(t, cur, "restricted to admin", func() { Set(cross(cur), "bio", "pwned") }) uassert.AbortsWithMessage(t, cur, "restricted to admin", func() { Append(cross(cur), "bio", "pwned") }) uassert.AbortsWithMessage(t, cur, "restricted to admin", func() { Delete(cross(cur), "bio") }) uassert.Equal(t, "", Get("bio")) } func TestSlugRules(cur realm, t *testing.T) { reset() testing.SetRealm(testing.NewUserRealm(admin)) uassert.True(t, validSlug("bio")) uassert.True(t, validSlug("now.2026-09")) uassert.True(t, validSlug("latest_packages")) uassert.False(t, validSlug(""), "empty") uassert.False(t, validSlug("Bio"), "uppercase: a slot must have one name") uassert.False(t, validSlug("a b"), "space") uassert.False(t, validSlug("a:b"), "a colon would break out of the :slug: placeholder") uassert.False(t, validSlug(strings.Repeat("a", maxSlugLen+1)), "too long") uassert.AbortsContains(t, cur, "invalid slug", func() { Set(cross(cur), "Bad Slug", "x") }) // A reserved name would shadow a value computed from chain state. for _, name := range reservedSlugs { uassert.AbortsContains(t, cur, "reserved slug", func() { Set(cross(cur), name, "x") }) } // "layout" is special but NOT reserved: it is a real, writable slot. Set(cross(cur), layoutSlug, "# hi") uassert.Equal(t, "# hi", Get(layoutSlug)) } func TestManifestIsTheDiffSurface(cur realm, t *testing.T) { reset() testing.SetRealm(testing.NewUserRealm(admin)) Set(cross(cur), "bio", "hello") Set(cross(cur), "alpha", "") // Sorted by slug (avl order), one line each, four tab-separated fields. lines := strings.Split(strings.TrimSuffix(Manifest(), "\n"), "\n") uassert.Equal(t, 2, len(lines)) alpha := strings.Split(lines[0], "\t") uassert.Equal(t, 4, len(alpha)) uassert.Equal(t, "alpha", alpha[0]) uassert.Equal(t, "0", alpha[2], "byte length of an empty body") // sha256(""), pinning that the hash is over the body, not over a wrapper. uassert.Equal(t, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", alpha[3]) bio := strings.Split(lines[1], "\t") uassert.Equal(t, "bio", bio[0]) uassert.Equal(t, "5", bio[2]) // sha256("hello") uassert.Equal(t, "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824", bio[3]) } func TestRenderFillsTheLayoutSlot(cur realm, t *testing.T) { reset() testing.SetRealm(testing.NewUserRealm(admin)) Set(cross(cur), layoutSlug, "# :owner:\n\n:bio:\n\n:missing:\n") Set(cross(cur), "bio", "Building on gno.") out := Render("") uassert.True(t, strings.Contains(out, "# "+admin.String()), "a computed placeholder is filled from chain state") uassert.True(t, strings.Contains(out, "Building on gno."), "a slot placeholder is filled from the tree") uassert.True(t, strings.Contains(out, ":missing:"), "an unmatched placeholder survives verbatim, so a gap is visible") } func TestRenderDoesNotRecurse(cur realm, t *testing.T) { reset() testing.SetRealm(testing.NewUserRealm(admin)) // A slot body that looks like a placeholder must not expand: substitution // is one pass, which is what makes cycles impossible. Set(cross(cur), layoutSlug, ":a:") Set(cross(cur), "a", ":b:") Set(cross(cur), "b", "should not appear") uassert.Equal(t, ":b:", Render("")) } func TestRenderUnsetLayoutFallsBack(t *testing.T) { reset() out := Render("") uassert.True(t, strings.Contains(out, "No layout slot yet")) uassert.False(t, strings.Contains(out, ":slots:"), "the default layout must not leave its own placeholders unresolved") uassert.False(t, strings.Contains(out, ":rev:")) uassert.False(t, strings.Contains(out, ":height:")) uassert.False(t, strings.Contains(out, ":chainid:")) } func TestRenderSubPaths(t *testing.T) { reset() seed("bio", "Building on gno.") idx := Render("slots") uassert.True(t, strings.Contains(idx, "| [bio](/r/moul/home:slots/bio) |")) raw := Render("slots/bio") uassert.True(t, strings.Contains(raw, "Building on gno.")) uassert.True(t, strings.Contains(raw, "16 bytes")) uassert.True(t, strings.Contains(Render("slots/nope"), "No slot named")) uassert.True(t, strings.Contains(Render("whatever"), "No such path")) } func TestRenderEmptyIndex(t *testing.T) { reset() uassert.True(t, strings.Contains(Render("slots"), "_no slots yet_")) }
- #10render.gno
- #11package home import ( "strconv" "strings" "chain/runtime" "gno.land/p/moul/dynreplacer/v0" ) // defaultLayout is what renders before a layout slot exists, i.e. right after // the very first deploy. It uses only computed placeholders, so it never shows // an unresolved :slug: of its own. const defaultLayout = "# gno.land/r/moul/home\n\n" + "No layout slot yet. Set one, then the page is whatever you make it:\n\n" + " gnokey maketx call -pkgpath gno.land/r/moul/home -func Set \\\n" + " -args layout -args \"$(/bin/cat content/layout.md)\" \\\n" + " -gas-fee 1000000ugnot -gas-wanted 20000000 \\\n" + " -broadcast -chainid gnoland-1 -remote https://rpc.gno.land:443 moul\n\n" + "## Slots\n\n:slots:\n\n---\n\nrev :rev: · height :height: · :chainid:\n" func chainHeight() int64 { return runtime.ChainHeight() } // Render serves three views: // // "" the assembled page, what https://gno.land/u/moul shows // "slots" the slot index: name, size, revision, last write // "slots/<slug>" one slot's raw markdown, fenced func Render(path string) string { switch { case path == "": return renderPage() case path == "slots": return renderIndex() case strings.HasPrefix(path, "slots/"): return renderSlot(strings.TrimPrefix(path, "slots/")) default: return "# Not found\n\nNo such path: " + strconv.Quote(path) + "\n\nTry [the slot index](/r/moul/home:slots).\n" } } // renderPage fills the layout. dynreplacer only invokes the callbacks whose // placeholder actually occurs in the layout, so an unused slot is never even // read out of the tree. func renderPage() string { layout := Get(layoutSlug) if layout == "" { layout = defaultLayout } r := dynreplacer.New() // Computed from chain state. Registered first; assertWritableSlug keeps a // slot from ever taking one of these names, so nothing shadows them. r.RegisterCallback(":owner:", func() string { return admin.String() }) r.RegisterCallback(":realm:", func() string { return "gno.land/r/moul/home" }) r.RegisterCallback(":chainid:", func() string { return runtime.ChainID() }) r.RegisterCallback(":height:", func() string { return strconv.FormatInt(runtime.ChainHeight(), 10) }) r.RegisterCallback(":rev:", func() string { return strconv.Itoa(rev) }) r.RegisterCallback(":slots:", func() string { return slotLinks() }) // One callback per slot. The closure captures s, which is re-bound on each // iteration, so every callback sees its own slot. slots.Iterate("", "", func(key string, value any) bool { s := value.(*slot) r.RegisterCallback(":"+key+":", func() string { return s.body }) return false }) return r.Replace(layout) } // slotLinks is the :slots: placeholder: a bullet list of every slot, linking to // its raw view. func slotLinks() string { if slots.Size() == 0 { return "_no slots yet_" } var b strings.Builder slots.Iterate("", "", func(key string, value any) bool { b.WriteString("- [") b.WriteString(key) b.WriteString("](/r/moul/home:slots/") b.WriteString(key) b.WriteString(")\n") return false }) return strings.TrimSuffix(b.String(), "\n") } func renderIndex() string { var b strings.Builder b.WriteString("# Slots\n\n") b.WriteString("rev ") b.WriteString(strconv.Itoa(rev)) b.WriteString(" · ") b.WriteString(strconv.Itoa(slots.Size())) b.WriteString(" slot(s)\n\n") if slots.Size() == 0 { b.WriteString("_no slots yet_\n") return b.String() } b.WriteString("| slot | bytes | rev | height |\n") b.WriteString("| --- | ---: | ---: | ---: |\n") slots.Iterate("", "", func(key string, value any) bool { s := value.(*slot) b.WriteString("| [") b.WriteString(key) b.WriteString("](/r/moul/home:slots/") b.WriteString(key) b.WriteString(") | ") b.WriteString(strconv.Itoa(len(s.body))) b.WriteString(" | ") b.WriteString(strconv.Itoa(s.rev)) b.WriteString(" | ") b.WriteString(strconv.FormatInt(s.updated, 10)) b.WriteString(" |\n") return false }) return b.String() } func renderSlot(slug string) string { v := slots.Get(slug) if v == nil { return "# Not found\n\nNo slot named " + strconv.Quote(slug) + ".\n\nTry [the slot index](/r/moul/home:slots).\n" } s := v.(*slot) var b strings.Builder b.WriteString("# ") b.WriteString(slug) b.WriteString("\n\n") b.WriteString(strconv.Itoa(len(s.body))) b.WriteString(" bytes · rev ") b.WriteString(strconv.Itoa(s.rev)) b.WriteString(" · written at height ") b.WriteString(strconv.FormatInt(s.updated, 10)) b.WriteString("\n\n```\n") b.WriteString(s.body) if !strings.HasSuffix(s.body, "\n") { b.WriteString("\n") } b.WriteString("```\n") return b.String() }
- #12render_example_test.gno
- #13package home // ExampleRender pins the assembled page. It seeds state directly (rather than // through Set) so the example takes no `cur realm`, and it uses only // non-volatile placeholders so the golden output does not depend on the test // machine's block height or chain id. func ExampleRender() { reset() seed("layout", "# :owner:\n\n:bio:\n\n## Packages\n\n:packages:\n") seed("bio", "Building on gno.") seed("packages", "- p/moul/dynreplacer\n- r/moul/home") print(Render("")) // Output: // # g1manfred47kzduec920z88wfr64ylksmdcedlf5 // // Building on gno. // // ## Packages // // - p/moul/dynreplacer // - r/moul/home }
- #14/gno.MemPackageType
- #15 MPUserAll
Result log
msg:0,success:true,log:,events:[]