Transaction
23BC35D5867DF5…A2632B028B87
Block 923,232 · index 0 · indexed
Summary
- Hash
- 23BC35D5867DF58E981A7649DEB6CADFB5E7E4BB2B1566E24E28A2632B028B87
- Block
- 923,232
- Size
- 22325 bytes
- Gas used
- 30,894,116 / 69,114,200
- Fee
- 207342 ugnot
- Status
- success
Messages
- Attached funds
- 9000000 ugnot
Arguments · 11
- #1eggling
- #2README.md
- #3# Eggling > ⚠️ **Experimental — generated with no human supervision** by the daily MCP pipeline to exercise gno tooling. Not audited. See [r/moul/x/daily](https://github.com/moul/gno-contracts/blob/main/r/moul/x/daily/README.md). --- Plant an on-chain egg, let it incubate for at least 20 blocks, then hatch it — how long you waited plus a bit of sealed-in luck decides whether you get a Common Slime or a Legendary Glimmer. Train hatched creatures for XP and levels, and rename them once they've hatched. It's a lighter, luck-and-patience spin on yesterday's tamagotchi: no hunger or death, just the thrill of the hatch and a slow climb of levels. Built for gno 0.9. ## What changed in v1 Identical behaviour to [`v0`](https://github.com/moul/gno-contracts/tree/4f2df83869b80470eb81c48a82fdbe82256b8113/r/moul/x/daily/eggling) apart from rendering, which now goes through [`p/moul/kit/ui`](/p/moul/kit/ui/v0) instead of the local `escapeInline`, `shortAddr` 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. The rendering change means the output differs from v0, which under this repo's versioning rule is a compatibility change, hence a new version rather than an edit in place. `v0` 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:** [](https://gnoscope.com/realm/r/moul/x/daily/eggling/v1) [](https://gnoscope.com/realm/r/moul/x/daily/eggling/v1) [](https://gnoscope.com/realm/r/moul/x/daily/eggling/v1) [](https://gnoscope.com/realm/r/moul/x/daily/eggling/v1) **Dependency graph:**  > 🧪 **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 -->
- #4eggling.gno
- #5// Package eggling is an on-chain egg incubator and creature collector. // Plant an egg, let it incubate for a minimum number of blocks, then Hatch // it: the longer you waited (and a little luck, seeded from the egg's own // history) decides the rarity of the creature you get. Train hatched // creatures to level them up. Unlike a tamagotchi there's nothing to feed // or lose to neglect — eggling is about patience and the luck of the // hatch, not survival. package eggling import ( "crypto/sha256" "encoding/hex" "sort" "strconv" "strings" "chain/markdown" "chain/runtime" "gno.land/p/moul/kit/ui/v0" "gno.land/p/nt/avl/v0" ) // minIncubation is the minimum number of blocks an egg must sit before it // can hatch. const minIncubation int64 = 20 // waitCap is the incubation-time bonus cap (in blocks) used by rarityTier, // so waiting forever doesn't guarantee a legendary — it just improves odds. const waitCap int64 = 200 var speciesNames = [...]string{ "Slime", "Sprout", "Ember", "Pebble", "Breeze", "Glimmer", "Shade", "Coral", } var rarityNames = [...]string{"Common", "Uncommon", "Rare", "Legendary"} var rarityEmoji = [...]string{"⚪", "🟢", "🔵", "🟡"} // egg is the persisted record for one planted egg, hatched or not. type egg struct { ID string Owner address PlantedAt int64 Hatched bool Species string RarityTier int Name string XP int Level int } var ( eggs avl.Tree // id string -> *egg nextID int totalPlanted int totalHatched int rarityCounts [4]int ) func get(id string) (*egg, bool) { v := eggs.Get(id) if v == nil { return nil, false } return v.(*egg), true } // hashSeed hashes the given parts (joined with ":") to a deterministic hex // digest. Used to derive an egg's species and rarity roll from facts // already fixed at plant time, so nobody — not even the owner — can game // the outcome after the fact. func hashSeed(parts ...string) string { sum := sha256.Sum256([]byte(strings.Join(parts, ":"))) return hex.EncodeToString(sum[:]) } // seedBytes pulls the first two bytes out of a hex digest for use as two // independent 0-255 rolls (species pick, rarity roll). func seedBytes(seedHex string) (byte, byte) { raw, err := hex.DecodeString(seedHex) if err != nil || len(raw) < 2 { return 0, 0 } return raw[0], raw[1] } // rarityTier turns a 0-255 roll plus the blocks waited into a tier index // 0..3 (common..legendary). Waiting longer raises the effective score, so // patience improves your odds, but a bad roll can still land common even // after a long wait, and a lucky roll can hatch rare almost immediately. func rarityTier(roll uint8, waitBlocks int64) int { bonus := waitBlocks if bonus > waitCap { bonus = waitCap } score := int(roll) + int(bonus)/2 switch { case score >= 300: return 3 case score >= 220: return 2 case score >= 140: return 1 default: return 0 } } // plant is the non-crossing core of PlantEgg. func plant(owner address, height int64) *egg { nextID++ id := strconv.Itoa(nextID) e := &egg{ID: id, Owner: owner, PlantedAt: height} eggs.Set(id, e) totalPlanted++ return e } // PlantEgg starts incubating a new egg for the caller. Returns its ID. func PlantEgg(cur realm) string { if !cur.IsCurrent() { panic("spoofed realm") } e := plant(cur.Previous().Address(), runtime.ChainHeight()) return "🥚 planted egg #" + e.ID + " — incubate at least " + strconv.Itoa(int(minIncubation)) + " blocks, then Hatch(\"" + e.ID + "\")" } // hatch is the non-crossing core of Hatch. func hatch(e *egg, height int64) string { if e.Hatched { panic("egg #" + e.ID + " already hatched into a " + e.Species) } wait := height - e.PlantedAt if wait < minIncubation { panic("egg #" + e.ID + " needs " + strconv.Itoa(int(minIncubation-wait)) + " more blocks to incubate") } seed := hashSeed(e.ID, e.Owner.String(), strconv.FormatInt(e.PlantedAt, 10)) rarityRoll, speciesRoll := seedBytes(seed) tier := rarityTier(rarityRoll, wait) species := speciesNames[int(speciesRoll)%len(speciesNames)] e.Hatched = true e.Species = species e.RarityTier = tier e.Name = species e.Level = 1 rarityCounts[tier]++ totalHatched++ return rarityEmoji[tier] + " egg #" + e.ID + " hatched into a " + rarityNames[tier] + " " + species + "!" } // Hatch hatches an incubated egg the caller owns. func Hatch(cur realm, id string) string { if !cur.IsCurrent() { panic("spoofed realm") } e, ok := get(id) if !ok { panic("no such egg #" + id) } if e.Owner != cur.Previous().Address() { panic("only the owner can hatch egg #" + id) } return hatch(e, runtime.ChainHeight()) } // train is the non-crossing core of Train. func train(e *egg) string { if !e.Hatched { panic("egg #" + e.ID + " hasn't hatched yet") } e.XP += 10 newLevel := e.XP/50 + 1 leveled := newLevel > e.Level e.Level = newLevel msg := e.Name + " gained 10 XP (" + strconv.Itoa(e.XP) + " total)" if leveled { msg += " and reached level " + strconv.Itoa(e.Level) + "!" } return msg } // Train gives a hatched creature the caller owns some experience, leveling // it up every 50 XP. func Train(cur realm, id string) string { if !cur.IsCurrent() { panic("spoofed realm") } e, ok := get(id) if !ok { panic("no such egg #" + id) } if e.Owner != cur.Previous().Address() { panic("only the owner can train egg #" + id) } return train(e) } // rename is the non-crossing core of Rename. func rename(e *egg, name string) string { if !e.Hatched { panic("egg #" + e.ID + " hasn't hatched yet — nothing to name") } name = strings.TrimSpace(name) if strings.TrimSpace(markdown.StripBidiAndZeroWidth(name)) == "" { panic("name cannot be empty") } old := e.Name e.Name = name return old + " renamed to " + name } // Rename gives a hatched creature the caller owns a custom name. func Rename(cur realm, id string, name string) string { if !cur.IsCurrent() { panic("spoofed realm") } e, ok := get(id) if !ok { panic("no such egg #" + id) } if e.Owner != cur.Previous().Address() { panic("only the owner can rename egg #" + id) } return rename(e, name) } // byIDNumeric orders eggs by their numeric ID, ascending. type byIDNumeric []*egg func (r byIDNumeric) Len() int { return len(r) } func (r byIDNumeric) Swap(i, j int) { r[i], r[j] = r[j], r[i] } func (r byIDNumeric) Less(i, j int) bool { a, _ := strconv.Atoi(r[i].ID) b, _ := strconv.Atoi(r[j].ID) return a < b } func allEggs() []*egg { var rows []*egg eggs.Iterate("", "", func(_ string, v any) bool { rows = append(rows, v.(*egg)) return false }) sort.Stable(byIDNumeric(rows)) return rows } func renderHome() string { var b strings.Builder b.WriteString("# 🥚 Eggling\n\n") b.WriteString("An on-chain egg incubator. `PlantEgg()` to start one, wait at least " + strconv.Itoa(int(minIncubation)) + " blocks, then `Hatch(id)` — the longer you " + "waited (plus a little sealed-in luck) decides the rarity of the creature you get. " + "`Train(id)` levels a hatched creature up; `Rename(id, name)` gives it a name.\n\n") b.WriteString("- Eggs planted: " + strconv.Itoa(totalPlanted) + "\n") b.WriteString("- Creatures hatched: " + strconv.Itoa(totalHatched) + "\n") if totalHatched > 0 { for tier := 3; tier >= 0; tier-- { if rarityCounts[tier] > 0 { b.WriteString(" - " + rarityEmoji[tier] + " " + rarityNames[tier] + ": " + strconv.Itoa(rarityCounts[tier]) + "\n") } } } rows := allEggs() b.WriteString("\n## Eggs\n\n") if len(rows) == 0 { b.WriteString("_None planted yet. Be the first!_\n") return b.String() } b.WriteString("| ID | Owner | Status | Level |\n") b.WriteString("| :--- | :--- | :--- | ---: |\n") for _, e := range rows { status := "🥚 incubating" level := "-" if e.Hatched { status = rarityEmoji[e.RarityTier] + " " + ui.Inline(e.Name) + " (" + rarityNames[e.RarityTier] + " " + e.Species + ")" level = strconv.Itoa(e.Level) } b.WriteString("| #" + e.ID + " | " + ui.Addr(e.Owner) + " | " + status + " | " + level + " |\n") } b.WriteString("\n_View a single egg at this realm's path plus its ID (e.g. `.../eggling:3`), " + "or one owner's eggs plus their address._\n") return b.String() } func renderEgg(id string, height int64) string { e, ok := get(id) if !ok { return "# Egg #" + ui.Inline(id) + "\n\nNo such egg.\n" } var b strings.Builder if !e.Hatched { wait := height - e.PlantedAt b.WriteString("# 🥚 Egg #" + e.ID + "\n\n") b.WriteString("- Owner: `" + e.Owner.String() + "`\n") b.WriteString("- Planted at block: " + strconv.FormatInt(e.PlantedAt, 10) + "\n") if wait < minIncubation { b.WriteString("- Ready to hatch in: " + strconv.FormatInt(minIncubation-wait, 10) + " more blocks\n") } else { b.WriteString("- Ready to hatch now — call `Hatch(\"" + e.ID + "\")`\n") } return b.String() } b.WriteString("# " + rarityEmoji[e.RarityTier] + " " + e.Name + "\n\n") b.WriteString("- Owner: `" + e.Owner.String() + "`\n") b.WriteString("- Species: " + e.Species + "\n") b.WriteString("- Rarity: " + rarityNames[e.RarityTier] + "\n") b.WriteString("- Level: " + strconv.Itoa(e.Level) + " (" + strconv.Itoa(e.XP) + " XP)\n") return b.String() } func renderOwner(rawAddr string) string { owner := address(strings.TrimSpace(rawAddr)) safe := ui.Inline(owner.String()) var b strings.Builder b.WriteString("# Eggs owned by " + safe + "\n\n") found := false for _, e := range allEggs() { if e.Owner != owner { continue } found = true if e.Hatched { b.WriteString("- #" + e.ID + ": " + rarityEmoji[e.RarityTier] + " " + ui.Inline(e.Name) + " — " + rarityNames[e.RarityTier] + " " + e.Species + ", level " + strconv.Itoa(e.Level) + "\n") } else { b.WriteString("- #" + e.ID + ": 🥚 incubating\n") } } if !found { b.WriteString("_No eggs found for this address._\n") } return b.String() } // Render shows the full egg list at "", a single egg's detail when path is // a numeric ID, or one owner's eggs when path is a bech32 address. func Render(path string) string { path = strings.TrimPrefix(strings.TrimSpace(path), "/") if path == "" { return renderHome() } if _, err := strconv.Atoi(path); err == nil { return renderEgg(path, runtime.ChainHeight()) } return renderOwner(path) }
- #6eggling_test.gno
- #7package eggling import ( "strings" "testing" "gno.land/p/nt/avl/v0" "gno.land/p/nt/testutils/v0" ) func resetState() { eggs = avl.Tree{} nextID = 0 totalPlanted = 0 totalHatched = 0 rarityCounts = [4]int{} } func TestHashSeedDeterministicAndSensitive(t *testing.T) { a := hashSeed("1", "g1alice", "100") b := hashSeed("1", "g1alice", "100") if a != b { t.Fatal("hashSeed should be deterministic for the same inputs") } if a == hashSeed("2", "g1alice", "100") { t.Fatal("different egg IDs should hash differently") } if len(a) != 64 { t.Fatalf("hashSeed length = %d, want 64 (hex sha256)", len(a)) } } func TestSeedBytesFromKnownDigest(t *testing.T) { // sha256("") = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 r1, r2 := seedBytes(hashSeed("")) if r1 != 0xe3 || r2 != 0xb0 { t.Fatalf("seedBytes = (%x, %x), want (e3, b0)", r1, r2) } } func TestRarityTierBoundaries(t *testing.T) { cases := []struct { roll uint8 wait int64 want int }{ {0, 0, 0}, // score 0 -> common {139, 0, 0}, // score 139 -> common {140, 0, 1}, // score 140 -> uncommon {219, 0, 1}, // score 219 -> uncommon {220, 0, 2}, // score 220 -> rare {255, 0, 2}, // score 255 -> rare (no wait bonus) {255, 200, 3}, // score 355 -> legendary (max wait bonus) {0, 200, 0}, // score 100 -> still common, roll matters too } for _, c := range cases { if got := rarityTier(c.roll, c.wait); got != c.want { t.Fatalf("rarityTier(%d, %d) = %d, want %d", c.roll, c.wait, got, c.want) } } } func TestRarityTierCapsWaitBonus(t *testing.T) { // waitCap is 200; waiting 1000 blocks should score identically to // waiting exactly 200. if rarityTier(50, 1000) != rarityTier(50, 200) { t.Fatal("rarityTier should cap the wait bonus at waitCap") } } func TestPlantAssignsSequentialIDs(t *testing.T) { resetState() alice := testutils.TestAddress("alice") e1 := plant(alice, 100) e2 := plant(alice, 101) if e1.ID != "1" || e2.ID != "2" { t.Fatalf("expected sequential IDs 1, 2; got %s, %s", e1.ID, e2.ID) } if totalPlanted != 2 { t.Fatalf("totalPlanted = %d, want 2", totalPlanted) } } func TestHatchTooEarlyPanics(t *testing.T) { resetState() alice := testutils.TestAddress("alice") e := plant(alice, 100) defer func() { if r := recover(); r == nil { t.Fatal("expected panic hatching before minIncubation blocks pass") } }() hatch(e, 100+minIncubation-1) } func TestHatchTwicePanics(t *testing.T) { resetState() alice := testutils.TestAddress("alice") e := plant(alice, 100) hatch(e, 100+minIncubation) defer func() { if r := recover(); r == nil { t.Fatal("expected panic hatching an already-hatched egg") } }() hatch(e, 100+minIncubation) } func TestHatchSetsSpeciesAndCountsStats(t *testing.T) { resetState() alice := testutils.TestAddress("alice") e := plant(alice, 100) hatch(e, 100+minIncubation) if !e.Hatched { t.Fatal("expected egg to be hatched") } if e.Species == "" { t.Fatal("expected a species to be assigned") } if e.Level != 1 { t.Fatalf("expected level 1 on hatch, got %d", e.Level) } if totalHatched != 1 { t.Fatalf("totalHatched = %d, want 1", totalHatched) } if rarityCounts[e.RarityTier] != 1 { t.Fatalf("expected rarityCounts[%d] = 1, got %d", e.RarityTier, rarityCounts[e.RarityTier]) } } func TestTrainBeforeHatchPanics(t *testing.T) { resetState() alice := testutils.TestAddress("alice") e := plant(alice, 100) defer func() { if r := recover(); r == nil { t.Fatal("expected panic training an unhatched egg") } }() train(e) } func TestTrainAccumulatesXPAndLevelsUp(t *testing.T) { resetState() alice := testutils.TestAddress("alice") e := plant(alice, 100) hatch(e, 100+minIncubation) for i := 0; i < 5; i++ { train(e) } if e.XP != 50 { t.Fatalf("XP = %d, want 50", e.XP) } if e.Level != 2 { t.Fatalf("Level = %d, want 2", e.Level) } } func TestRenameRequiresHatchedAndNonEmpty(t *testing.T) { resetState() alice := testutils.TestAddress("alice") e := plant(alice, 100) func() { defer func() { if r := recover(); r == nil { t.Fatal("expected panic renaming an unhatched egg") } }() rename(e, "Sparky") }() hatch(e, 100+minIncubation) rename(e, "Sparky") if e.Name != "Sparky" { t.Fatalf("Name = %q, want Sparky", e.Name) } defer func() { if r := recover(); r == nil { t.Fatal("expected panic renaming with an empty name") } }() rename(e, " ") } func TestRenderShowsEmptyThenEggThenOwner(t *testing.T) { resetState() if !strings.Contains(Render(""), "None planted yet") { t.Fatal("expected empty-state placeholder") } alice := testutils.TestAddress("alice") e := plant(alice, 100) hatch(e, 100+minIncubation) home := Render("") if !strings.Contains(home, "#"+e.ID) { t.Fatal("expected egg row in home listing") } detail := Render(e.ID) if !strings.Contains(detail, "Rarity") { t.Fatal("expected detail card to show rarity") } owned := Render(alice.String()) if !strings.Contains(owned, e.Name) { t.Fatal("expected owner view to list the creature by name") } } // TestFullLifecycleViaCrossingCalls smoke-tests the exported, realm-crossing // entry points end to end (as an on-chain caller would invoke them). func TestFullLifecycleViaCrossingCalls(cur realm, t *testing.T) { resetState() alice := testutils.TestAddress("alice") testing.SetRealm(testing.NewUserRealm(alice)) msg := PlantEgg(cross(cur)) if !strings.Contains(msg, "planted egg #1") { t.Fatalf("expected plant confirmation, got %q", msg) } testing.SkipHeights(minIncubation) hatchMsg := Hatch(cross(cur), "1") if !strings.Contains(hatchMsg, "hatched into a") { t.Fatalf("expected hatch confirmation, got %q", hatchMsg) } trainMsg := Train(cross(cur), "1") if !strings.Contains(trainMsg, "gained 10 XP") { t.Fatalf("expected train confirmation, got %q", trainMsg) } renameMsg := Rename(cross(cur), "1", "Buddy") if !strings.Contains(renameMsg, "renamed to Buddy") { t.Fatalf("expected rename confirmation, got %q", renameMsg) } e, ok := get("1") if !ok || e.Name != "Buddy" || e.XP != 10 { t.Fatalf("unexpected final state: %+v", e) } } // TestOnlyOwnerCanHatch checks that another address can't hatch someone // else's egg. func TestOnlyOwnerCanHatch(cur realm, t *testing.T) { resetState() alice := testutils.TestAddress("alice") bob := testutils.TestAddress("bob") testing.SetRealm(testing.NewUserRealm(alice)) PlantEgg(cross(cur)) testing.SkipHeights(minIncubation) testing.SetRealm(testing.NewUserRealm(bob)) rec := revive(func() { Hatch(cross(cur), "1") }) if rec == nil { t.Fatal("expected panic hatching someone else's egg") } }
- #8gnomod.toml
- #9module = "gno.land/r/moul/x/daily/eggling/v1" gno = "0.9" private = true [source] repository = "https://github.com/moul/gno-contracts" path = "r/moul/x/daily/eggling" revision = "507056d812b505ad16a009f0d60786644ceeb19d"
- #10zz_zerowidth_test.gno
- #11package eggling 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 zwPanics(f func()) (p bool) { defer func() { if recover() != nil { p = true } }() f() return false } func TestZeroWidthNameIsRefused(t *testing.T) { resetState() defer resetState() e := plant(testutils.TestAddress("alice"), 100) hatch(e, 100+minIncubation) rename(e, "Sparky") for _, s := range zwBlank { if !zwPanics(func() { rename(e, s) }) { t.Errorf("rename accepted name %q, which the render strips to blank", s) } } if e.Name != "Sparky" { t.Fatalf("Name = %q after blank renames, want Sparky", e.Name) } for _, s := range zwOK { if zwPanics(func() { rename(e, s) }) { t.Errorf("rename refused name %q, which renders as text", s) } } }
Result log
msg:0,success:true,log:,events:[]