-
Notifications
You must be signed in to change notification settings - Fork 333
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
Conversation
There was a problem hiding this 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 👍
...22/nft-meta-data-pointer/anchor/program/programs/extension_nft/src/instructions/chop_tree.rs
Outdated
Show resolved
Hide resolved
...22/nft-meta-data-pointer/anchor/program/programs/extension_nft/src/instructions/chop_tree.rs
Show resolved
Hide resolved
...022/nft-meta-data-pointer/anchor/program/programs/extension_nft/src/instructions/mint_nft.rs
Outdated
Show resolved
Hide resolved
...022/nft-meta-data-pointer/anchor/program/programs/extension_nft/src/instructions/mint_nft.rs
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 })?;
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.