tokens.gno
20.48 Kb · 643 lines
1package core
2
3import (
4 "chain"
5 "encoding/base64"
6
7 "gno.land/p/nt/avl/v0"
8 "gno.land/p/nt/grc721/royalty/v0"
9 "gno.land/p/nt/grc721/v0"
10
11 "gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia4/engine/v2"
12 "gno.land/p/g1jz6j9hj6rdf5ltl2kcrpa4jwtdh3w30z0yul06/sinopia4/safe/v2"
13)
14
15// tokenState is the per-collection data the transfer hook needs. It is
16// shared by the collection and its lockExt, so neither points at the other.
17//
18// Per-token state is packed (storage-cost-analysis P1+P3): one fixed-width
19// entry of packEntry bytes per token, packSlots tokens per avl key. Entry =
20// four big-endian uint32 fields: mint height, transfer count (H-2), height
21// of the last transfer, and the token's approval nonce (SA-L3). A mint
22// appends entries in tid order (a new key every packSlots tokens, ~2 KB the
23// minter of that bucket's first token pays); a transfer or an Approve only
24// rewrites bytes in place, so neither creates a storage object.
25//
26// First owners (I-20) are run-length records in a second tree with the
27// same bucket keys: one record of ownerRec bytes (the token's slot in the
28// bucket, then the 40-character address) for each run of consecutive
29// tokens minted to one address. A mint batch adds at most one record per
30// bucket it touches, and none when it continues the bucket's last run, so
31// a batch of n costs 41 bytes, not 40 n; a bucket holds at most
32// packSlots records. Neither a transfer nor an approval touches it.
33type tokenState struct {
34 final bool
35 soulbound bool // non-transferable collection (I-20)
36 pack avl.Tree // safe.PadInt((tid-1)/packSlots, packKeyWidth) -> string of packed entries
37 owners avl.Tree // same key -> string of first-owner run records
38}
39
40const (
41 packSlots = 128
42 packFields = 4
43 packEntry = packFields * 4
44 packKeyWidth = 3 // MaxSupplyCap/packSlots < 1000
45
46 addrLen = 40 // a bech32 "g1…" address of 20 bytes
47 ownerRec = 1 + addrLen
48
49 fieldMintHeight = 0
50 fieldMoves = 1
51 fieldLastMove = 2
52 fieldNonce = 3
53)
54
55func packKey(tid int64) string { return safe.PadInt((tid-1)/packSlots, packKeyWidth) }
56
57// u32 encodes v as 4 big-endian bytes. Heights stay below 2^32 for ~470
58// years of 3.5 s blocks; 2^32 transfers or approvals of one token cannot
59// happen, so overflow is a hard error rather than a wrap.
60func u32(v int64) string {
61 if v < 0 || v > 0xFFFFFFFF {
62 panic("token state: value out of uint32 range")
63 }
64 return string([]byte{byte(v >> 24), byte(v >> 16), byte(v >> 8), byte(v)})
65}
66
67// appendTokens adds zeroed entries (mint height h) for first..last, which
68// must directly follow the last stored token.
69func (st *tokenState) appendTokens(first, last, h int64) {
70 entry := u32(h) + u32(0) + u32(0) + u32(0)
71 for tid := first; tid <= last; {
72 k := packKey(tid)
73 v, _ := st.pack.Get(k).(string)
74 if int64(len(v)) != ((tid-1)%packSlots)*packEntry {
75 panic("token state: tokens must be appended in order")
76 }
77 for ; tid <= last && packKey(tid) == k; tid++ {
78 v += entry
79 }
80 st.pack.Set(k, v)
81 }
82}
83
84// appendOwners records to as the first owner of first..last (appended in
85// tid order, right after appendTokens of the same range).
86func (st *tokenState) appendOwners(first, last int64, to address) {
87 a := to.String()
88 if len(a) != addrLen {
89 panic("token state: unexpected address length")
90 }
91 for tid := first; tid <= last; {
92 k := packKey(tid)
93 v, _ := st.owners.Get(k).(string)
94 if len(v) < ownerRec || v[len(v)-addrLen:] != a {
95 st.owners.Set(k, v+string([]byte{byte((tid-1)%packSlots)})+a)
96 }
97 tid = (tid-1)/packSlots*packSlots + packSlots + 1 // first tid of the next bucket
98 }
99}
100
101// firstOwner is the address token tid was minted to, or "" for a token
102// that was never minted. Burned tokens keep theirs.
103func (st *tokenState) firstOwner(tid int64) address {
104 if tid <= 0 || st.field(tid, fieldMintHeight) == 0 {
105 return ""
106 }
107 return st.ownerAt(tid)
108}
109
110// ownerAt is the first owner recorded for a minted token tid: the last run
111// record at or before its slot (records are in slot order).
112func (st *tokenState) ownerAt(tid int64) address {
113 v, _ := st.owners.Get(packKey(tid)).(string)
114 slot := byte((tid - 1) % packSlots)
115 at := -1
116 for off := 0; off+ownerRec <= len(v) && v[off] <= slot; off += ownerRec {
117 at = off
118 }
119 if at < 0 {
120 return ""
121 }
122 return address(v[at+1 : at+ownerRec])
123}
124
125// field reads one field of token tid; 0 for a token that was never minted.
126func (st *tokenState) field(tid int64, f int) int64 {
127 if tid <= 0 {
128 return 0
129 }
130 v, _ := st.pack.Get(packKey(tid)).(string)
131 off := int((tid-1)%packSlots)*packEntry + f*4
132 if off+4 > len(v) {
133 return 0
134 }
135 return int64(v[off])<<24 | int64(v[off+1])<<16 | int64(v[off+2])<<8 | int64(v[off+3])
136}
137
138// setFields rewrites one or two fields of token tid in place (one avl
139// update; f2 < 0 means none).
140func (st *tokenState) setFields(tid int64, f1 int, v1 int64, f2 int, v2 int64) {
141 k := packKey(tid)
142 v, _ := st.pack.Get(k).(string)
143 base := int((tid-1)%packSlots) * packEntry
144 if tid <= 0 || base+packEntry > len(v) {
145 panic("token state: unknown token")
146 }
147 o1 := base + f1*4
148 v = v[:o1] + u32(v1) + v[o1+4:]
149 if f2 >= 0 {
150 o2 := base + f2*4
151 v = v[:o2] + u32(v2) + v[o2+4:]
152 }
153 st.pack.Set(k, v)
154}
155
156func (st *tokenState) mintHeight(tid int64) int64 { return st.field(tid, fieldMintHeight) }
157
158func (st *tokenState) moveOf(tid string) (moves, lastMove int64) {
159 n := tidNum(tid)
160 return st.field(n, fieldMoves), st.field(n, fieldLastMove)
161}
162
163// tidNum is the numeric token id, or 0 for anything that is not a
164// canonical positive decimal (no such token exists).
165func tidNum(tid string) int64 {
166 if len(tid) == 0 || len(tid) > 12 || tid[0] == '0' {
167 return 0
168 }
169 var n int64
170 for i := 0; i < len(tid); i++ {
171 c := tid[i]
172 if c < '0' || c > '9' {
173 return 0
174 }
175 n = n*10 + int64(c-'0')
176 }
177 return n
178}
179
180// lockExt is the grc721 Extension behind two invariants:
181//
182// - I-11: before Final no token moves or burns (the reveal lock that
183// closes RA H-3's information-advantage branch). The veto is a panic,
184// which aborts the whole transaction — the documented Extension
185// semantics of p/nt/grc721/v0.
186// - H-2: every transfer bumps the token's move counter, so a market
187// listing taken at moves=N is dead after any transfer, even if the
188// token later comes back to the seller.
189//
190// It is declared in this realm, so the hooks write core state with core's
191// authority even when another realm moves the token via RealmTeller.
192type lockExt struct {
193 cid string
194 st *tokenState
195}
196
197const lockKind = "art-lock"
198
199func (e *lockExt) ExtensionKind() string { return lockKind }
200
201// The hooks also emit the platform's per-token history events with the
202// collection id ("Minted", "Transfer"); grc721's own Transfer event carries
203// only the token's grc721 id.
204func (e *lockExt) OnMint(to address, tid grc721.TokenID) {
205 chain.Emit("Minted", "cid", e.cid, "tid", tid.String(), "to", to.String())
206}
207
208func (e *lockExt) OnTransfer(from, to address, tid grc721.TokenID) {
209 if e.st.soulbound {
210 panic(errSoulbound)
211 }
212 if !e.st.final {
213 panic("tokens are locked until the collection is final (reveal)")
214 }
215 key := tid.String()
216 n := tidNum(key)
217 e.st.setFields(n, fieldMoves, e.st.field(n, fieldMoves)+1, fieldLastMove, height())
218 chain.Emit("Transfer", "cid", e.cid, "tid", key, "from", from.String(), "to", to.String())
219}
220
221func (e *lockExt) OnBurn(tid grc721.TokenID) {
222 if !e.st.final {
223 panic("tokens are locked until the collection is final (reveal)")
224 }
225 // the packed entry stays: a burned id is never minted again (I-5)
226}
227
228// --- owner actions (I-2: never paused) ---------------------------------------
229//
230// The acting account is always the immediate caller (cur.Previous()), the
231// same rule as grc721's CallerTeller: a realm a user merely calls cannot act
232// for that user. Another realm moves tokens only after an Approve, through
233// Token(cid).RealmTeller (market/v1 does exactly that).
234
235// Every Approve of a token and every SetApprovalForAll of an (owner,
236// operator) pair bumps a nonce. A market pins the nonces at listing time,
237// so revoking an approval kills a listing for good: approving again later
238// starts a new nonce and never revives the old listing (SA-L3).
239//
240// Argument order follows grc721 with the collection first (K-1, Onbloc
241// option A): Approve(cid, to, tid), TransferFrom(cid, from, to, tid).
242func Approve(cur realm, cid string, to address, tid string) {
243 assertNoDeposit(cur)
244 c := mustCollection(cid)
245 assertTransferable(c)
246 if err := c.ledger.Approve(caller(cur), to, grc721.TokenID(tid)); err != nil {
247 panic(err)
248 }
249 n := tidNum(tid)
250 c.st.setFields(n, fieldNonce, c.st.field(n, fieldNonce)+1, -1, 0)
251}
252
253func SetApprovalForAll(cur realm, cid string, operator address, approved bool) {
254 assertNoDeposit(cur)
255 c := mustCollection(cid)
256 if approved {
257 assertTransferable(c)
258 }
259 owner := caller(cur)
260 if err := c.ledger.SetApprovalForAll(owner, operator, approved); err != nil {
261 panic(err)
262 }
263 bumpNonce(c, "o:"+owner.String()+":"+operator.String())
264}
265
266// ApprovalNonces returns the token's approval nonce and the (owner,
267// operator) approval-for-all nonce. Approvals made directly through
268// Token(cid).RealmTeller by a realm acting for itself do not bump them.
269func ApprovalNonces(cid, tid string, owner, operator address) (tokenNonce, operatorNonce int64) {
270 c := mustCollection(cid)
271 return c.st.field(tidNum(tid), fieldNonce), nonceOf(c, "o:"+owner.String()+":"+operator.String())
272}
273
274func bumpNonce(c *collection, key string) {
275 c.approvals.Set(key, nonceOf(c, key)+1)
276}
277
278func nonceOf(c *collection, key string) int64 {
279 if v := c.approvals.Get(key); v != nil {
280 return v.(int64)
281 }
282 return 0
283}
284
285func TransferFrom(cur realm, cid string, from, to address, tid string) {
286 assertNoDeposit(cur)
287 c := mustCollection(cid)
288 assertTransferable(c)
289 if err := c.ledger.TransferFrom(caller(cur), from, to, grc721.TokenID(tid)); err != nil {
290 panic(err)
291 }
292}
293
294const errSoulbound = "tokens of a non-transferable collection never move or get approved"
295
296// assertTransferable refuses core's transfer and approval entry points for
297// a non-transferable collection (I-20). The lockExt hook refuses every
298// transfer anyway, also one through Token(cid).RealmTeller; this gives the
299// same text before grc721's own approval checks. Revoking an
300// approval-for-all stays possible.
301func assertTransferable(c *collection) {
302 if c.soulbound {
303 panic(errSoulbound)
304 }
305}
306
307// Burn is owner-only. The supply gate uses nextTID, so a burn never reopens
308// a slot (I-5).
309func Burn(cur realm, cid, tid string) {
310 assertNoDeposit(cur)
311 c := mustCollection(cid)
312 owner, err := c.token.OwnerOf(grc721.TokenID(tid))
313 if err != nil {
314 panic(err)
315 }
316 if owner != caller(cur) {
317 panic("only the owner can burn a token")
318 }
319 if err := c.ledger.Burn(grc721.TokenID(tid)); err != nil {
320 panic(err)
321 }
322}
323
324// --- token reads ---------------------------------------------------------------
325
326// Token publishes the collection's official *grc721.Token. Its exported
327// methods are reads or teller factories that need the caller's live realm;
328// the ledger itself is never published.
329func Token(cid string) *grc721.Token { return mustCollection(cid).token }
330
331// Royalty publishes the read-only royalty view (EIP-2981 RoyaltyInfo).
332func Royalty(cid string) *royalty.Royalty { return mustCollection(cid).roy }
333
334// Name and Symbol are the collection's grc721 name and symbol (K-1: the
335// grc721 read set a wallet needs, keyed by collection).
336func Name(cid string) string { return mustCollection(cid).name }
337
338func Symbol(cid string) string { return mustCollection(cid).symbol }
339
340func OwnerOf(cid, tid string) (address, error) {
341 return mustCollection(cid).token.OwnerOf(grc721.TokenID(tid))
342}
343
344func BalanceOf(cid string, owner address) (int64, error) {
345 return mustCollection(cid).token.BalanceOf(owner)
346}
347
348// FirstOwner is the address token tid was minted to (a sale mint or a
349// creator reserve), whoever holds it now; burned tokens keep it. Panics
350// for a token that was never minted.
351func FirstOwner(cid, tid string) address {
352 a := mustCollection(cid).st.firstOwner(tidNum(tid))
353 if a == "" {
354 panic(grc721.ErrInvalidTokenId)
355 }
356 return a
357}
358
359// TokenMoves is the transfer counter market/v1 pins in a listing (H-2).
360func TokenMoves(cid, tid string) int64 {
361 n, _ := mustCollection(cid).st.moveOf(tid)
362 return n
363}
364
365// TokenSeed is "" until the collection is Final: no read path can leak the
366// rarity map early.
367func TokenSeed(cid, tid string) string {
368 c := mustCollection(cid)
369 if !c.st.final || !exists(c, tid) {
370 return ""
371 }
372 return safe.Seed(c.id, tid, c.prov.salt)
373}
374
375// TokenState is {mintHeight, lastMoveHeight, moves, firstOwner} as JSON.
376func TokenState(cid, tid string) string {
377 c := mustCollection(cid)
378 if !exists(c, tid) {
379 panic(grc721.ErrInvalidTokenId)
380 }
381 in := tokenInput(c, tid)
382 w := &safe.JSONWriter{}
383 w.BeginObject()
384 w.IntField("mintHeight", in.MintHeight)
385 w.IntField("lastMoveHeight", in.LastMoveHeight)
386 w.IntField("moves", in.Moves)
387 w.StrField("firstOwner", in.FirstOwner.String())
388 w.EndObject()
389 return w.String()
390}
391
392// TokenURI is the token's art (I-15). Before Final every token shows
393// core's neutral placeholder, never engine output (design §4.2). Then:
394// an SVG engine's checked Render as an SVG data URI; a media engine's
395// checked Media as a raster/SVG data URI or its ipfs:// CIDv1 URI, or —
396// when the Media is empty or fails engine.CheckMedia — the checked card.
397func TokenURI(cid, tid string) (string, error) {
398 c := mustCollection(cid)
399 if _, err := c.token.OwnerOf(grc721.TokenID(tid)); err != nil {
400 return "", err
401 }
402 a := tokenArt(c, tid)
403 return a.uri(), nil
404}
405
406// TokenCard is the token's checked SVG as a data URI: the art of an SVG
407// engine, the card of a media engine, or the placeholder (gnoweb and
408// SVG-only clients).
409func TokenCard(cid, tid string) (string, error) {
410 c := mustCollection(cid)
411 if _, err := c.token.OwnerOf(grc721.TokenID(tid)); err != nil {
412 return "", err
413 }
414 if !c.st.final {
415 return dataURI(placeholderSVG(c.name, "Unrevealed")), nil
416 }
417 return dataURI(renderToken(c, tid)), nil
418}
419
420// TokenMediaInfo describes what TokenURI returns without the payload:
421// {"source":"placeholder"|"svg"|"card"|"data"|"ipfs","mime","sha256","uri","bytes"}
422// (uri only for ipfs; bytes = the file size for data, else 0).
423func TokenMediaInfo(cid, tid string) string {
424 c := mustCollection(cid)
425 if !exists(c, tid) {
426 panic(grc721.ErrInvalidTokenId)
427 }
428 a := tokenArt(c, tid)
429 w := &safe.JSONWriter{}
430 w.BeginObject()
431 w.StrField("source", a.source)
432 w.StrField("mime", a.mime)
433 w.StrField("sha256", a.md.Sha256)
434 uri := ""
435 if a.source == artIPFS {
436 uri = a.md.URI
437 }
438 w.StrField("uri", uri)
439 w.IntField("bytes", int64(len(a.md.Data)))
440 w.EndObject()
441 return w.String()
442}
443
444// TokenTraits is [{"trait_type":…,"value":…}] JSON.
445func TokenTraits(cid, tid string) string {
446 c := mustCollection(cid)
447 w := &safe.JSONWriter{}
448 writeTraits(w, tokenTraits(c, tid))
449 return w.String()
450}
451
452// TokenTraitList is the typed form of TokenTraits for other realms (a copy).
453func TokenTraitList(cid, tid string) []engine.Trait {
454 return append([]engine.Trait{}, tokenTraits(mustCollection(cid), tid)...)
455}
456
457// TokenMetadata is OpenSea-style metadata JSON. "image" is TokenURI
458// written without escaping (it only ever holds data-URI / ipfs characters,
459// M-4); "image_mime" and "image_sha256" describe a checked media file.
460func TokenMetadata(cid, tid string) string {
461 c := mustCollection(cid)
462 if !exists(c, tid) {
463 panic(grc721.ErrInvalidTokenId)
464 }
465 a := tokenArt(c, tid)
466 w := &safe.JSONWriter{}
467 w.BeginObject()
468 w.StrField("name", c.name+" #"+tid)
469 w.StrField("description", c.description)
470 w.RawStrField("image", a.uri())
471 if a.source == artData || a.source == artIPFS {
472 w.StrField("image_mime", a.mime)
473 if a.md.Sha256 != "" {
474 w.StrField("image_sha256", a.md.Sha256)
475 }
476 }
477 // attributes carry OpenSea's trait_type and Adena's traitType (K-1)
478 w.Key("attributes")
479 w.BeginArray()
480 for _, tr := range tokenTraits(c, tid) {
481 w.BeginObject()
482 w.StrField("trait_type", tr.Type)
483 w.StrField("traitType", tr.Type)
484 w.StrField("value", tr.Value)
485 w.EndObject()
486 }
487 w.EndArray()
488 w.EndObject()
489 return w.String()
490}
491
492// Art sources of a token (TokenMediaInfo "source").
493const (
494 artPlaceholder = "placeholder"
495 artSVG = "svg"
496 artCard = "card"
497 artData = "data"
498 artIPFS = "ipfs"
499)
500
501// art is a token's resolved, checked art.
502type art struct {
503 source string
504 mime string
505 svg string // placeholder / svg / card
506 md engine.Media // data / ipfs (checked)
507}
508
509func (a art) uri() string {
510 switch a.source {
511 case artData:
512 return "data:" + a.mime + ";base64," + base64.StdEncoding.EncodeToString([]byte(a.md.Data))
513 case artIPFS:
514 return a.md.URI
515 }
516 return dataURI(a.svg)
517}
518
519// tokenArt resolves a token's art under I-15; every engine output passes
520// engine.CheckSVG or engine.CheckMedia first.
521func tokenArt(c *collection, tid string) art {
522 if !c.st.final {
523 return art{source: artPlaceholder, mime: engine.MimeSVG, svg: placeholderSVG(c.name, "Unrevealed")}
524 }
525 rec := mustEngine(c.engineID)
526 in := tokenInput(c, tid)
527 if rec.manifest.Kind == engine.KindMedia {
528 md := rec.impl.Media(in)
529 if !md.IsZero() && engine.CheckMedia(rec.manifest, md) == nil {
530 if md.Data != "" {
531 return art{source: artData, mime: md.Mime, md: md}
532 }
533 return art{source: artIPFS, mime: md.Mime, md: md}
534 }
535 svg, ok := renderCheckedToken(c, rec, in)
536 if ok {
537 return art{source: artCard, mime: engine.MimeSVG, svg: svg}
538 }
539 return art{source: artPlaceholder, mime: engine.MimeSVG, svg: svg}
540 }
541 svg, ok := renderCheckedToken(c, rec, in)
542 if ok {
543 return art{source: artSVG, mime: engine.MimeSVG, svg: svg}
544 }
545 return art{source: artPlaceholder, mime: engine.MimeSVG, svg: svg}
546}
547
548func exists(c *collection, tid string) bool {
549 _, err := c.token.OwnerOf(grc721.TokenID(tid))
550 return err == nil
551}
552
553func tokenInput(c *collection, tid string) engine.Input {
554 n := safe.ParseID("tid", tid)
555 moves, lastMove := c.st.moveOf(tid)
556 mh := c.st.mintHeight(n)
557 if lastMove == 0 {
558 lastMove = mh
559 }
560 in := engine.Input{
561 Params: c.params,
562 CollectionID: c.id,
563 TokenID: tid,
564 MintHeight: mh,
565 LastMoveHeight: lastMove,
566 Moves: moves,
567 Height: height(),
568 }
569 if mh > 0 {
570 in.FirstOwner = c.st.ownerAt(n)
571 }
572 if c.st.final {
573 in.Seed = safe.Seed(c.id, tid, c.prov.salt)
574 in.Salt = c.prov.salt
575 }
576 return in
577}
578
579// renderToken runs the collection's engine on a read path. A bad output
580// degrades to a placeholder; a panicking engine only fails reads of its own
581// collections (interrealm v2 §9: cross-realm panics abort the query).
582func renderToken(c *collection, tid string) string {
583 rec := mustEngine(c.engineID)
584 svg, _ := renderCheckedToken(c, rec, tokenInput(c, tid))
585 return svg
586}
587
588// renderCheckedToken is Render + CheckSVG; false (and the placeholder) when
589// the output is rejected.
590func renderCheckedToken(c *collection, rec *engineRecord, in engine.Input) (string, bool) {
591 svg := rec.impl.Render(in)
592 if err := engine.CheckSVG(rec.manifest, svg); err != nil {
593 return placeholderSVG(c.name, "Engine output rejected"), false
594 }
595 return svg, true
596}
597
598func tokenTraits(c *collection, tid string) []engine.Trait {
599 if !exists(c, tid) {
600 panic(grc721.ErrInvalidTokenId)
601 }
602 if !c.st.final {
603 return []engine.Trait{{Type: "Status", Value: "Unrevealed"}}
604 }
605 rec := mustEngine(c.engineID)
606 ts := rec.impl.Traits(tokenInput(c, tid))
607 if err := engine.ValidateTraitsFor(traitTypesOf(c), ts); err != nil {
608 return []engine.Trait{{Type: "Status", Value: "Engine output rejected"}}
609 }
610 return ts
611}
612
613func writeTraits(w *safe.JSONWriter, ts []engine.Trait) {
614 w.BeginArray()
615 for _, t := range ts {
616 w.BeginObject()
617 w.StrField("trait_type", t.Type)
618 w.StrField("value", t.Value)
619 w.EndObject()
620 }
621 w.EndArray()
622}
623
624// placeholderSVG is core's own neutral art: identical for every token of a
625// collection, so it carries no rarity signal.
626func placeholderSVG(name, label string) string {
627 return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">` +
628 `<rect width="512" height="512" fill="#111"/>` +
629 `<text x="256" y="236" fill="#ddd" font-family="monospace" font-size="24" text-anchor="middle">` +
630 safe.XMLEscape(name) + `</text>` +
631 `<text x="256" y="286" fill="#888" font-family="monospace" font-size="18" text-anchor="middle">` +
632 safe.XMLEscape(label) + `</text></svg>`
633}
634
635func dataURI(svg string) string {
636 return "data:image/svg+xml;base64," + base64.StdEncoding.EncodeToString([]byte(svg))
637}
638
639// emitBatch announces one MintTo ("MintBatch") or ReserveTo ("Reserved")
640// call; each token also gets its own "Minted" event from lockExt.
641func emitBatch(kind string, c *collection, to address, first, last int64) {
642 chain.Emit(kind, "cid", c.id, "to", to.String(), "first", itoa(first), "last", itoa(last))
643}