Transaction

EA3B8D68497721…927E01E28B85

Block 923,227 · index 0 · indexed

Summary

Hash
EA3B8D684977215B70CD68F25162AD19EC921AFECC394D5D345C927E01E28B85
Block
923,227
Size
15045 bytes
Gas used
17,356,203 / 50,162,800
Fee
150488 ugnot
Status
success

Messages

#1AddPackagegno.land/r/moul/x/daily/guestbook/v113 arguments
Attached funds
6000000 ugnot

Arguments · 13

  1. #1guestbook
  2. #2README.md
  3. #3# Guestbook > ⚠️ **Experimental — generated with no human supervision.** This realm was > produced automatically by an MCP-driven agent to exercise the gno MCP server > and tooling, and to generate test content for gno compilers, linters and > formatters. **Not audited. Not for production.** Full context & folder README: > [r/moul/x/daily](https://github.com/moul/gno-contracts/blob/main/r/moul/x/daily/README.md) --- A public, on-chain guestbook realm for gno.land. Anyone can leave a signed message; every entry records the signer's address, the message, and the block height at which it was signed. The realm's `Render` page shows all entries as a Markdown table, newest-first, with a running total. Built for the **sapphire** testnet (gno 0.9). ## Realm path ``` gno.land/r/REPLACE_ADDR/guestbook ``` (`REPLACE_ADDR` is substituted with the deployer's address at publish time.) ## Public API - `Sign(cur realm, message string)` — crossing tx. Appends an entry attributed to the immediate caller. Panics on an empty or over-long (>280 bytes) message. - `Count() int` — total number of signatures (read-only). - `Render(path string) string` — Markdown table of all entries, newest-first. ## Example calls Sign the guestbook (from an EOA via `gnokey`): ```sh gnokey maketx call \ -pkgpath "gno.land/r/REPLACE_ADDR/guestbook" \ -func Sign \ -args "gm gno.land!" \ -gas-fee 20000ugnot -gas-wanted 2000000 \ -broadcast -chainid sapphire-1 -remote <rpc> mykey ``` From another realm, invoke it as a crossing call: ```go guestbook.Sign(cross(cur), "hello from my realm") ``` View the rendered guestbook: ```sh gnokey query vm/qrender --data "gno.land/r/REPLACE_ADDR/guestbook:" ``` ## Example render output ```markdown # Guestbook **Total signatures:** 2 | # | Who | Message | Height | |---|-----|---------|--------| | 2 | g1v9jxgu…0gh | hello from my realm | 4210 | | 1 | g1jg8mtu…qf5 | gm gno.land! | 4180 | ``` ## Notes - Caller identity uses the gno 0.9 interrealm convention: `Sign` is a crossing function that checks `cur.IsCurrent()` before deriving the author from `cur.Previous().Address()`. - Block height comes from `chain/runtime.ChainHeight()` — deterministic. - Entries are stored in a `gno.land/p/nt/avl/v0` tree keyed by a zero-padded sequence number so iteration order is deterministic and matches insertion order (reversed for newest-first rendering). ``` ## What changed in v1 Two ports against [`v0`](https://github.com/moul/gno-contracts/tree/4f2df83869b80470eb81c48a82fdbe82256b8113/r/moul/x/daily/guestbook), which stays live and untouched. ### Rendering Identical behaviour to [`v0`](https://github.com/moul/gno-contracts/tree/4f2df83869b80470eb81c48a82fdbe82256b8113/r/moul/x/daily/guestbook) apart from rendering, which now goes through [`p/moul/kit/ui`](/p/moul/kit/ui/v0) instead of the local `shortAddr`, `escapeCell` helpers. **One address format.** Eleven realms carried their own `shortAddr` with four different truncation rules, so the same account rendered differently depending on which realm you opened. `ui.Addr` is that decision made once: 8 leading characters, an ellipsis, 4 trailing, in backticks. **Real escaping.** The local helper replaced a handful of markdown metacharacters. `ui.Inline` and `ui.Cell` delegate to [`p/nt/markdown/sanitize`](/p/nt/markdown/sanitize/v0), which also strips bidi and zero-width characters and folds newlines, so user text cannot reorder or escape the line it sits on. Visible change: addresses now render in monospace. ### Storage State moved from a hand-rolled `avl.Tree` + `nextID` + zero-padding helper to [`p/moul/kit/store`](/p/moul/kit/store/v0), which keys entries by [`seqid`](/p/nt/seqid/v0) instead of a fixed-width decimal string. `v0` padded ids to width 16, the widest of the six hand-rolled variants in this repo and still a ceiling. Past that width the padding stops and the tree orders `"1000000000000"` before `"999999999999"`, so every list this realm renders would be wrong from that entry on. `store` keys are 8 big-endian bytes whose order is numeric for every `uint64`, so there is no width left to outgrow. `Entry` loses its `ID` field, which the store now owns, so `addEntry` returns `(store.ID, *Entry)`. The `count` global is gone too: `Len()` answers it. Ids stay plain integers and the rendered output of the storage port is unchanged. Each port changes something `v0` promised, one the rendered output and one the storage layout, so under this repo's versioning rule each is a compatibility change and neither could be an edit to `v0` in place. They land in the **same** new version because `v1` was never published. A version number is a tag on something that exists on a chain, and until it does there is nothing for a second number to avoid disturbing, so the right move is to keep editing the version you have. `gnopm unbump` is what folded the second port back down into this one. <!-- 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. **On mainnet:** [![deployment status](https://gnoscope.com/_badges/shield/status/r/moul/x/daily/guestbook/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/guestbook/v1) [![transactions](https://gnoscope.com/_badges/shield/txs/r/moul/x/daily/guestbook/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/guestbook/v1) [![unique callers](https://gnoscope.com/_badges/shield/users/r/moul/x/daily/guestbook/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/guestbook/v1) [![deployed revision](https://gnoscope.com/_badges/shield/version/r/moul/x/daily/guestbook/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/guestbook/v1) **Dependency graph:** ![gno.land/r/moul/x/daily/guestbook/v1 dependency graph](https://raw.githubusercontent.com/moul/gno-contracts/main/_assets/gno.land/r/moul/x/daily/guestbook/v1/deps.png) > 🧪 **Highly experimental — potentially vibe-coded.** Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: [DISCLAIMER](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md). <!-- END GNOCONTRACTS FOOTER -->
  4. #4gnomod.toml
  5. #5module = "gno.land/r/moul/x/daily/guestbook/v1" gno = "0.9" private = true [source] repository = "https://github.com/moul/gno-contracts" path = "r/moul/x/daily/guestbook" revision = "507056d812b505ad16a009f0d60786644ceeb19d"
  6. #6guestbook.gno
  7. #7// Package guestbook is a public, on-chain guestbook realm for gno.land. // // Anyone can sign the guestbook with a short message via the Sign crossing // function. Every entry records the caller's address, the message, and the // block height at which it was signed. Render lists all entries newest-first // as a Markdown table. // // v1 renders through [p/moul/kit/ui](/p/moul/kit/ui/v0) instead of the // hand-rolled shortAddr and escapeCell helpers v0 carried. The escaping is the // substantive change: v0 replaced four characters, while ui.Cell also strips // bidi and zero-width characters, which a message can otherwise use to reorder // how the rest of the row reads. package guestbook import ( "strconv" "strings" "chain" "chain/markdown" "chain/runtime" "gno.land/p/moul/kit/store/v0" "gno.land/p/moul/kit/ui/v0" ) // Entry is a single signed guestbook line. It carries no ID field: the id // belongs to the store, which hands it back on lookup and iteration. type Entry struct { Author string // bech32 address of the signer Message string // the message left by the signer Height int64 // block height at which the entry was signed } const maxMessageLen = 280 // entries assigns the sequence numbers. v1 kept its own count plus a seqKey() // that zero-padded to width 16, the widest of the six hand-rolled variants in // this repo and still a ceiling; the store key has none. var entries = store.Named("guestbook: entry") // Sign appends a new entry to the guestbook attributed to the immediate caller. // // It is a crossing function (gno 0.9 interrealm convention): callers invoke it // as Sign(cross(cur), "hello"). The cur.IsCurrent() guard is the authentication // primitive — without it a stale/forged realm value could spoof the author. func Sign(cur realm, message string) { if !cur.IsCurrent() { panic("guestbook: spoofed realm; Sign must be called via cross(cur)") } author := cur.Previous().Address().String() id, e := addEntry(author, message, runtime.ChainHeight()) chain.Emit("Signed", "id", id.String(), "author", e.Author, "height", strconv.FormatInt(e.Height, 10), ) } // addEntry validates the message and appends an entry. Non-crossing internal // helper so the append/validation logic is unit-testable without a realm frame. // Panics (aborting the tx, reverting state) on an invalid message. func addEntry(author, message string, height int64) (store.ID, *Entry) { msg := strings.TrimSpace(message) if strings.TrimSpace(markdown.StripBidiAndZeroWidth(msg)) == "" { panic("guestbook: message must not be empty") } if len(msg) > maxMessageLen { panic("guestbook: message too long (max " + strconv.Itoa(maxMessageLen) + " bytes)") } e := &Entry{ Author: author, Message: msg, Height: height, } return entries.Add(e), e } // Count returns the total number of signatures. Read-only, non-crossing. func Count() int { return entries.Len() } // Render lists every entry newest-first as a Markdown table plus a total count. func Render(path string) string { if entries.Len() == 0 { return "# Guestbook\n\n" + ui.Empty("No one has signed yet. Be the first!") } t := ui.NewTable("#", "Who", "Message", "Height") // Ids ascend with signing, so reverse iteration is newest-first. entries.EachReverse(func(id store.ID, v any) { e := v.(*Entry) t.Row( id.String(), ui.AddrOf(e.Author), ui.Cell(e.Message), strconv.FormatInt(e.Height, 10), ) }) return "# Guestbook\n\n**Total signatures:** " + strconv.Itoa(entries.Len()) + "\n\n" + t.String() }
  8. #8guestbook_test.gno
  9. #9package guestbook import ( "strings" "testing" "gno.land/p/moul/kit/store/v0" ) // resetState clears package globals between tests (globals persist across // test functions in the same package binary). func resetState() { entries = store.Named("guestbook: entry") } func TestAddEntryAppendsAndCounts(t *testing.T) { resetState() addEntry("g1alice", "hello world", 100) addEntry("g1bob", "second entry", 101) if got := Count(); got != 2 { t.Fatalf("Count() = %d, want 2", got) } out := Render("") if !strings.Contains(out, "**Total signatures:** 2") { t.Errorf("Render missing total; got:\n%s", out) } if !strings.Contains(out, "hello world") { t.Errorf("Render missing first message; got:\n%s", out) } if !strings.Contains(out, "second entry") { t.Errorf("Render missing second message; got:\n%s", out) } if !strings.Contains(out, "100") || !strings.Contains(out, "101") { t.Errorf("Render missing heights; got:\n%s", out) } } func TestRenderNewestFirst(t *testing.T) { resetState() addEntry("g1alice", "AAA oldest", 1) addEntry("g1alice", "BBB newest", 2) out := Render("") iNew := strings.Index(out, "BBB newest") iOld := strings.Index(out, "AAA oldest") if iNew < 0 || iOld < 0 { t.Fatalf("both messages must appear; got:\n%s", out) } if iNew > iOld { t.Errorf("newest entry should render before oldest; got:\n%s", out) } } func TestRenderEmpty(t *testing.T) { resetState() out := Render("") if !strings.Contains(out, "No one has signed yet") { t.Errorf("empty render should invite signing; got:\n%s", out) } } func TestEmptyMessagePanics(t *testing.T) { resetState() defer func() { if r := recover(); r == nil { t.Errorf("signing an empty message should panic") } }() addEntry("g1alice", " ", 1) } // A message must not be able to break out of its table cell. The escaping now // lives in ui.Cell, so this asserts the realm's rendered output rather than a // local helper. func TestRenderEscapesMessage(t *testing.T) { resetState() defer resetState() addEntry("g1manfred47kzduec920z88wfr64ylksmdcedlf5", "a|b", 1) out := Render("") if strings.Contains(out, "| a|b |") { t.Errorf("an unescaped pipe would open a column:\n%s", out) } if !strings.Contains(out, `a\|b`) { t.Errorf("message should appear escaped:\n%s", out) } } // v1 asserted that its own seqKey() ordered numerically. That held only below // its width of 16: seqKey(10^16) is 17 characters and sorts before // seqKey(10^16-1). The store key is 8 bytes for every id, so there is no // ceiling to reach. func TestSeqKeyOrders(t *testing.T) { if a, b := store.ID(2).Key(), store.ID(10).Key(); !(a < b) { t.Error("id 2 should sort before id 10") } if a, b := store.ID(9999999999999999).Key(), store.ID(10000000000000000).Key(); !(a < b) { t.Error("ordering should survive one past v1's width-16 ceiling") } }
  10. #10render_example_test.gno
  11. #11package guestbook // ExampleRender pins the realm's Render output as a testable example. func ExampleRender() { print(Render("")) // Output: // # Guestbook // // *No one has signed yet. Be the first!* }
  12. #12zz_zerowidth_test.gno
  13. #13package guestbook import ( "testing" ) // zwBlank holds one input per rune range chain/markdown.StripBidiAndZeroWidth // removes (U+200B..U+200F, U+202A..U+202E, U+2066..U+2069, U+FEFF), plus a mix // with real spaces. strings.TrimSpace keeps every one of them and the render // strips them all, so each must be refused. var zwBlank = []string{ "\u200b\u200b\u200b", // ZWSP "\u200d", // ZWJ "\u200e", // LRM "\u202e", // RLO "\u2066\u2069", // LRI PDI "\ufeff", // BOM " \u200b \u200b ", // mixed with real spaces } // zwOK must stay accepted: the stripper removes the marks and leaves text. var zwOK = []string{"a", "a\u200bb", " padded "} func zwPanics(f func()) (p bool) { defer func() { if recover() != nil { p = true } }() f() return false } func TestZeroWidthMessageIsRefused(t *testing.T) { resetState() defer resetState() for _, s := range zwBlank { if !zwPanics(func() { addEntry("g1alice", s, 1) }) { t.Errorf("addEntry(%q) accepted a message the render strips to blank", s) } } for _, s := range zwOK { if zwPanics(func() { addEntry("g1alice", s, 1) }) { t.Errorf("addEntry(%q) refused a message that renders as text", s) } } if Count() != len(zwOK) { t.Errorf("Count = %d, want %d", Count(), len(zwOK)) } }

Result log

msg:0,success:true,log:,events:[]