burn.gno
1.32 Kb · 47 lines
1package gnogle_nftmarket
2
3import (
4 "chain"
5 "strconv"
6
7 "gno.land/p/g18wk4a80cr7dqa25vfka2yug5n3pd50udled6y3/grc721"
8)
9
10// Burn permanently destroys a token the caller owns. The token must be held
11// directly by the caller (not escrowed in a listing or auction).
12func Burn(cur realm, collID, tokenID string) {
13 assertUserCall(cur)
14 coll := mustGetCollection(collID)
15 caller := cur.Previous().Address()
16 tid := grc721.TokenID(tokenID)
17
18 owner, err := coll.nft.OwnerOf(tid)
19 if err != nil {
20 panic(err)
21 }
22 if owner != caller {
23 panic("only the token owner can burn it")
24 }
25 if err := coll.nft.Burn(tid); err != nil {
26 panic(err)
27 }
28 coll.burned++
29
30 chain.Emit("Burn", "collection", collID, "tokenId", tokenID, "by", caller.String())
31}
32
33// SealCollection caps a collection at its current minted count, permanently
34// "burning" the unminted remainder so no further tokens can be minted.
35// Creator-only and irreversible — useful when you created a large supply but
36// minted only part of it.
37func SealCollection(cur realm, collID string) {
38 assertUserCall(cur)
39 coll := mustGetCollection(collID)
40 if cur.Previous().Address() != coll.creator {
41 panic("only the collection creator can seal it")
42 }
43 coll.maxSupply = coll.minted
44 coll.sealed = true
45
46 chain.Emit("CollectionSealed", "collection", collID, "supply", strconv.FormatInt(coll.minted, 10))
47}