Skip to content Search Apps Documentation Source Content Run Reset Eval Playground 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.

rubrica.gno

2.31 Kb · 66 lines
 1// Package rubrica is the thin adapter that registers the Rubrica engine
 2// (p/…/sinopia/art/rubrica/v1) with core: core knows it only as this realm's
 3// package path plus an interface value.
 4//
 5// The adapter is stateless and has no admin: what it renders is fixed by the
 6// 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 rubrica
 9
10import (
11	art "gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia/art/rubrica/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).
24const AuthorFeeBps = 100
25
26// impl is zero-size and declared here, so core runs it with this realm's
27// authority (interrealm v2 borrow rule #1).
28type impl struct{}
29
30func (impl) Manifest() engine.Manifest {
31	m := art.Manifest()
32	m.Author = author
33	m.FeeBps = AuthorFeeBps
34	return m
35}
36
37func (impl) ValidateParams(params string) error { return art.ValidateParams(params) }
38
39func (impl) Traits(in engine.Input) []engine.Trait { return art.Traits(in) }
40
41func (impl) Render(in engine.Input) string { return art.Render(in) }
42
43// Register is an explicit call, not init: under the inert package policy
44// init runs inside the approver's transaction (RA B-1). Anyone may call it;
45// it can only ever register this realm, once.
46func Register(cur realm) string {
47	return core.RegisterEngine(cross(cur), impl{})
48}
49
50// RenderSeed and TraitsSeed are the plan-B surface (design §5.6): if
51// dynamic registration fails on chain, readers call the engine directly.
52func RenderSeed(seed, params string) string {
53	if err := art.ValidateParams(params); err != nil {
54		panic(err)
55	}
56	return art.SVG(seed, params)
57}
58
59func TraitsSeed(seed, params string) []engine.Trait {
60	if err := art.ValidateParams(params); err != nil {
61		panic(err)
62	}
63	in := engine.SampleInput()
64	in.Seed, in.Params = seed, params
65	return art.Traits(in)
66}