-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Use the _update mechanism in ERC721 #4377
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
Changes from 2 commits
a3526ac
1ed8f9e
7ec3435
e2fdbac
e9f03bd
78c280b
1cc7f54
c7303ec
54cb3ca
562ddf5
0bb98cb
5ab254c
bd0c52e
1a95520
7e9d024
16f2f15
2558c8f
de570d0
7121ff7
b973d98
e4b0e72
4516803
7c3f161
9ba0120
1081508
fb4d951
d7a6aaf
4c25b48
20048ca
e996ba4
b29e573
328b16b
08da709
12f63b3
81aca96
d037530
5ce49a4
a023cad
caabbf3
ca32b45
b982e2a
f404802
20bb47f
a475ffa
e26d5c0
2897abc
52923d1
42e17ee
c2e1a55
a036284
1e4f353
7b26030
7249414
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,8 +179,10 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er | |
| /** | ||
| * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist | ||
| * | ||
| * WARNING: Any override of this function that allocates token to accounts following a custom logic should go in | ||
| * pair with a call to {_increaseBalance} so that balances and ownerships remain consistent with one another. | ||
| * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the | ||
| * core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances | ||
| * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by | ||
| * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`. | ||
| */ | ||
| function _ownerOf(uint256 tokenId) internal view virtual returns (address) { | ||
| return _owners[tokenId]; | ||
|
|
@@ -197,20 +199,17 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er | |
| * @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in | ||
| * particular (ignoring whether it is owned by `owner`). | ||
| * | ||
| * WARNING: | ||
| * - ownership is not checked. | ||
| * - spender = address(0) will lead to this function returning true in unexpected situations. | ||
| * WARNING: This function doesn't check that `owner` is the actual owner of the specified `tokenId`. Moreover, it returns true if `owner == spender` in order to skip the check where needed. Consider checking for cases where `spender == address(0)` since they could lead to unexpected behavior. | ||
| */ | ||
| function _isApproved(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) { | ||
frangio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return owner == spender || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender; | ||
frangio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * @dev Checks whether `spender` was approved by `owner` to operate on `tokenId` or is the owner of `tokenId`. | ||
| * Reverts if `spender` is not approved nor owner of `tokenId`. | ||
| * @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner. | ||
| * Reverts if `spender` has not approval for all assets of the provided `owner` nor the actual owner approved the `spender` for the specific `tokenId`. | ||
| * | ||
| * WARNING: | ||
| * - ownership is not checked. | ||
| * WARNING: This function relies on {_isApproved}, so it doesn't check whether `owner` is the actual owner of `tokenId` and will skip the check if `spender == owner` | ||
| */ | ||
| function _checkApproved(address owner, address spender, uint256 tokenId) internal view virtual { | ||
| if (!_isApproved(owner, spender, tokenId)) { | ||
|
|
@@ -279,7 +278,7 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er | |
| } | ||
|
|
||
| /** | ||
| * @dev Safely mints `tokenId` and transfers it to `to`. | ||
| * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance. | ||
| * | ||
| * Requirements: | ||
| * | ||
|
|
@@ -343,8 +342,8 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er | |
| } | ||
|
|
||
| /** | ||
| * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients | ||
| * are aware of the ERC721 protocol to prevent tokens from being forever locked. | ||
| * @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients | ||
| * are aware of the ERC721 standard to prevent tokens from being forever locked. | ||
| * | ||
| * `data` is additional data, it has no specified format and it is sent in call to `to`. | ||
| * | ||
|
|
@@ -361,8 +360,7 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er | |
| * Emits a {Transfer} event. | ||
| */ | ||
| function _safeTransfer(address from, address to, uint256 tokenId) internal { | ||
| _transfer(from, to, tokenId); | ||
| _checkOnERC721Received(from, to, tokenId, ""); | ||
| _safeTransfer(from, to, tokenId, ""); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -391,6 +389,10 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er | |
| /** | ||
| * @dev Approve `operator` to operate on all of `owner` tokens | ||
| * | ||
| * Requirements: | ||
| * - operator can't be the address zero. | ||
| * - owner can't approve himself. | ||
|
||
| * | ||
| * Emits an {ApprovalForAll} event. | ||
Amxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| function _setApprovalForAll(address owner, address operator, bool approved) internal virtual { | ||
|
|
@@ -449,6 +451,8 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er | |
| * remain consistent with one another. | ||
| */ | ||
| function _increaseBalance(address account, uint128 value) internal virtual { | ||
|
||
| _balances[account] += value; | ||
| unchecked { | ||
| _balances[account] += value; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.