Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
a55678891 committed Mar 27, 2024
1 parent d5bc55d commit 57577c6
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions hw1/src/NFinTech/NFinTech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ interface IERC721 {
}

interface IERC721TokenReceiver {
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data)
external
returns (bytes4);
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}

contract NFinTech is IERC721 {
using Address for address payable;

string private _name;
string private _symbol;
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
Expand Down Expand Up @@ -53,6 +49,8 @@ contract NFinTech is IERC721 {
isClaim[msg.sender] = true;

_tokenId += 1;

emit Transfer(address(0), msg.sender, id);
}
}

Expand Down Expand Up @@ -108,19 +106,21 @@ contract NFinTech is IERC721 {
emit Transfer(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external {
require(isContract(to), "NFinTech: transfer to non-contract address");
transferFrom(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, data), "NFinTech: transfer to non ERC721Receiver implementer");
function safeTransferFrom(address from, address to, uint256 tokenId) external {
_safeTransferFrom(from, to, tokenId, "");
}

function safeTransferFrom(address from, address to, uint256 tokenId) public {
require(isContract(to), "NFinTech: transfer to non-contract address");
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) external {
require(_isApprovedOrOwner(msg.sender, tokenId), "NFinTech: transfer caller is not owner nor approved");
_safeTransferFrom(from, to, tokenId, data);
}

function _safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) internal {
transferFrom(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, ""), "NFinTech: transfer to non ERC721Receiver implementer");
require(_checkOnERC721Received(from, to, tokenId, data), "NFinTech: transfer to non ERC721Receiver implementer");
}

function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes calldata data) internal returns (bool) {
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) internal returns (bool) {
if (!isContract(to)) {
return true;
}
Expand All @@ -135,7 +135,9 @@ contract NFinTech is IERC721 {

function isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
assembly {
size := extcodesize(addr)
}
return size > 0;
}
}

0 comments on commit 57577c6

Please sign in to comment.