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

Added extension nft meta data pointer example #68

Merged
merged 3 commits into from
Mar 12, 2024
Merged

Conversation

Woody4618
Copy link
Collaborator

@Woody4618 Woody4618 commented Feb 18, 2024

Added an example on how to create NFTs with the token meta data pointer extension and additional meta data with nextjs app, unity client and anchor program.

Copy link
Member

@brimigs brimigs left a comment

Choose a reason for hiding this comment

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

just some feedback on general rust 👍

tokens/token-2022/nft-meta-data-pointer/anchor/README.md Outdated Show resolved Hide resolved

impl GameData {
pub fn on_tree_chopped(&mut self, amount_chopped: u64) -> Result<()> {
match self.total_wood_collected.checked_add(amount_chopped) {
Copy link
Member

Choose a reason for hiding this comment

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

missing error handling for checked.add() should have an .ok_or_else() to handle any overflow errors otherwise it could contribute to silent errors in the game

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Isnt the "match" doing exactly that check? If none its an overflow if some it worked. Or are there also other cases then it returns none?

}

pub fn chop_tree(&mut self, amount: u64) -> Result<()> {
match self.wood.checked_add(amount) {
Copy link
Member

Choose a reason for hiding this comment

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

missing overflow handing with checked_add() and checked_sub(). Would suggest adding in ok_or_else()

Something like this:
let new_wood = self.wood.checked_add(amount).ok_or_else(|| { msg!("Overflow error: Too much wood collected."); ProgramError::InvalidArgument })?;

@Woody4618 Woody4618 merged commit feb82f2 into main Mar 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants