Cyfrin / foundry-nft-cu

22 stars 25 forks source link

Undeclared identifier: _isApprovedOrOwner() #43

Closed Zacharyii closed 1 month ago

Zacharyii commented 1 month ago

Error (7576): Undeclared identifier. --> src/MoodNft.sol:38:13: | 38 | if(!_isApprovedOrOwner(msg.sender, tokenId)){ | ^^^^^^^^^^^^^^^^^^

Zacharyii commented 1 month ago

In this logic of removing hidden SLOADs, the _isApprovedOrOwner function was removed in favor of a new _isAuthorized function. Overrides that used to target the _isApprovedOrOwner should now be performed on the _isAuthorized function. Calls to _isApprovedOrOwner that preceded a call to _transfer, _burn or _approve should be removed in favor of using the auth argument in _update and _approve. This is showcased in ERC721Burnable.burn and in ERC721Wrapper.withdrawTo.

Zacharyii commented 1 month ago

Is this right? I changed A to B.

A:

    function flipMood(uint256 tokenId) public {
        if(!_isApprovedOrOwner(msg.sender, tokenId)){
            revert MoodNft__CantFlipMoodIfNotOwner();
        }
        if (s_tokenIdToMood[tokenId] == Mood.HAPPY) {
            s_tokenIdToMood[tokenId] = Mood.SAD;
        }else{
            s_tokenIdToMood[tokenId] = Mood.HAPPY;
        }
    }

B:

    function flipMood(uint256 tokenId) public {
        address owner = ownerOf(tokenId);  // 获取 tokenId 对应的所有者
        if (!_isAuthorized(owner, msg.sender, tokenId)) {
            revert MoodNft__CantFlipMoodIfNotOwner();
        }
        if (s_tokenIdToMood[tokenId] == Mood.HAPPY) {
            s_tokenIdToMood[tokenId] = Mood.SAD;
        } else {
            s_tokenIdToMood[tokenId] = Mood.HAPPY;
        }
    }
PatrickAlphaC commented 1 month ago

At a first glance, this looks correct! (no promises though). I'm going to close this issue though to keep the codebase as-is.