Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(p/grc721): Distinct Event Types for GRC721 Functions #3102

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions examples/gno.land/p/demo/grc/grc721/basic_nft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package grc721

import (
"std"
"strconv"

"gno.land/p/demo/avl"
"gno.land/p/demo/ufmt"
Expand Down Expand Up @@ -120,8 +121,12 @@ func (s *basicNFT) Approve(to std.Address, tid TokenID) error {
}

s.tokenApprovals.Set(string(tid), to.String())
event := ApprovalEvent{owner, to, tid}
emit(&event)
std.Emit(
ApprovalEvent,
"owner", string(owner),
"to", string(to),
"tokenId", string(tid),
)

return nil
}
Expand Down Expand Up @@ -219,8 +224,12 @@ func (s *basicNFT) Burn(tid TokenID) error {
s.balances.Set(owner.String(), balance)
s.owners.Remove(string(tid))

event := TransferEvent{owner, zeroAddress, tid}
emit(&event)
std.Emit(
BurnEvent,
"from", string(owner),
"to", "",
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
"tokenId", string(tid),
)

s.afterTokenTransfer(owner, zeroAddress, tid, 1)

Expand All @@ -238,8 +247,12 @@ func (s *basicNFT) setApprovalForAll(owner, operator std.Address, approved bool)
key := owner.String() + ":" + operator.String()
s.operatorApprovals.Set(key, approved)

event := ApprovalForAllEvent{owner, operator, approved}
emit(&event)
std.Emit(
ApprovalForAllEvent,
"owner", string(owner),
"to", string(operator),
"approved", strconv.FormatBool(approved),
)

return nil
}
Expand Down Expand Up @@ -291,8 +304,12 @@ func (s *basicNFT) transfer(from, to std.Address, tid TokenID) error {
s.balances.Set(to.String(), toBalance)
s.owners.Set(string(tid), to)

event := TransferEvent{from, to, tid}
emit(&event)
std.Emit(
TransferEvent,
"from", string(from),
"to", string(to),
"tokenId", string(tid),
)

s.afterTokenTransfer(from, to, tid, 1)

Expand Down Expand Up @@ -324,8 +341,12 @@ func (s *basicNFT) mint(to std.Address, tid TokenID) error {
s.balances.Set(to.String(), toBalance)
s.owners.Set(string(tid), to)

event := TransferEvent{zeroAddress, to, tid}
emit(&event)
std.Emit(
MintEvent,
"from", "",
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
"to", string(to),
"tokenId", string(tid),
)

s.afterTokenTransfer(zeroAddress, to, tid, 1)

Expand Down
9 changes: 6 additions & 3 deletions examples/gno.land/p/demo/grc/grc721/grc721_metadata.gno
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ func (s *metadataNFT) mint(to std.Address, tid TokenID) error {
// Set owner of the token ID to the recipient address
s.basicNFT.owners.Set(string(tid), to)

// Emit transfer event
event := TransferEvent{zeroAddress, to, tid}
emit(&event)
std.Emit(
TransferEvent,
"from", string(zeroAddress),
"to", string(to),
"tokenId", string(tid),
)

s.basicNFT.afterTokenTransfer(zeroAddress, to, tid, 1)

Expand Down
24 changes: 7 additions & 17 deletions examples/gno.land/p/demo/grc/grc721/igrc721.gno
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,10 @@ type (
TokenURI string
)

type TransferEvent struct {
From std.Address
To std.Address
TokenID TokenID
}

type ApprovalEvent struct {
Owner std.Address
Approved std.Address
TokenID TokenID
}

type ApprovalForAllEvent struct {
Owner std.Address
Operator std.Address
Approved bool
}
const (
MintEvent = "Mint"
BurnEvent = "Burn"
TransferEvent = "Transfer"
ApprovalEvent = "Approval"
ApprovalForAllEvent = "ApprovalForAll"
)
Loading