refactor _checkAuhtorized

This commit is contained in:
Hadrien Croubois
2023-07-13 16:45:30 +02:00
parent 328b16bf8c
commit 08da709ba7

View File

@ -207,13 +207,14 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
* WARNING: This function relies on {_isAuthorized}, so it doesn't check whether `owner` is the actual owner of `tokenId` and will skip the check if `spender == owner` * WARNING: This function relies on {_isAuthorized}, so it doesn't check whether `owner` is the actual owner of `tokenId` and will skip the check if `spender == owner`
*/ */
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual { function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
// That first check is needed because the error is different, and should as precedence over insufficient approval if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) { if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId); revert ERC721NonexistentToken(tokenId);
} else if (!_isAuthorized(owner, spender, tokenId)) { } else {
revert ERC721InsufficientApproval(spender, tokenId); revert ERC721InsufficientApproval(spender, tokenId);
} }
} }
}
/** /**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override. * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.