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.

render.gno

2.79 Kb · 69 lines
 1package upload
 2
 3import (
 4	"strconv"
 5	"strings"
 6
 7	"gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia/media/v1"
 8	"gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia/safe/v1"
 9)
10
11// cardSVG is the generic card: the registration sample (unique
12// fingerprint, CV-L3), RenderWith output, and the answer to any call that
13// is not core's real render of a revealed, bound token.
14const cardSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">` +
15	`<rect width="512" height="512" fill="#16130f"/>` +
16	`<rect x="20" y="20" width="472" height="472" fill="none" stroke="#b5332e" stroke-width="3"/>` +
17	`<text x="256" y="240" fill="#eeeeee" font-family="monospace" font-size="30" text-anchor="middle">Sinopia Upload</text>` +
18	`<text x="256" y="282" fill="#999999" font-family="monospace" font-size="15" text-anchor="middle">art from a sealed asset store</text>` +
19	`</svg>`
20
21// certificateSVG stands in for raster and IPFS art on core's TokenURI
22// path, which only carries allowlisted SVG (§10.1). Every text is
23// XML-escaped; the document stays far below MaxSVGBytes.
24func certificateSVG(r resolved) string {
25	a := r.art
26	title := a.Title
27	if title == "" {
28		title = "Artwork #" + strconv.FormatInt(a.Index+1, 10)
29	}
30	tier := "no tier"
31	if a.Tier != "" {
32		tier = a.Tier + " — creator tier"
33	}
34	where := strings.ToUpper(media.MimeName(a.Mime)) + " · " + sizeLabel(a.Size) + " · stored on-chain"
35	if a.Kind != media.KindChain {
36		where = "IPFS · " + strings.ToUpper(media.MimeName(a.Mime)) + " · " + sizeLabel(a.Size)
37	}
38	var b strings.Builder
39	b.WriteString(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">`)
40	b.WriteString(`<rect width="512" height="512" fill="#16130f"/>`)
41	b.WriteString(`<rect x="16" y="16" width="480" height="480" fill="none" stroke="#b5332e" stroke-width="2"/>`)
42	line := func(y int, size int, fill, text string) {
43		b.WriteString(`<text x="256" y="` + strconv.Itoa(y) + `" fill="` + fill + `" font-family="monospace" font-size="` +
44			strconv.Itoa(size) + `" text-anchor="middle">` + safe.XMLEscape(text) + `</text>`)
45	}
46	line(78, 24, "#eeeeee", r.info.Name)
47	line(116, 20, "#cccccc", "#"+r.tid)
48	line(196, 20, "#eeeeee", title)
49	line(232, 16, "#d9a441", tier)
50	if a.Editions > 1 {
51		line(262, 14, "#aaaaaa", "edition "+editionLabel(r.edition, a.Editions))
52	}
53	line(316, 14, "#aaaaaa", where)
54	if a.CID != "" {
55		line(340, 11, "#888888", a.CID)
56	}
57	line(364, 12, "#888888", "sha256 "+a.SHA256[:16]+"…")
58	line(452, 11, "#777777", "full image: "+selfPath+" TokenURI")
59	b.WriteString(`</svg>`)
60	return b.String()
61}
62
63func sizeLabel(n int64) string {
64	if n < 1024 {
65		return strconv.FormatInt(n, 10) + " B"
66	}
67	tenths := (n*10 + 512) / 1024
68	return strconv.FormatInt(tenths/10, 10) + "." + strconv.FormatInt(tenths%10, 10) + " KB"
69}