Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

genesis.gno

2.14 Kb · 61 lines
 1// Package genesis is the thin adapter that registers the genesis engine
 2// (p/…/art/art/genesis/v1) with core. It dogfoods the third-party path: core
 3// knows genesis only as this realm's package path plus an interface value.
 4//
 5// The adapter is stateless and has no admin: what it renders is fixed by
 6// the p/ package it imports, which can never change. Never mark this realm
 7// private (design §5.4: a re-deployable adapter could swap the art).
 8package genesis
 9
10import (
11	art "gno.land/p/g19dzk54hhsdc3gllpksuj6gu4a3e6fl8cr6rn4w/minhwa/art/genesis/v1"
12	"gno.land/p/g19dzk54hhsdc3gllpksuj6gu4a3e6fl8cr6rn4w/minhwa/engine/v1"
13	"gno.land/r/g19dzk54hhsdc3gllpksuj6gu4a3e6fl8cr6rn4w/minhwa2/core"
14)
15
16// author is the address that claims the engine in core (ClaimEngine).
17// TODO(mainnet): the platform's engine-author key, not the deployer.
18var author = address("g19dzk54hhsdc3gllpksuj6gu4a3e6fl8cr6rn4w")
19
20func Author() address { return author }
21
22// impl is zero-size and declared here, so core runs it with this realm's
23// authority (interrealm v2 borrow rule #1).
24type impl struct{}
25
26func (impl) Manifest() engine.Manifest {
27	m := art.Manifest()
28	m.Author = author
29	return m
30}
31
32func (impl) ValidateParams(params string) error { return art.ValidateParams(params) }
33
34func (impl) Traits(in engine.Input) []engine.Trait { return art.Traits(in) }
35
36func (impl) Render(in engine.Input) string { return art.Render(in) }
37
38// Register is an explicit call, not init: under the inert package policy
39// init runs inside the approver's transaction (RA B-1). Anyone may call it;
40// it can only ever register this realm, once.
41func Register(cur realm) string {
42	return core.RegisterEngine(cross(cur), impl{})
43}
44
45// RenderSeed and TraitsSeed are the plan-B surface (design §5.6): if
46// dynamic registration fails on chain, readers call the engine directly.
47func RenderSeed(seed, params string) string {
48	if err := art.ValidateParams(params); err != nil {
49		panic(err)
50	}
51	return art.SVG(seed)
52}
53
54func TraitsSeed(seed, params string) []engine.Trait {
55	in := engine.SampleInput()
56	in.Seed, in.Params = seed, params
57	if err := art.ValidateParams(params); err != nil {
58		panic(err)
59	}
60	return art.Traits(in)
61}