Skip to content

Commit

Permalink
Merge pull request #33 from nventuro/erc721-init
Browse files Browse the repository at this point in the history
ERC721 contracts no longer initialize their parents.
  • Loading branch information
nventuro committed Oct 15, 2018
2 parents 36043ec + d75ba16 commit 84a37e1
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion contracts/introspection/ERC165.sol
Expand Up @@ -37,7 +37,7 @@ contract ERC165 is Initializable, IERC165 {
* @dev implement supportsInterface(bytes4) using a lookup table
*/
function supportsInterface(bytes4 interfaceId)
external
public
view
returns (bool)
{
Expand Down
5 changes: 3 additions & 2 deletions contracts/mocks/ERC721FullMock.sol
Expand Up @@ -14,10 +14,11 @@ import "../token/ERC721/ERC721Burnable.sol";
contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
constructor(string name, string symbol) public
{
ERC721Full.initialize(name, symbol);
ERC721.initialize();
ERC721Metadata.initialize(name, symbol);
ERC721Enumerable.initialize();
ERC721Mintable.initialize(msg.sender);
ERC721MetadataMintable.initialize(msg.sender);
ERC721Burnable.initialize();
}

function exists(uint256 tokenId) public view returns (bool) {
Expand Down
5 changes: 3 additions & 2 deletions contracts/mocks/ERC721MintableBurnableImpl.sol
Expand Up @@ -15,9 +15,10 @@ contract ERC721MintableBurnableImpl
constructor()
public
{
ERC721Full.initialize("Test", "TEST");
ERC721.initialize();
ERC721Metadata.initialize("Test", "TEST");
ERC721Enumerable.initialize();
ERC721Mintable.initialize(msg.sender);
ERC721MetadataMintable.initialize(msg.sender);
ERC721Burnable.initialize();
}
}
1 change: 1 addition & 0 deletions contracts/mocks/ERC721PausableMock.sol
Expand Up @@ -10,6 +10,7 @@ import "./PauserRoleMock.sol";
*/
contract ERC721PausableMock is ERC721Pausable, PauserRoleMock {
constructor() {
ERC721.initialize();
ERC721Pausable.initialize(msg.sender);
}

Expand Down
4 changes: 4 additions & 0 deletions contracts/token/ERC721/ERC721.sol
Expand Up @@ -57,6 +57,10 @@ contract ERC721 is Initializable, ERC165, IERC721 {
_registerInterface(_InterfaceId_ERC721);
}

function _hasBeenInitialized() internal view returns (bool) {
return supportsInterface(_InterfaceId_ERC721);
}

/**
* @dev Gets the balance of the specified address
* @param owner address to query the balance of
Expand Down
4 changes: 0 additions & 4 deletions contracts/token/ERC721/ERC721Burnable.sol
Expand Up @@ -5,10 +5,6 @@ import "./ERC721.sol";


contract ERC721Burnable is Initializable, ERC721 {
function initialize() public initializer {
ERC721.initialize();
}

function burn(uint256 tokenId)
public
{
Expand Down
7 changes: 5 additions & 2 deletions contracts/token/ERC721/ERC721Enumerable.sol
Expand Up @@ -31,13 +31,16 @@ contract ERC721Enumerable is Initializable, ERC165, ERC721, IERC721Enumerable {
* @dev Constructor function
*/
function initialize() public initializer {
ERC165.initialize();
ERC721.initialize();
require(ERC721._hasBeenInitialized());

// register the supported interface to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Enumerable);
}

function _hasBeenInitialized() internal view returns (bool) {
return supportsInterface(_InterfaceId_ERC721Enumerable);
}

/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param owner address owning the tokens list to be accessed
Expand Down
9 changes: 0 additions & 9 deletions contracts/token/ERC721/ERC721Full.sol
Expand Up @@ -13,14 +13,5 @@ import "./ERC721Metadata.sol";
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/
contract ERC721Full is Initializable, ERC721, ERC721Enumerable, ERC721Metadata {
function initialize(string name, string symbol)
public
initializer
{
ERC721.initialize();
ERC721Enumerable.initialize();
ERC721Metadata.initialize(name, symbol);
}

uint256[50] private ______gap;
}
7 changes: 5 additions & 2 deletions contracts/token/ERC721/ERC721Metadata.sol
Expand Up @@ -28,8 +28,7 @@ contract ERC721Metadata is Initializable, ERC165, ERC721, IERC721Metadata {
* @dev Constructor function
*/
function initialize(string name, string symbol) public initializer {
ERC165.initialize();
ERC721.initialize();
require(ERC721._hasBeenInitialized());

_name = name;
_symbol = symbol;
Expand All @@ -38,6 +37,10 @@ contract ERC721Metadata is Initializable, ERC165, ERC721, IERC721Metadata {
_registerInterface(InterfaceId_ERC721Metadata);
}

function _hasBeenInitialized() internal view returns (bool) {
return supportsInterface(InterfaceId_ERC721Metadata);
}

/**
* @dev Gets the token name
* @return string representing the token name
Expand Down
3 changes: 2 additions & 1 deletion contracts/token/ERC721/ERC721MetadataMintable.sol
Expand Up @@ -11,7 +11,8 @@ import "../../access/roles/MinterRole.sol";
*/
contract ERC721MetadataMintable is Initializable, ERC721, ERC721Metadata, MinterRole {
function initialize(address sender) public initializer {
ERC721.initialize();
require(ERC721._hasBeenInitialized());
require(ERC721Metadata._hasBeenInitialized());
MinterRole.initialize(sender);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/ERC721Mintable.sol
Expand Up @@ -11,7 +11,7 @@ import "../../access/roles/MinterRole.sol";
*/
contract ERC721Mintable is Initializable, ERC721, MinterRole {
function initialize(address sender) public initializer {
ERC721.initialize();
require(ERC721._hasBeenInitialized());
MinterRole.initialize(sender);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC721/ERC721Pausable.sol
Expand Up @@ -11,7 +11,7 @@ import "../../lifecycle/Pausable.sol";
**/
contract ERC721Pausable is Initializable, ERC721, Pausable {
function initialize(address sender) public initializer {
ERC721.initialize();
require(ERC721._hasBeenInitialized());
Pausable.initialize(sender);
}

Expand Down

0 comments on commit 84a37e1

Please sign in to comment.