Skip to content

Commit 8204f6a

Browse files
authored
Improved some ERC721 internal shenanigans (#1450)
* Made _clearApproval private, added clarifying comments in _addTokenTo and _removeTokenFrom. * Added approval information.
1 parent bbe804a commit 8204f6a

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

contracts/token/ERC721/ERC721.sol

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,10 @@ contract ERC721 is ERC165, IERC721 {
262262
emit Transfer(owner, address(0), tokenId);
263263
}
264264

265-
/**
266-
* @dev Internal function to clear current approval of a given token ID
267-
* Reverts if the given address is not indeed the owner of the token
268-
* @param owner owner of the token
269-
* @param tokenId uint256 ID of the token to be transferred
270-
*/
271-
function _clearApproval(address owner, uint256 tokenId) internal {
272-
require(ownerOf(tokenId) == owner);
273-
if (_tokenApprovals[tokenId] != address(0)) {
274-
_tokenApprovals[tokenId] = address(0);
275-
}
276-
}
277-
278265
/**
279266
* @dev Internal function to add a token ID to the list of a given address
267+
* Note that this function is left internal to make ERC721Enumerable possible, but is not
268+
* intended to be called by custom derived contracts: in particular, it emits no Transfer event.
280269
* @param to address representing the new owner of the given token ID
281270
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
282271
*/
@@ -288,6 +277,9 @@ contract ERC721 is ERC165, IERC721 {
288277

289278
/**
290279
* @dev Internal function to remove a token ID from the list of a given address
280+
* Note that this function is left internal to make ERC721Enumerable possible, but is not
281+
* intended to be called by custom derived contracts: in particular, it emits no Transfer event,
282+
* and doesn't clear approvals.
291283
* @param from address representing the previous owner of the given token ID
292284
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
293285
*/
@@ -322,4 +314,17 @@ contract ERC721 is ERC165, IERC721 {
322314
msg.sender, from, tokenId, _data);
323315
return (retval == _ERC721_RECEIVED);
324316
}
317+
318+
/**
319+
* @dev Private function to clear current approval of a given token ID
320+
* Reverts if the given address is not indeed the owner of the token
321+
* @param owner owner of the token
322+
* @param tokenId uint256 ID of the token to be transferred
323+
*/
324+
function _clearApproval(address owner, uint256 tokenId) private {
325+
require(ownerOf(tokenId) == owner);
326+
if (_tokenApprovals[tokenId] != address(0)) {
327+
_tokenApprovals[tokenId] = address(0);
328+
}
329+
}
325330
}

contracts/token/ERC721/ERC721Enumerable.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ contract ERC721Enumerable is ERC165, ERC721, IERC721Enumerable {
7272

7373
/**
7474
* @dev Internal function to add a token ID to the list of a given address
75+
* This function is internal due to language limitations, see the note in ERC721.sol.
76+
* It is not intended to be called by custom derived contracts: in particular, it emits no Transfer event.
7577
* @param to address representing the new owner of the given token ID
7678
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
7779
*/
@@ -84,6 +86,9 @@ contract ERC721Enumerable is ERC165, ERC721, IERC721Enumerable {
8486

8587
/**
8688
* @dev Internal function to remove a token ID from the list of a given address
89+
* This function is internal due to language limitations, see the note in ERC721.sol.
90+
* It is not intended to be called by custom derived contracts: in particular, it emits no Transfer event,
91+
* and doesn't clear approvals.
8792
* @param from address representing the previous owner of the given token ID
8893
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
8994
*/

0 commit comments

Comments
 (0)