diff --git a/src/contracts/mocks/nf-token-metadata-enumerable-mock.sol b/src/contracts/mocks/nf-token-metadata-enumerable-mock.sol index 54003da..6f2b8c8 100644 --- a/src/contracts/mocks/nf-token-metadata-enumerable-mock.sol +++ b/src/contracts/mocks/nf-token-metadata-enumerable-mock.sol @@ -15,6 +15,29 @@ contract NFTokenMetadataEnumerableMock is Ownable { + /** + * @dev Function to check which interfaces are suported by this contract. + * @param _interfaceID Id of the interface. + * @return True if _interfaceID is supported, false otherwise. + */ + function supportsInterface( + bytes4 _interfaceID + ) + external + override(NFTokenEnumerable, NFTokenMetadata) + virtual + pure + returns (bool) + { + if (_interfaceID == 0x01ffc9a7 + || _interfaceID == 0x80ac58cd + || _interfaceID == 0x780e9d63 + || _interfaceID == 0x5b5e139f) { + return true; + } + return false; + } + /** * @dev Contract constructor. * @param _name A descriptive name for a collection of NFTs. diff --git a/src/contracts/tokens/nf-token-enumerable.sol b/src/contracts/tokens/nf-token-enumerable.sol index 25118bc..ac73d0f 100644 --- a/src/contracts/tokens/nf-token-enumerable.sol +++ b/src/contracts/tokens/nf-token-enumerable.sol @@ -38,14 +38,6 @@ contract NFTokenEnumerable is */ mapping(uint256 => uint256) internal idToOwnerIndex; - /** - * @dev Contract constructor. - */ - constructor() - { - supportedInterfaces[0x780e9d63] = true; // ERC721Enumerable - } - /** * @dev Returns the count of all existing NFTokens. * @return Total supply of NFTs. @@ -95,6 +87,28 @@ contract NFTokenEnumerable is return ownerToIds[_owner][_index]; } + /** + * @dev Function to check which interfaces are suported by this contract. + * @param _interfaceID Id of the interface. + * @return True if _interfaceID is supported, false otherwise. + */ + function supportsInterface( + bytes4 _interfaceID + ) + external + override + virtual + pure + returns (bool) + { + if (_interfaceID == 0x01ffc9a7 + || _interfaceID == 0x80ac58cd + || _interfaceID == 0x780e9d63) { + return true; + } + return false; + } + /** * @notice This is an internal function which should be called from user-implemented external * mint function. Its purpose is to show and properly initialize data structures when using this diff --git a/src/contracts/tokens/nf-token-metadata.sol b/src/contracts/tokens/nf-token-metadata.sol index bd8dced..f89945f 100644 --- a/src/contracts/tokens/nf-token-metadata.sol +++ b/src/contracts/tokens/nf-token-metadata.sol @@ -27,15 +27,6 @@ contract NFTokenMetadata is */ mapping (uint256 => string) internal idToUri; - /** - * @notice When implementing this contract don't forget to set nftName and nftSymbol. - * @dev Contract constructor. - */ - constructor() - { - supportedInterfaces[0x5b5e139f] = true; // ERC721Metadata - } - /** * @dev Returns a descriptive name for a collection of NFTokens. * @return _name Representing name. @@ -96,6 +87,28 @@ contract NFTokenMetadata is return idToUri[_tokenId]; } + /** + * @dev Function to check which interfaces are suported by this contract. + * @param _interfaceID Id of the interface. + * @return True if _interfaceID is supported, false otherwise. + */ + function supportsInterface( + bytes4 _interfaceID + ) + external + override + virtual + pure + returns (bool) + { + if (_interfaceID == 0x01ffc9a7 + || _interfaceID == 0x80ac58cd + || _interfaceID == 0x5b5e139f) { + return true; + } + return false; + } + /** * @notice This is an internal function which should be called from user-implemented external * burn function. Its purpose is to show and properly initialize data structures when using this diff --git a/src/contracts/tokens/nf-token.sol b/src/contracts/tokens/nf-token.sol index fd6dc54..9674e2b 100644 --- a/src/contracts/tokens/nf-token.sol +++ b/src/contracts/tokens/nf-token.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import "./erc721.sol"; import "./erc721-token-receiver.sol"; -import "../utils/supports-interface.sol"; +import "../utils/erc165.sol"; import "../utils/address-utils.sol"; /** @@ -11,7 +11,7 @@ import "../utils/address-utils.sol"; */ contract NFToken is ERC721, - SupportsInterface + ERC165 { using AddressUtils for address; @@ -100,14 +100,6 @@ contract NFToken is _; } - /** - * @dev Contract constructor. - */ - constructor() - { - supportedInterfaces[0x80ac58cd] = true; // ERC721 - } - /** * @notice Throws unless `msg.sender` is the current owner, an authorized operator, or the * approved address for this NFT. Throws if `_from` is not the current owner. Throws if `_to` is @@ -294,6 +286,26 @@ contract NFToken is return ownerToOperators[_owner][_operator]; } + /** + * @dev Function to check which interfaces are suported by this contract. + * @param _interfaceID Id of the interface. + * @return True if _interfaceID is supported, false otherwise. + */ + function supportsInterface( + bytes4 _interfaceID + ) + external + override + virtual + pure + returns (bool) + { + if (_interfaceID == 0x01ffc9a7 || _interfaceID == 0x80ac58cd) { + return true; + } + return false; + } + /** * @notice Does NO checks. * @dev Actually performs the transfer. diff --git a/src/contracts/utils/erc165.sol b/src/contracts/utils/erc165.sol index 5c70dd6..2babd39 100644 --- a/src/contracts/utils/erc165.sol +++ b/src/contracts/utils/erc165.sol @@ -18,7 +18,7 @@ interface ERC165 bytes4 _interfaceID ) external - view + pure returns (bool); } diff --git a/src/contracts/utils/supports-interface.sol b/src/contracts/utils/supports-interface.sol deleted file mode 100644 index ced307f..0000000 --- a/src/contracts/utils/supports-interface.sol +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "./erc165.sol"; - -/** - * @dev Implementation of standard for detect smart contract interfaces. - */ -contract SupportsInterface is - ERC165 -{ - - /** - * @dev Mapping of supported intefraces. You must not set element 0xffffffff to true. - */ - mapping(bytes4 => bool) internal supportedInterfaces; - - /** - * @dev Contract constructor. - */ - constructor() - { - supportedInterfaces[0x01ffc9a7] = true; // ERC165 - } - - /** - * @dev Function to check which interfaces are suported by this contract. - * @param _interfaceID Id of the interface. - * @return True if _interfaceID is supported, false otherwise. - */ - function supportsInterface( - bytes4 _interfaceID - ) - external - override - view - returns (bool) - { - return supportedInterfaces[_interfaceID]; - } - -}