Search Apps Documentation Source Content File Folder Download Copy Actions Download

igrc721.gno

2.13 Kb · 59 lines
 1package grc721
 2
 3// IGRC721Reader is the read-only view of an NFT. Safe to receive across
 4// realm boundaries — has no rlm-typed methods, so a malicious impl can
 5// only lie about read results (data-integrity issue), not capture cur.
 6//
 7// Writes are concrete methods on *BasicNFT / *metadataNFT only — there
 8// is no IGRC721 writer interface. The owning realm should hold the
 9// concrete *metadataNFT in an unexported package var and expose public
10// caller-deriving wrappers like:
11//
12//	func TransferFrom(cur realm, from, to address, tid TokenID) error {
13//		caller := unsaferealm.PreviousRealm().Address() // chain/runtime/unsafe
14//		return nft.TransferFrom(caller, from, to, tid)
15//	}
16//
17// (cur.Previous().Address() is the more idiomatic form where every
18// target network's GnoVM supports it — confirmed missing on Beta
19// Mainnet's as of 2026-08, hence the unsafe fallback above; see
20// basic_nft.gno's NewBasicNFT doc comment for the full rationale and
21// the empirical/structural argument for why it's safe for this
22// call shape specifically.)
23//
24// This is the Reader/Writer split — stronger than the Authority-pattern
25// because the writer interface doesn't exist at all, so no realm author
26// can accidentally expose it.
27type IGRC721Reader interface {
28	Name() string
29	Symbol() string
30	TokenCount() int64
31	BalanceOf(owner address) (int64, error)
32	OwnerOf(tid TokenID) (address, error)
33	GetApproved(tid TokenID) (address, error)
34	IsApprovedForAll(owner, operator address) bool
35}
36
37type (
38	TokenID  string
39	TokenURI string
40)
41
42func (t TokenID) String() string  { return string(t) }
43func (t TokenURI) String() string { return string(t) }
44
45const (
46	MintEvent           = "Mint"
47	BurnEvent           = "Burn"
48	TransferEvent       = "Transfer"
49	ApprovalEvent       = "Approval"
50	ApprovalForAllEvent = "ApprovalForAll"
51	TokenURIUpdateEvent = "TokenUriUpdate"
52	MetadataUpdateEvent = "MetadataUpdate"
53)
54
55// NFTGetter returns a reader-only view of an NFT. Aggregators (such as
56// a marketplace or observer) register and dispatch NFTGetters; the
57// reader-only return type means even a malicious aggregator can't be
58// used to leak cur.
59type NFTGetter func() IGRC721Reader