Преглед изворни кода

Make ERC721.exists internal (#1193)

* Made ERC721.exists internal.

* Removed exists ERC165 identifiers
Nicolás Venturo пре 7 година
родитељ
комит
41e6b2e992

+ 5 - 1
contracts/mocks/ERC721TokenMock.sol

@@ -21,10 +21,14 @@ contract ERC721TokenMock is ERC721Token {
     super._burn(ownerOf(_tokenId), _tokenId);
   }
 
+  function exists(uint256 _tokenId) public view returns (bool) {
+    return super._exists(_tokenId);
+  }
+
   function setTokenURI(uint256 _tokenId, string _uri) public {
     super._setTokenURI(_tokenId, _uri);
   }
-  
+
   function _removeTokenFrom(address _from, uint256 _tokenId) public {
     super.removeTokenFrom(_from, _tokenId);
   }

+ 0 - 7
contracts/token/ERC721/ERC721Basic.sol

@@ -23,12 +23,6 @@ contract ERC721Basic is ERC165 {
    *   bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
    */
 
-  bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79;
-  /*
-   * 0x4f558e79 ===
-   *   bytes4(keccak256('exists(uint256)'))
-   */
-
   bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63;
   /**
    * 0x780e9d63 ===
@@ -63,7 +57,6 @@ contract ERC721Basic is ERC165 {
 
   function balanceOf(address _owner) public view returns (uint256 _balance);
   function ownerOf(uint256 _tokenId) public view returns (address _owner);
-  function exists(uint256 _tokenId) public view returns (bool _exists);
 
   function approve(address _to, uint256 _tokenId) public;
   function getApproved(uint256 _tokenId)

+ 10 - 11
contracts/token/ERC721/ERC721BasicToken.sol

@@ -37,7 +37,6 @@ contract ERC721BasicToken is SupportsInterfaceWithLookup, ERC721Basic {
   {
     // register the supported interfaces to conform to ERC721 via ERC165
     _registerInterface(InterfaceId_ERC721);
-    _registerInterface(InterfaceId_ERC721Exists);
   }
 
   /**
@@ -61,16 +60,6 @@ contract ERC721BasicToken is SupportsInterfaceWithLookup, ERC721Basic {
     return owner;
   }
 
-  /**
-   * @dev Returns whether the specified token exists
-   * @param _tokenId uint256 ID of the token to query the existence of
-   * @return whether the token exists
-   */
-  function exists(uint256 _tokenId) public view returns (bool) {
-    address owner = tokenOwner[_tokenId];
-    return owner != address(0);
-  }
-
   /**
    * @dev Approves another address to transfer the given token ID
    * The zero address indicates there is no approved address.
@@ -200,6 +189,16 @@ contract ERC721BasicToken is SupportsInterfaceWithLookup, ERC721Basic {
     require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data));
   }
 
+  /**
+   * @dev Returns whether the specified token exists
+   * @param _tokenId uint256 ID of the token to query the existence of
+   * @return whether the token exists
+   */
+  function _exists(uint256 _tokenId) internal view returns (bool) {
+    address owner = tokenOwner[_tokenId];
+    return owner != address(0);
+  }
+
   /**
    * @dev Returns whether the given spender can transfer a given token ID
    * @param _spender address of the spender to query

+ 2 - 2
contracts/token/ERC721/ERC721Token.sol

@@ -68,7 +68,7 @@ contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
    * @param _tokenId uint256 ID of the token to query
    */
   function tokenURI(uint256 _tokenId) public view returns (string) {
-    require(exists(_tokenId));
+    require(_exists(_tokenId));
     return tokenURIs[_tokenId];
   }
 
@@ -116,7 +116,7 @@ contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
    * @param _uri string URI to assign
    */
   function _setTokenURI(uint256 _tokenId, string _uri) internal {
-    require(exists(_tokenId));
+    require(_exists(_tokenId));
     tokenURIs[_tokenId] = _uri;
   }
 

+ 0 - 21
test/token/ERC721/ERC721BasicToken.behavior.js

@@ -47,26 +47,6 @@ function shouldBehaveLikeERC721BasicToken (accounts) {
       });
     });
 
-    describe('exists', function () {
-      context('when the token exists', function () {
-        const tokenId = firstTokenId;
-
-        it('should return true', async function () {
-          const result = await this.token.exists(tokenId);
-          result.should.be.true;
-        });
-      });
-
-      context('when the token does not exist', function () {
-        const tokenId = unknownTokenId;
-
-        it('should return false', async function () {
-          const result = await this.token.exists(tokenId);
-          result.should.be.false;
-        });
-      });
-    });
-
     describe('ownerOf', function () {
       context('when the given token ID was tracked by this token', function () {
         const tokenId = firstTokenId;
@@ -554,7 +534,6 @@ function shouldBehaveLikeERC721BasicToken (accounts) {
     shouldSupportInterfaces([
       'ERC165',
       'ERC721',
-      'ERC721Exists',
     ]);
   });
 }

+ 0 - 1
test/token/ERC721/ERC721Token.test.js

@@ -225,7 +225,6 @@ contract('ERC721Token', function (accounts) {
   shouldSupportInterfaces([
     'ERC165',
     'ERC721',
-    'ERC721Exists',
     'ERC721Enumerable',
     'ERC721Metadata',
   ]);