Search Apps Documentation Source Content File Folder Download Copy Actions Download

extra.gno

1.56 Kb · 57 lines
 1package gnogle_nftmarket
 2
 3import (
 4	"chain"
 5	"strconv"
 6
 7	"gno.land/p/nt/ufmt/v0"
 8)
 9
10// MintBatch mints `count` (1..20) tokens to the caller in one call, charging
11// count × the mint price. Returns the first token id minted.
12func MintBatch(cur realm, collID string, count int64) string {
13	assertUserCall(cur)
14	if count <= 0 || count > 20 {
15		panic("count must be between 1 and 20")
16	}
17	coll := mustGetCollection(collID)
18	minter := cur.Previous().Address()
19
20	paid := receivedUgnot()
21	if paid != coll.mintPrice*count {
22		panic(ufmt.Sprintf("must send exactly %d ugnot for %d mints", coll.mintPrice*count, count))
23	}
24
25	first := ""
26	for i := int64(0); i < count; i++ {
27		tid := mintOne(coll, minter)
28		if first == "" {
29			first = tid
30		}
31	}
32	if paid > 0 {
33		payout(cur, coll.creator, paid)
34	}
35	chain.Emit("MintBatch", "collection", collID, "count", strconv.FormatInt(count, 10), "minter", minter.String())
36	return first
37}
38
39// SetBaseURI updates a collection's metadata base URI (e.g. after pinning images
40// to IPFS). Creator-only.
41func SetBaseURI(cur realm, collID, uri string) {
42	assertUserCall(cur)
43	coll := mustGetCollection(collID)
44	if cur.Previous().Address() != coll.creator {
45		panic("only the collection creator can set the base URI")
46	}
47	coll.baseURI = uri
48	chain.Emit("SetBaseURI", "collection", collID)
49}
50
51// SetVerified toggles a collection's "verified" badge. Admin-only.
52func SetVerified(cur realm, collID string, v bool) {
53	assertAdmin(cur)
54	coll := mustGetCollection(collID)
55	coll.verified = v
56	chain.Emit("SetVerified", "collection", collID, "verified", strconv.FormatBool(v))
57}