ERC721 contracts no longer initialize their parents (but have some safety checks).

This commit is contained in:
Nicolás Venturo
2018-10-15 13:41:51 -03:00
parent 1961032592
commit d75ba16223
12 changed files with 26 additions and 25 deletions

View File

@ -37,7 +37,7 @@ contract ERC165 is Initializable, IERC165 {
* @dev implement supportsInterface(bytes4) using a lookup table * @dev implement supportsInterface(bytes4) using a lookup table
*/ */
function supportsInterface(bytes4 interfaceId) function supportsInterface(bytes4 interfaceId)
external public
view view
returns (bool) returns (bool)
{ {

View File

@ -14,10 +14,11 @@ import "../token/ERC721/ERC721Burnable.sol";
contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable { contract ERC721FullMock is ERC721Full, ERC721Mintable, ERC721MetadataMintable, ERC721Burnable {
constructor(string name, string symbol) public constructor(string name, string symbol) public
{ {
ERC721Full.initialize(name, symbol); ERC721.initialize();
ERC721Metadata.initialize(name, symbol);
ERC721Enumerable.initialize();
ERC721Mintable.initialize(msg.sender); ERC721Mintable.initialize(msg.sender);
ERC721MetadataMintable.initialize(msg.sender); ERC721MetadataMintable.initialize(msg.sender);
ERC721Burnable.initialize();
} }
function exists(uint256 tokenId) public view returns (bool) { function exists(uint256 tokenId) public view returns (bool) {

View File

@ -15,9 +15,10 @@ contract ERC721MintableBurnableImpl
constructor() constructor()
public public
{ {
ERC721Full.initialize("Test", "TEST"); ERC721.initialize();
ERC721Metadata.initialize("Test", "TEST");
ERC721Enumerable.initialize();
ERC721Mintable.initialize(msg.sender); ERC721Mintable.initialize(msg.sender);
ERC721MetadataMintable.initialize(msg.sender); ERC721MetadataMintable.initialize(msg.sender);
ERC721Burnable.initialize();
} }
} }

View File

@ -10,6 +10,7 @@ import "./PauserRoleMock.sol";
*/ */
contract ERC721PausableMock is ERC721Pausable, PauserRoleMock { contract ERC721PausableMock is ERC721Pausable, PauserRoleMock {
constructor() { constructor() {
ERC721.initialize();
ERC721Pausable.initialize(msg.sender); ERC721Pausable.initialize(msg.sender);
} }

View File

@ -57,6 +57,10 @@ contract ERC721 is Initializable, ERC165, IERC721 {
_registerInterface(_InterfaceId_ERC721); _registerInterface(_InterfaceId_ERC721);
} }
function _hasBeenInitialized() internal view returns (bool) {
return supportsInterface(_InterfaceId_ERC721);
}
/** /**
* @dev Gets the balance of the specified address * @dev Gets the balance of the specified address
* @param owner address to query the balance of * @param owner address to query the balance of

View File

@ -5,10 +5,6 @@ import "./ERC721.sol";
contract ERC721Burnable is Initializable, ERC721 { contract ERC721Burnable is Initializable, ERC721 {
function initialize() public initializer {
ERC721.initialize();
}
function burn(uint256 tokenId) function burn(uint256 tokenId)
public public
{ {

View File

@ -31,13 +31,16 @@ contract ERC721Enumerable is Initializable, ERC165, ERC721, IERC721Enumerable {
* @dev Constructor function * @dev Constructor function
*/ */
function initialize() public initializer { function initialize() public initializer {
ERC165.initialize(); require(ERC721._hasBeenInitialized());
ERC721.initialize();
// register the supported interface to conform to ERC721 via ERC165 // register the supported interface to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Enumerable); _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 * @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 * @param owner address owning the tokens list to be accessed

View File

@ -13,14 +13,5 @@ import "./ERC721Metadata.sol";
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ */
contract ERC721Full is Initializable, ERC721, ERC721Enumerable, ERC721Metadata { 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; uint256[50] private ______gap;
} }

View File

@ -28,8 +28,7 @@ contract ERC721Metadata is Initializable, ERC165, ERC721, IERC721Metadata {
* @dev Constructor function * @dev Constructor function
*/ */
function initialize(string name, string symbol) public initializer { function initialize(string name, string symbol) public initializer {
ERC165.initialize(); require(ERC721._hasBeenInitialized());
ERC721.initialize();
_name = name; _name = name;
_symbol = symbol; _symbol = symbol;
@ -38,6 +37,10 @@ contract ERC721Metadata is Initializable, ERC165, ERC721, IERC721Metadata {
_registerInterface(InterfaceId_ERC721Metadata); _registerInterface(InterfaceId_ERC721Metadata);
} }
function _hasBeenInitialized() internal view returns (bool) {
return supportsInterface(InterfaceId_ERC721Metadata);
}
/** /**
* @dev Gets the token name * @dev Gets the token name
* @return string representing the token name * @return string representing the token name

View File

@ -11,7 +11,8 @@ import "../../access/roles/MinterRole.sol";
*/ */
contract ERC721MetadataMintable is Initializable, ERC721, ERC721Metadata, MinterRole { contract ERC721MetadataMintable is Initializable, ERC721, ERC721Metadata, MinterRole {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
ERC721.initialize(); require(ERC721._hasBeenInitialized());
require(ERC721Metadata._hasBeenInitialized());
MinterRole.initialize(sender); MinterRole.initialize(sender);
} }

View File

@ -11,7 +11,7 @@ import "../../access/roles/MinterRole.sol";
*/ */
contract ERC721Mintable is Initializable, ERC721, MinterRole { contract ERC721Mintable is Initializable, ERC721, MinterRole {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
ERC721.initialize(); require(ERC721._hasBeenInitialized());
MinterRole.initialize(sender); MinterRole.initialize(sender);
} }

View File

@ -11,7 +11,7 @@ import "../../lifecycle/Pausable.sol";
**/ **/
contract ERC721Pausable is Initializable, ERC721, Pausable { contract ERC721Pausable is Initializable, ERC721, Pausable {
function initialize(address sender) public initializer { function initialize(address sender) public initializer {
ERC721.initialize(); require(ERC721._hasBeenInitialized());
Pausable.initialize(sender); Pausable.initialize(sender);
} }