Transaction

26B290CC0A97BF…B673BDDE66E7

Block 923,233 · index 0 · indexed

Summary

Hash
26B290CC0A97BF97E3ED5217F88ADFD5F7CAEF9E384C2F4D981FB673BDDE66E7
Block
923,233
Size
14491 bytes
Gas used
19,128,971 / 48,712,000
Fee
146136 ugnot
Status
success

Messages

Attached funds
6000000 ugnot

Arguments · 13

  1. #1timecapsule
  2. #2README.md
  3. #3# Time Capsule 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 guestbook with a twist: every message is sealed until a future block height, chosen by its author when they leave it. Until then it's just a locked entry showing who sealed it and when it opens; once the chain reaches that height, the message unlocks forever for anyone to read. Realm: `gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/timecapsule` ## Example calls - `Leave("see you in 100 blocks", 100)` — seal a message that opens 100 blocks from now. Returns the capsule id. Only direct EOA (`MsgCall`) calls can seal one; empty messages, messages over 500 bytes, and delays outside `(0, 1_000_000]` blocks are rejected. - `Render("")` — home page: counts + every already-unlocked message. - `Render("sealed")` — every still-sealed capsule with its unlock height and blocks remaining (message hidden). - `Render("capsule/<id>")` — a single capsule's detail page; shows the message only once unlocked. ## Toolchain status Tested locally against a `gnolang/gno` master checkout (`~/p/gh/gnoland/gno`) using its own `gno` binary as GNOROOT, resolving `/p/nt/*` deps through its `examples/` workspace. All 5 unit tests pass (`gno test -v .`), and `gno lint .` reports no issues. This is newer than sapphire (gno 0.9), but the code only uses APIs documented as current in the project's gno skill (`chain`, `chain/runtime`, `gno.land/p/nt/avl/v0`, `gno.land/p/nt/markdown/sanitize/v0`), so it should be on-chain-valid for sapphire as well. ## What changed in v1 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 12. 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. `capsule` loses its `id` field, which the store now owns, and **capsule ids start at 1** where `v0` handed out 0 for the first one. `capsule/0` is now rejected as an invalid id rather than looked up. This is a storage change, which under this repo's versioning rule is a compatibility change, hence a new version rather than an edit in place. [`v0`](https://github.com/moul/gno-contracts/tree/4f2df83869b80470eb81c48a82fdbe82256b8113/r/moul/x/daily/timecapsule) stays live and untouched. <!-- 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/timecapsule/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/timecapsule/v1) [![transactions](https://gnoscope.com/_badges/shield/txs/r/moul/x/daily/timecapsule/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/timecapsule/v1) [![unique callers](https://gnoscope.com/_badges/shield/users/r/moul/x/daily/timecapsule/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/timecapsule/v1) [![deployed revision](https://gnoscope.com/_badges/shield/version/r/moul/x/daily/timecapsule/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/timecapsule/v1) **Dependency graph:** ![gno.land/r/moul/x/daily/timecapsule/v1 dependency graph](https://raw.githubusercontent.com/moul/gno-contracts/main/_assets/gno.land/r/moul/x/daily/timecapsule/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/timecapsule/v1" gno = "0.9" private = true [source] repository = "https://github.com/moul/gno-contracts" path = "r/moul/x/daily/timecapsule" revision = "507056d812b505ad16a009f0d60786644ceeb19d"
  6. #6render_example_test.gno
  7. #7package timecapsule // ExampleRender pins the realm's Render output as a testable example. func ExampleRender() { print(Render("")) // Output: // # ⏳ Time Capsule Guestbook // // Leave a message for the future. It stays sealed until its unlock block height, then anyone can read it — call `Leave(message, delayBlocks)`. // // 0 capsule(s) total · 0 unlocked · 0 still sealed. // // ## Unlocked messages // // _None yet. Be the first to leave one that will open later._ }
  8. #8timecapsule.gno
  9. #9// Package timecapsule is a public guestbook where every message is sealed // until a future block height, then permanently unlocked for anyone to read. package timecapsule import ( "strconv" "strings" "chain" "chain/markdown" "chain/runtime" "gno.land/p/moul/kit/store/v0" "gno.land/p/nt/markdown/sanitize/v0" ) // capsule carries no id field: the id belongs to the store, which hands it // back on lookup and iteration. type capsule struct { author address message string createdAt int64 unlockHeight int64 } // capsules assigns the capsule ids. v0 kept its own nextID plus an idKey() // that called strings.Repeat WITHOUT the length guard the other realms had, so // at the 10^12th capsule it did not mis-sort, it panicked: Repeat rejects a // negative count, and the realm would have stopped accepting Leave calls. The // store key is 8 fixed bytes with no width to outgrow. var capsules = store.Named("capsule") const ( maxDelayBlocks int64 = 1_000_000 maxMessageLen int = 500 ) // Leave seals a new message that stays hidden until `delayBlocks` blocks // from now, then becomes publicly readable forever. Returns the capsule id. func Leave(cur realm, message string, delayBlocks int64) int64 { if !cur.Previous().IsUserCall() { panic("only direct user calls can leave a capsule") } message = strings.TrimSpace(message) if strings.TrimSpace(markdown.StripBidiAndZeroWidth(message)) == "" { panic("message must not be empty") } if len(message) > maxMessageLen { panic("message too long") } if delayBlocks <= 0 || delayBlocks > maxDelayBlocks { panic("delayBlocks out of range") } now := runtime.ChainHeight() c := &capsule{ author: cur.Previous().Address(), message: message, createdAt: now, unlockHeight: now + delayBlocks, } id := capsules.Add(c) chain.Emit("CapsuleSealed", "id", id.String(), "unlockHeight", strconv.FormatInt(c.unlockHeight, 10), ) return int64(id) } func Render(path string) string { switch { case path == "": return renderHome() case path == "sealed": return renderSealed() case strings.HasPrefix(path, "capsule/"): return renderCapsule(strings.TrimPrefix(path, "capsule/")) default: return "> [!WARNING]\n> Path not found\n" } } func renderHome() string { now := runtime.ChainHeight() revealed := 0 sealed := 0 capsules.Each(func(_ store.ID, value any) { if value.(*capsule).unlockHeight <= now { revealed++ } else { sealed++ } }) var out strings.Builder out.WriteString("# ⏳ Time Capsule Guestbook\n\n") out.WriteString("Leave a message for the future. It stays sealed until its unlock block height, then anyone can read it — call `Leave(message, delayBlocks)`.\n\n") out.WriteString(strconv.Itoa(revealed+sealed) + " capsule(s) total · " + strconv.Itoa(revealed) + " unlocked · " + strconv.Itoa(sealed) + " still sealed") if sealed > 0 { out.WriteString(" (see [sealed](sealed))") } out.WriteString(".\n\n## Unlocked messages\n\n") if revealed == 0 { out.WriteString("_None yet. Be the first to leave one that will open later._\n") return out.String() } capsules.Each(func(id store.ID, value any) { c := value.(*capsule) if c.unlockHeight <= now { out.WriteString(renderEntry(id, c)) } }) return out.String() } func renderSealed() string { now := runtime.ChainHeight() var out strings.Builder out.WriteString("# Sealed Capsules\n\n") found := false capsules.Each(func(id store.ID, value any) { c := value.(*capsule) if c.unlockHeight > now { found = true out.WriteString("- capsule [#" + id.String() + "](capsule/" + id.String() + ") by `" + c.author.String() + "` — unlocks at block " + strconv.FormatInt(c.unlockHeight, 10) + " (" + strconv.FormatInt(c.unlockHeight-now, 10) + " blocks left)\n") } }) if !found { out.WriteString("_No sealed capsules right now._\n") } return out.String() } func renderCapsule(idStr string) string { id, ok := store.ParseID(idStr) if !ok { return "> [!WARNING]\n> Invalid capsule id\n" } v, ok := capsules.Get(id) if !ok { return "> [!WARNING]\n> Capsule not found\n" } c := v.(*capsule) now := runtime.ChainHeight() var out strings.Builder out.WriteString("# Capsule #" + id.String() + "\n\n") out.WriteString("Sealed by `" + c.author.String() + "` at block " + strconv.FormatInt(c.createdAt, 10) + ".\n\n") if c.unlockHeight > now { out.WriteString("\U0001f512 Still sealed. Unlocks at block " + strconv.FormatInt(c.unlockHeight, 10) + " (" + strconv.FormatInt(c.unlockHeight-now, 10) + " blocks left).\n") return out.String() } out.WriteString("\U0001f513 Unlocked at block " + strconv.FormatInt(c.unlockHeight, 10) + ":\n\n> " + sanitize.InlineText(c.message) + "\n") return out.String() } func renderEntry(id store.ID, c *capsule) string { return "- **#" + id.String() + "** by `" + c.author.String() + "` (sealed at block " + strconv.FormatInt(c.createdAt, 10) + ", opened at block " + strconv.FormatInt(c.unlockHeight, 10) + "):\n > " + sanitize.InlineText(c.message) + "\n\n" }
  10. #10timecapsule_test.gno
  11. #11package timecapsule import ( "strings" "testing" "gno.land/p/moul/kit/store/v0" "gno.land/p/nt/testutils/v0" "gno.land/p/nt/uassert/v0" ) func resetState() { capsules = store.Named("capsule") } func TestLeaveAndReveal(cur realm, t *testing.T) { resetState() alice := testutils.TestAddress("alice") testing.SetRealm(testing.NewUserRealm(alice)) // v1 ids start at 1: the store never assigns 0, so the zero id stays // usable as "absent". v0 handed out 0 for the first capsule. id := Leave(cross(cur), "hello, future", 5) uassert.Equal(t, int64(1), id) if got := Render(""); !strings.Contains(got, "1 still sealed") { t.Fatalf("expected capsule to still be sealed, got: %s", got) } if got := Render("sealed"); !strings.Contains(got, "capsule/1") { t.Fatalf("expected capsule 1 listed as sealed, got: %s", got) } testing.SkipHeights(5) if got := Render(""); !strings.Contains(got, "hello, future") { t.Fatalf("expected capsule to be revealed, got: %s", got) } if got := Render("capsule/1"); !strings.Contains(got, "hello, future") { t.Fatalf("expected capsule detail to reveal message, got: %s", got) } // Id 0 is never assigned, so the path is rejected rather than looked up. if got := Render("capsule/0"); !strings.Contains(got, "Invalid capsule id") { t.Fatalf("expected capsule/0 to be rejected, got: %s", got) } } func TestLeaveRejectsEmptyMessage(cur realm, t *testing.T) { resetState() alice := testutils.TestAddress("alice") testing.SetRealm(testing.NewUserRealm(alice)) uassert.AbortsWithMessage(t, cur, "message must not be empty", func() { Leave(cross(cur), " ", 5) }) } func TestLeaveRejectsBadDelay(cur realm, t *testing.T) { resetState() alice := testutils.TestAddress("alice") testing.SetRealm(testing.NewUserRealm(alice)) uassert.AbortsWithMessage(t, cur, "delayBlocks out of range", func() { Leave(cross(cur), "hi", 0) }) } // Regression: an intermediate realm (not a direct EOA call) must never be // able to seal a capsule as if it were a user. func TestLeaveRejectsCodeRealm(cur realm, t *testing.T) { resetState() testing.SetRealm(testing.NewCodeRealm("gno.land/r/some/attacker")) uassert.AbortsWithMessage(t, cur, "only direct user calls can leave a capsule", func() { Leave(cross(cur), "hi", 5) }) } func TestRenderNotFound(t *testing.T) { resetState() if got := Render("nope"); !strings.Contains(got, "not found") { t.Fatalf("expected 404-ish message, got: %s", got) } }
  12. #12zz_zerowidth_test.gno
  13. #13package timecapsule import ( "testing" "gno.land/p/nt/testutils/v0" ) // 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 TestZeroWidthMessageIsRefused(cur realm, t *testing.T) { resetState() defer resetState() testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("alice"))) for _, s := range zwBlank { if revive(func() { Leave(cross(cur), s, 5) }) == nil { t.Errorf("Leave accepted message %q, which the render strips to blank", s) } } for _, s := range zwOK { if r := revive(func() { Leave(cross(cur), s, 5) }); r != nil { t.Errorf("Leave refused message %q: %v", s, r) } } if capsules.Len() != len(zwOK) { t.Errorf("%d capsule(s), want %d", capsules.Len(), len(zwOK)) } }

Result log

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