-
Notifications
You must be signed in to change notification settings - Fork 561
Fix listing validation: add failsafe for nonexistent tokens #364
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
Conversation
address operator; | ||
|
||
// failsafe for reverts in case of non-existent tokens | ||
try IERC721(_assetContract).ownerOf(_tokenId) returns (address _owner) { |
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.
wouldn't this just return the zero address? it doesn't throw in solidity right?
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.
Yeah it won't throw. The operator and owner variables are zero address by default. The check below will evaluate to false in case these remain zero due to external calls failing.
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.
then why do we need the try catch?
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.
The ownerOf
function does throw an error in some ERC-721 contracts out there. For example, this is the ownerOf
code in the OpenZeppelin ERC-721 contract:
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}
try IERC721(_assetContract).ownerOf(_tokenId) returns (address _owner) { | ||
owner = _owner; | ||
|
||
try IERC721(_assetContract).getApproved(_tokenId) returns (address _operator) { |
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.
oh is this the call that throws? i would assume that also just returns false if the tokenId doesnt exist?
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.
Yeah both ownerOf
and getApproved
check if the token-id exists, and revert if not.
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.
For most cases, including create and update listing, this is fine. The call would just revert.
But it affects the view function for getting the valid listings.
Yes |
No description provided.