|
4 | 4 | pragma solidity ^0.8.20;
|
5 | 5 |
|
6 | 6 | import {IERC721} from "./IERC721.sol";
|
7 |
| -import {IERC721Receiver} from "./IERC721Receiver.sol"; |
8 | 7 | import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
|
| 8 | +import {ERC721Utils} from "./utils/ERC721Utils.sol"; |
9 | 9 | import {Context} from "../../utils/Context.sol";
|
10 | 10 | import {Strings} from "../../utils/Strings.sol";
|
11 | 11 | import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
|
@@ -158,7 +158,7 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
|
158 | 158 | */
|
159 | 159 | function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
|
160 | 160 | transferFrom(from, to, tokenId);
|
161 |
| - _checkOnERC721Received(from, to, tokenId, data); |
| 161 | + ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data); |
162 | 162 | }
|
163 | 163 |
|
164 | 164 | /**
|
@@ -311,7 +311,7 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
|
311 | 311 | */
|
312 | 312 | function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
|
313 | 313 | _mint(to, tokenId);
|
314 |
| - _checkOnERC721Received(address(0), to, tokenId, data); |
| 314 | + ERC721Utils.checkOnERC721Received(_msgSender(), address(0), to, tokenId, data); |
315 | 315 | }
|
316 | 316 |
|
317 | 317 | /**
|
@@ -384,7 +384,7 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
|
384 | 384 | */
|
385 | 385 | function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
|
386 | 386 | _transfer(from, to, tokenId);
|
387 |
| - _checkOnERC721Received(from, to, tokenId, data); |
| 387 | + ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data); |
388 | 388 | }
|
389 | 389 |
|
390 | 390 | /**
|
@@ -452,32 +452,4 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
|
452 | 452 | }
|
453 | 453 | return owner;
|
454 | 454 | }
|
455 |
| - |
456 |
| - /** |
457 |
| - * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the |
458 |
| - * recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract. |
459 |
| - * |
460 |
| - * @param from address representing the previous owner of the given token ID |
461 |
| - * @param to target address that will receive the tokens |
462 |
| - * @param tokenId uint256 ID of the token to be transferred |
463 |
| - * @param data bytes optional data to send along with the call |
464 |
| - */ |
465 |
| - function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private { |
466 |
| - if (to.code.length > 0) { |
467 |
| - try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) { |
468 |
| - if (retval != IERC721Receiver.onERC721Received.selector) { |
469 |
| - revert ERC721InvalidReceiver(to); |
470 |
| - } |
471 |
| - } catch (bytes memory reason) { |
472 |
| - if (reason.length == 0) { |
473 |
| - revert ERC721InvalidReceiver(to); |
474 |
| - } else { |
475 |
| - /// @solidity memory-safe-assembly |
476 |
| - assembly { |
477 |
| - revert(add(32, reason), mload(reason)) |
478 |
| - } |
479 |
| - } |
480 |
| - } |
481 |
| - } |
482 |
| - } |
483 | 455 | }
|
0 commit comments