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

fix(grc721): Make basic metadataNFT implementation usable from external packages #3495

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

stefann-01
Copy link
Contributor

@stefann-01 stefann-01 commented Jan 13, 2025

The current implementation of grc721_metadata.gno has a critical usability issue where external packages can't access basic_nft.gno methods when using NewNFTWithMetadata(). This is because:

  1. The metadataNFT struct in grc721_metadata.gno embeds *basicNFT which is unexported
  2. While embedding promotes methods within the same package, unexported methods are not accessible from external packages
  3. External packages could only access the metadata-specific methods (SetTokenMetadata, TokenMetadata)

Changes made:

  • Add forwarding methods in metadataNFT for all basicNFT functionality (Name, Symbol, BalanceOf, etc.)
  • Remove owner check in SetTokenMetadata, since this is something that should be left for NFT collection creator to choose who should be able to use this method

These changes ensure that external packages can properly use the metadata NFT implementation with full NFT functionality while maintaining proper encapsulation of the underlying basicNFT struct interface.

An example of a working usage of this updated grc721_metadata.gno can be found in this file.

…y (Name, Symbol, BalanceOf, etc.)

- add SetTokenMetadata to IGRC721MetadataOnchain interface
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Jan 13, 2025
@stefann-01 stefann-01 changed the title fix(grc721): Make metadata NFT implementation usable from external packages fix(grc721): Make metadataNFT implementation usable from external packages Jan 13, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Jan 13, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
  • The pull request description provides enough details (checked by @thehowl)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 The pull request was created from a fork (head branch repo: stefann-01/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission
The pull request description provides enough details

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors)
    └── 🟢 Not (🔴 Pull request author is user: dependabot[bot])

Can be checked by

  • team core-contributors

@stefann-01 stefann-01 changed the title fix(grc721): Make metadataNFT implementation usable from external packages fix(grc721): Make basic metadataNFT implementation usable from external packages Jan 13, 2025
@Kouteki Kouteki requested review from jefft0, notJoon and r3v4s January 13, 2025 12:22
@Kouteki Kouteki added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jan 13, 2025
Copy link
Member

@notJoon notJoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why owner check were done in the existing code, but I think making access control looser as it has been modified now would allow for more flexible application to other projects in the future.

Still, this seems related to policy, we should check with others for their opinions as well. Anyway LGTM

@notJoon notJoon removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jan 14, 2025
@thehowl thehowl requested a review from leohhhn January 14, 2025 18:12
Comment on lines -32 to -41
// Check if the caller is the owner of the token
owner, err := s.basicNFT.OwnerOf(tid)
if err != nil {
return err
}
caller := std.PrevRealm().Addr()
if caller != owner {
return ErrCallerIsNotOwner
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

Copy link
Contributor Author

@stefann-01 stefann-01 Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described in the description, I removed the owner check in SetTokenMetadata. This change ensures that the decision of who can use this method is left to the NFT collection creator, rather than being predefined in the basic implementation.

In most cases, setting token metadata is typically a one-time operation, either automated by the contract or handled by the collection owner. Token owners usually do not have the capability to modify metadata.

By removing the owner check in the basic implementation, we allow greater flexibility, enabling both options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • grc721 metadata is implementation of opensea metadata standards.
  • opensea does supports ERC-7015 to proof ownership. (which is pretty latest spec)

Therefore, removing owner logic might be work for now but as what @leohhhn said about refactoring, we won't have this issue :D

@leohhhn
Copy link
Contributor

leohhhn commented Jan 14, 2025

Hopefully we'll do a full refactor of the GRC721 package and we won't have issues with this :)

@stefann-01
Copy link
Contributor Author

Hopefully we'll do a full refactor of the GRC721 package and we won't have issues with this :)

I completely agree that the current GRC721 implementation could benefit from a full refactor. I’ve already started considering some approaches to address these issues. However, the current implementation of grc721_metadata.gno is completely unusable, so I believe merging this PR is a necessary step to make it functional until a more comprehensive refactor can be completed.

Copy link
Contributor

@r3v4s r3v4s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't have strong opinion for this pr, because full refactoring grc721 won't produce this kind of issues anymore.

For short-term solution, looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

6 participants