giornate.gno
2.42 Kb · 67 lines
1// Package giornate is the thin adapter that registers the Giornate engine
2// (p/…/sinopia/art/giornate/v1) with core: a fresco wall caught mid-work,
3// finished day-patches in pigment, the rest still red sinopia underdrawing.
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 giornate
9
10import (
11 art "gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia/art/giornate/v1"
12 "gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia/engine/v1"
13 "gno.land/r/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia3/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("g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06")
19
20func Author() address { return author }
21
22// AuthorFeeBps is the author's fee on sales of collections by other creators
23// (engine.Manifest.FeeBps; 0 for the author's own collections).
24// TODO(mainnet): product decision; 1% here so Onyx exercises the path.
25const AuthorFeeBps = 100
26
27// impl is zero-size and declared here, so core runs it with this realm's
28// authority (interrealm v2 borrow rule #1).
29type impl struct{}
30
31func (impl) Manifest() engine.Manifest {
32 m := art.Manifest()
33 m.Author = author
34 m.FeeBps = AuthorFeeBps
35 return m
36}
37
38func (impl) ValidateParams(params string) error { return art.ValidateParams(params) }
39
40func (impl) Traits(in engine.Input) []engine.Trait { return art.Traits(in) }
41
42func (impl) Render(in engine.Input) string { return art.Render(in) }
43
44// Register is an explicit call, not init: under the inert package policy
45// init runs inside the approver's transaction (RA B-1). Anyone may call it;
46// it can only ever register this realm, once.
47func Register(cur realm) string {
48 return core.RegisterEngine(cross(cur), impl{})
49}
50
51// RenderSeed and TraitsSeed are the plan-B surface (design §5.6): if
52// dynamic registration fails on chain, readers call the engine directly.
53func RenderSeed(seed, params string) string {
54 if err := art.ValidateParams(params); err != nil {
55 panic(err)
56 }
57 return art.SVGWith(seed, params)
58}
59
60func TraitsSeed(seed, params string) []engine.Trait {
61 if err := art.ValidateParams(params); err != nil {
62 panic(err)
63 }
64 in := engine.SampleInput()
65 in.Seed, in.Params = seed, params
66 return art.Traits(in)
67}