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