Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change erc165 to pure. #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/contracts/mocks/nf-token-metadata-enumerable-mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 22 additions & 8 deletions src/contracts/tokens/nf-token-enumerable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
31 changes: 22 additions & 9 deletions src/contracts/tokens/nf-token-metadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
32 changes: 22 additions & 10 deletions src/contracts/tokens/nf-token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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";

/**
* @dev Implementation of ERC-721 non-fungible token standard.
*/
contract NFToken is
ERC721,
SupportsInterface
ERC165
{
using AddressUtils for address;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/utils/erc165.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ERC165
bytes4 _interfaceID
)
external
view
pure
returns (bool);

}
42 changes: 0 additions & 42 deletions src/contracts/utils/supports-interface.sol

This file was deleted.