Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
rayliao1031 committed Mar 13, 2024
1 parent 4740476 commit a925c31
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions hw1/src/NFinTech/NFinTech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,52 @@ contract NFinTech is IERC721 {
}

function setApprovalForAll(address operator, bool approved) external {
// TODO: please add your implementaiton here
require(operator != address(0), "ERC721: setting approve to the zero address");
require(msg.sender != operator, "ERC721: setting approval status for self");

_operatorApproval[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}

function isApprovedForAll(address owner, address operator) public view returns (bool) {
// TODO: please add your implementaiton here
return _operatorApproval[owner][operator];
}

function approve(address to, uint256 tokenId) external {
// TODO: please add your implementaiton here
address owner = _owner[tokenId];
require(owner == msg.sender || isApprovedForAll(owner, msg.sender), "ERC721: approve caller is not owner nor approved for all");
require(owner != address(0), "ERC721: approval to non-existent token");

_tokenApproval[tokenId] = to;
emit Approval(owner, to, tokenId);
}

function getApproved(uint256 tokenId) public view returns (address operator) {
// TODO: please add your implementaiton here
require(_owner[tokenId] != address(0), "ERC721: approved query for nonexistent token");
return _tokenApproval[tokenId];
}

function transferFrom(address from, address to, uint256 tokenId) public {
// TODO: please add your implementaiton here
}
require(_owner[tokenId] == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
require(msg.sender == from || getApproved(tokenId) == msg.sender || isApprovedForAll(from, msg.sender), "ERC721: transfer caller is not owner nor approved");

// 清除之前的授权
_tokenApproval[tokenId] = address(0);

_balances[from] -= 1;
_balances[to] += 1;
_owner[tokenId] = to;

emit Transfer(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) public {
// TODO: please add your implementaiton here
transferFrom(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId) public {
// TODO: please add your implementaiton here
}
safeTransferFrom(from, to, tokenId, "");
}

}

0 comments on commit a925c31

Please sign in to comment.