Transaction

5A39E4CD4026AE…61A84D90E218

Block 923,356 · index 0 · indexed

Summary

Hash
5A39E4CD4026AE66433CBF9144AC712FCFCAE6F3AC21C5D8181A61A84D90E218
Block
923,356
Size
14391 bytes
Gas used
19,456,990 / 48,467,600
Fee
145402 ugnot
Status
success

Messages

#1AddPackagegno.land/r/moul/x/daily/blog/v115 arguments
Attached funds
6000000 ugnot

Arguments · 15

  1. #1blog
  2. #2README.md
  3. #3# Personal Blog > ⚠️ **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 multi-author on-chain blog realm for gno.land. Anyone can publish a post; each post records its author (the calling address) and the block height at which it was published. Posts are stored persistently and rendered newest-first, with a dedicated page for each post's full text. **Realm path:** `gno.land/r/moul/x/daily/blog/v1` ## Example calls Publish a post (state-mutating, crossing function): ``` gnokey maketx call -pkgpath "gno.land/r/moul/x/daily/blog/v1" \ -func Publish -args "My first post" -args "Hello, gno.land!" \ -gas-fee 20000ugnot -gas-wanted 2000000 -broadcast -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 KEY ``` Read views (no transaction needed): - Root — list all posts, newest first: render `gno.land/r/moul/x/daily/blog/v1` - Single post by id: render `gno.land/r/moul/x/daily/blog/v1:/0` `PostCount()` returns the total number of published posts. ## 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. Ids stay plain integers, and `Post` loses its `ID` field, which the store now owns. Two things a reader will notice: - **Post ids now start at 1.** `v0` handed out 0 for the first post; the store never assigns 0, so the zero id stays usable as "absent". - **`/0` is no longer a post path.** It is rejected as invalid rather than looked up, along with anything else that is not a plain decimal. 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/blog) 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/blog/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/blog/v1) [![transactions](https://gnoscope.com/_badges/shield/txs/r/moul/x/daily/blog/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/blog/v1) [![unique callers](https://gnoscope.com/_badges/shield/users/r/moul/x/daily/blog/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/blog/v1) [![deployed revision](https://gnoscope.com/_badges/shield/version/r/moul/x/daily/blog/v1?network=mainnet)](https://gnoscope.com/realm/r/moul/x/daily/blog/v1) **Dependency graph:** ![gno.land/r/moul/x/daily/blog/v1 dependency graph](https://raw.githubusercontent.com/moul/gno-contracts/main/_assets/gno.land/r/moul/x/daily/blog/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. #4blog.gno
  5. #5// Package blog is a multi-author on-chain blog realm for gno.land. // // Any caller can Publish a post; posts are stored persistently and rendered // newest-first. Each post records its author (the calling address) and the // block height at which it was published. package blog import ( "strconv" "strings" "chain" "chain/markdown" "chain/runtime" "gno.land/p/moul/kit/store/v0" "gno.land/p/moul/kit/ui/v0" "gno.land/p/moul/md/v0" ) // selfPath is this realm's own page. A root-relative link resolves against // the domain, not the realm, so every link back into it names it in full. const selfPath = "/r/moul/x/daily/blog/v1" // Post is a single blog entry. It carries no id field: the id belongs to the // store, which hands it back on lookup and iteration. type Post struct { Title string Body string Author address Height int64 } // posts holds every published post. The store keys by seqid, so iteration is // in publication order for any number of posts; v0 kept its own nextID plus a // key() that zero-padded to width 12 and stopped ordering past it. var posts = store.Named("post") // Publish creates a new post authored by the caller and returns its id. // It is a state-mutating exported function, so it takes `cur realm`. func Publish(cur realm, title string, body string) int { if !cur.IsCurrent() { panic("blog: spoofed realm") } title = strings.TrimSpace(title) body = strings.TrimSpace(body) if strings.TrimSpace(markdown.StripBidiAndZeroWidth(title)) == "" { panic("blog: title must not be empty") } if strings.TrimSpace(markdown.StripBidiAndZeroWidth(body)) == "" { panic("blog: body must not be empty") } author := cur.Previous().Address() id := posts.Add(&Post{ Title: title, Body: body, Author: author, Height: runtime.ChainHeight(), }) chain.Emit( "PostPublished", "id", id.String(), "author", author.String(), ) return int(id) } // PostCount returns the number of published posts. func PostCount() int { return posts.Len() } // Render lists all posts newest-first at the root, or a single post's full // text at path "/<id>". Render is NOT a crossing function. func Render(path string) string { path = strings.TrimSpace(path) if path == "" || path == "/" { return renderList() } idStr := strings.TrimPrefix(path, "/") id, ok := store.ParseID(idStr) if !ok { return "# Not found\n\nInvalid post path: " + md.InlineCode(path) + "\n\n[← back](" + selfPath + ")\n" } v, ok := posts.Get(id) if !ok { return "# Not found\n\nNo post with id " + idStr + ".\n\n[← back](" + selfPath + ")\n" } return renderPost(v.(*Post)) } func renderList() string { var b strings.Builder b.WriteString("# 📝 Blog\n\n") if posts.Len() == 0 { b.WriteString("_No posts yet. Be the first to `Publish`._\n") return b.String() } b.WriteString(strconv.Itoa(posts.Len()) + " post(s), newest first.\n\n") // Ids ascend with publication, so reverse iteration is newest-first. posts.EachReverse(func(id store.ID, v any) { p := v.(*Post) b.WriteString("## [") b.WriteString(ui.Inline(p.Title)) b.WriteString("](" + selfPath + ":/") b.WriteString(id.String()) b.WriteString(")\n\n") b.WriteString("by `") b.WriteString(p.Author.String()) b.WriteString("` · height ") b.WriteString(strconv.FormatInt(p.Height, 10)) b.WriteString("\n\n") b.WriteString(ui.Excerpt(strings.TrimSpace(p.Body), 140)) b.WriteString("\n\n---\n\n") }) return b.String() } func renderPost(p *Post) string { var b strings.Builder b.WriteString("# ") b.WriteString(ui.Inline(p.Title)) b.WriteString("\n\n") b.WriteString("by `") b.WriteString(p.Author.String()) b.WriteString("` · height ") b.WriteString(strconv.FormatInt(p.Height, 10)) b.WriteString("\n\n") // Anyone may publish, so the body is the caller's text, not this realm's // markdown: each line is escaped, and a blank line still breaks a paragraph. for i, line := range strings.Split(p.Body, "\n") { if i > 0 { b.WriteString(" \n") } b.WriteString(ui.Inline(line)) } b.WriteString("\n\n---\n\n[← back to all posts](" + selfPath + ")\n") return b.String() }
  6. #6blog_test.gno
  7. #7package blog import ( "strings" "testing" "gno.land/p/nt/testutils/v0" "gno.land/p/nt/uassert/v0" ) func TestPublishAndRender(cur realm, t *testing.T) { alice := testutils.TestAddress("alice") bob := testutils.TestAddress("bob") testing.SetRealm(testing.NewUserRealm(alice)) // Ids start at 1 in v1: the store never assigns 0, so the zero id stays // usable as "absent". v0 handed out 0 for the first post. id0 := Publish(cross(cur), "First Post", "Hello from alice.") uassert.Equal(t, 1, id0) testing.SetRealm(testing.NewUserRealm(bob)) id1 := Publish(cross(cur), "Second Post", "A longer body\nwith a newline from bob.") uassert.Equal(t, 2, id1) uassert.Equal(t, 2, PostCount()) // Root render lists both, newest (bob's) first. list := Render("") uassert.True(t, strings.Contains(list, "First Post"), "list has first post") uassert.True(t, strings.Contains(list, "Second Post"), "list has second post") uassert.True(t, strings.Index(list, "Second Post") < strings.Index(list, "First Post"), "newest post appears first") uassert.True(t, strings.Contains(list, alice.String()), "list shows alice author") // Single-post render shows full body + back link. single := Render("/2") uassert.True(t, strings.Contains(single, "newline from bob"), "full body shown") uassert.True(t, strings.Contains(single, "← back"), "back link present") // Unknown id. uassert.True(t, strings.Contains(Render("/99"), "Not found"), "missing post handled") // Id 0 is never assigned, so the path is rejected rather than looked up. uassert.True(t, strings.Contains(Render("/0"), "Invalid post path"), "id 0 is not a post") uassert.True(t, strings.Contains(Render("/abc"), "Invalid post path"), "a non-numeric path is rejected") } func TestPublishEmptyTitleAborts(cur realm, t *testing.T) { carol := testutils.TestAddress("carol") testing.SetRealm(testing.NewUserRealm(carol)) uassert.AbortsWithMessage(t, cur, "blog: title must not be empty", func() { Publish(cross(cur), " ", "some body") }) uassert.AbortsWithMessage(t, cur, "blog: body must not be empty", func() { Publish(cross(cur), "a title", "") }) }
  8. #8gnomod.toml
  9. #9module = "gno.land/r/moul/x/daily/blog/v1" gno = "0.9" private = true [source] repository = "https://github.com/moul/gno-contracts" path = "r/moul/x/daily/blog" revision = "507056d812b505ad16a009f0d60786644ceeb19d"
  10. #10zz_escape_test.gno
  11. #11package blog import ( "strings" "testing" "gno.land/p/nt/testutils/v0" "gno.land/p/moul/md/v0" "gno.land/p/nt/uassert/v0" ) // Anyone may publish, so a title or a body is the caller's text and must not // become live markdown on the realm's own pages. func TestTitleAndBodyAreEscaped(cur realm, t *testing.T) { testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("escaper"))) id := Publish(cross(cur), "[claim](https://evil.example)", "line one\n[claim](https://evil.example)") uassert.False(t, strings.Contains(Render(""), "[claim](https://evil.example)"), Render("")) page := Render("/" + itoaTest(id)) uassert.False(t, strings.Contains(page, "[claim](https://evil.example)"), page) } // A path that names nothing is echoed back on the not-found page. It is the // visitor's text, so a backtick in it must not close a code span and let a // link through. func TestNotFoundPathIsEscaped(t *testing.T) { out := Render("/x` [claim](https://evil.example) `") // Still there, but inside a span md.InlineCode widened past its backticks. uassert.True(t, strings.Contains(out, md.InlineCode("/x` [claim](https://evil.example) `")), out) }
  12. #12zz_links_test.gno
  13. #13package blog import ( "strings" "testing" "gno.land/p/nt/testutils/v0" "gno.land/p/nt/uassert/v0" ) // Every link the realm renders names its own absolute path. A dead link here // once read /r/REPLACE_ADDR/blog, and a test that only checked "a back link // exists" passed against it. func TestLinksNameThisRealm(cur realm, t *testing.T) { testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("linker"))) id := Publish(cross(cur), "Linked", "body") idx := Render("") uassert.True(t, strings.Contains(idx, "](/r/moul/x/daily/blog/v1:/"), idx) page := Render("/" + itoaTest(id)) uassert.True(t, strings.Contains(page, "(/r/moul/x/daily/blog/v1)"), page) } func itoaTest(n int) string { if n == 0 { return "0" } s := "" for n > 0 { s = string(rune(byte(n%10)+byte(48))) + s n /= 10 } return s }
  14. #14zz_zerowidth_test.gno
  15. #15package blog 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 TestZeroWidthTitleAndBodyAreRefused(cur realm, t *testing.T) { testing.SetRealm(testing.NewUserRealm(testutils.TestAddress("alice"))) before := PostCount() for _, s := range zwBlank { if revive(func() { Publish(cross(cur), s, "body") }) == nil { t.Errorf("Publish accepted title %q, which the render strips to blank", s) } if revive(func() { Publish(cross(cur), "title", s) }) == nil { t.Errorf("Publish accepted body %q, which the render strips to blank", s) } } for _, s := range zwOK { if r := revive(func() { Publish(cross(cur), s, s) }); r != nil { t.Errorf("Publish refused title and body %q: %v", s, r) } } if got := PostCount() - before; got != len(zwOK) { t.Errorf("%d post(s) published, want %d", got, len(zwOK)) } }

Result log

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