Simplify ERC721 revert reasons (#3438)
This commit is contained in:
committed by
GitHub
parent
4fc9fd3efe
commit
62f2c0531b
@ -69,7 +69,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
||||
*/
|
||||
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
|
||||
address owner = _owners[tokenId];
|
||||
require(owner != address(0), "ERC721: owner query for nonexistent token");
|
||||
require(owner != address(0), "ERC721: invalid token ID");
|
||||
return owner;
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
||||
* @dev See {IERC721Metadata-tokenURI}.
|
||||
*/
|
||||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
||||
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
|
||||
_requireMinted(tokenId);
|
||||
|
||||
string memory baseURI = _baseURI();
|
||||
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
|
||||
@ -125,7 +125,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
||||
* @dev See {IERC721-getApproved}.
|
||||
*/
|
||||
function getApproved(uint256 tokenId) public view virtual override returns (address) {
|
||||
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
|
||||
_requireMinted(tokenId);
|
||||
|
||||
return _tokenApprovals[tokenId];
|
||||
}
|
||||
@ -374,6 +374,13 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
||||
emit ApprovalForAll(owner, operator, approved);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Reverts if the `tokenId` has not been minted yet.
|
||||
*/
|
||||
function _requireMinted(uint256 tokenId) internal view virtual {
|
||||
require(_exists(tokenId), "ERC721: invalid token ID");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
|
||||
* The call is not executed if the target address is not a contract.
|
||||
|
||||
@ -18,7 +18,7 @@ abstract contract ERC721URIStorage is ERC721 {
|
||||
* @dev See {IERC721Metadata-tokenURI}.
|
||||
*/
|
||||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
||||
require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");
|
||||
_requireMinted(tokenId);
|
||||
|
||||
string memory _tokenURI = _tokenURIs[tokenId];
|
||||
string memory base = _baseURI();
|
||||
|
||||
Reference in New Issue
Block a user