Search Apps Documentation Source Content File Folder Download Copy Actions Download

transfer.gno

1.99 Kb · 80 lines
 1package memba_nft_v2
 2
 3import (
 4	"chain"
 5	"chain/runtime/unsafe"
 6
 7	"gno.land/p/samcrew/grc721"
 8)
 9
10// ── Group 3: approvals + read-only queries ────────────────────────────────────
11
12func Approve(cur realm, id string, operator address, tid grc721.TokenID) {
13	c := mustGet(id)
14	if err := c.nft.Approve(unsafe.PreviousRealm().Address(), operator, tid); err != nil {
15		panic(err.Error())
16	}
17}
18
19func SetApprovalForAll(cur realm, id string, operator address, approved bool) {
20	c := mustGet(id)
21	if err := c.nft.SetApprovalForAll(unsafe.PreviousRealm().Address(), operator, approved); err != nil {
22		panic(err.Error())
23	}
24}
25
26func OwnerOf(id string, tid grc721.TokenID) address {
27	o, err := mustGet(id).nft.OwnerOf(tid)
28	if err != nil {
29		panic(err.Error())
30	}
31	return o
32}
33
34func BalanceOf(id string, owner address) int64 {
35	b, err := mustGet(id).nft.BalanceOf(owner)
36	if err != nil {
37		panic(err.Error())
38	}
39	return b
40}
41
42func GetApproved(id string, tid grc721.TokenID) address {
43	a, err := mustGet(id).nft.GetApproved(tid)
44	if err != nil {
45		return ""
46	}
47	return a
48}
49
50func IsApprovedForAll(id string, owner, operator address) bool {
51	return mustGet(id).nft.IsApprovedForAll(owner, operator)
52}
53
54func TokenURI(id string, tid grc721.TokenID) string {
55	u, err := mustGet(id).nft.TokenURI(tid)
56	if err != nil {
57		return ""
58	}
59	return u
60}
61
62// ── Group 5: MarketTransfer ────────────────────────────────────────────────────
63
64func MarketTransfer(cur realm, id string, from, to address, tid grc721.TokenID) {
65	market := unsafe.PreviousRealm().Address()
66	if !isRegisteredMarket(market) {
67		panic("unauthorized market")
68	}
69	c := mustGet(id)
70	assertNotPaused(c)
71	if err := c.nft.TransferFrom(market, from, to, tid); err != nil {
72		panic(err.Error())
73	}
74	chain.Emit("MarketTransfer",
75		"collection", id,
76		"from", from.String(),
77		"to", to.String(),
78		"tokenId", string(tid),
79	)
80}