Skip to content

Commit 61ff1f7

Browse files
committed
fix: defer lookup-specific info to implementations
1 parent 72792a7 commit 61ff1f7

File tree

4 files changed

+57
-63
lines changed

4 files changed

+57
-63
lines changed

contracts/token/ERC721/ERC721.sol

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,7 @@ import "./ERC721Basic.sol";
77
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
88
* @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
99
*/
10-
contract ERC721Enumerable is ERC721Basic {
11-
12-
bytes4 private constant InterfaceId_ERC721Enumerable = 0x780e9d63;
13-
/**
14-
* 0x780e9d63 ===
15-
* bytes4(keccak256('totalSupply()')) ^
16-
* bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^
17-
* bytes4(keccak256('tokenByIndex(uint256)'))
18-
*/
19-
20-
constructor()
21-
public
22-
{
23-
_registerInterface(InterfaceId_ERC721Enumerable);
24-
}
25-
10+
contract ERC721Enumerable {
2611
function totalSupply() public view returns (uint256);
2712
function tokenOfOwnerByIndex(
2813
address _owner,
@@ -40,22 +25,7 @@ contract ERC721Enumerable is ERC721Basic {
4025
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
4126
* @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
4227
*/
43-
contract ERC721Metadata is ERC721Basic {
44-
45-
bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
46-
/**
47-
* 0x5b5e139f ===
48-
* bytes4(keccak256('name()')) ^
49-
* bytes4(keccak256('symbol()')) ^
50-
* bytes4(keccak256('tokenURI(uint256)'))
51-
*/
52-
53-
constructor()
54-
public
55-
{
56-
_registerInterface(InterfaceId_ERC721Metadata);
57-
}
58-
28+
contract ERC721Metadata {
5929
function name() external view returns (string _name);
6030
function symbol() external view returns (string _symbol);
6131
function tokenURI(uint256 _tokenId) public view returns (string);

contracts/token/ERC721/ERC721Basic.sol

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "../../introspection/SupportsInterfaceWithLookup.sol";
77
* @title ERC721 Non-Fungible Token Standard basic interface
88
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
99
*/
10-
contract ERC721Basic is SupportsInterfaceWithLookup {
10+
contract ERC721Basic is ERC165 {
1111
event Transfer(
1212
address indexed _from,
1313
address indexed _to,
@@ -24,34 +24,6 @@ contract ERC721Basic is SupportsInterfaceWithLookup {
2424
bool _approved
2525
);
2626

27-
bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;
28-
/*
29-
* 0x80ac58cd ===
30-
* bytes4(keccak256('balanceOf(address)')) ^
31-
* bytes4(keccak256('ownerOf(uint256)')) ^
32-
* bytes4(keccak256('approve(address,uint256)')) ^
33-
* bytes4(keccak256('getApproved(uint256)')) ^
34-
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
35-
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
36-
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
37-
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
38-
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
39-
*/
40-
41-
bytes4 private constant InterfaceId_ERC721Exists = 0x4f558e79;
42-
/*
43-
* 0x4f558e79 ===
44-
* bytes4(keccak256('exists(uint256)'))
45-
*/
46-
47-
constructor ()
48-
public
49-
{
50-
// register the supported interfaces to conform to ERC721 via ERC165
51-
_registerInterface(InterfaceId_ERC721);
52-
_registerInterface(InterfaceId_ERC721Exists);
53-
}
54-
5527
function balanceOf(address _owner) public view returns (uint256 _balance);
5628
function ownerOf(uint256 _tokenId) public view returns (address _owner);
5729
function exists(uint256 _tokenId) public view returns (bool _exists);

contracts/token/ERC721/ERC721BasicToken.sol

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,35 @@ import "./ERC721Basic.sol";
44
import "./ERC721Receiver.sol";
55
import "../../math/SafeMath.sol";
66
import "../../AddressUtils.sol";
7+
import "../../introspection/SupportsInterfaceWithLookup.sol";
78

89

910
/**
1011
* @title ERC721 Non-Fungible Token Standard basic implementation
1112
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
1213
*/
13-
contract ERC721BasicToken is ERC721Basic {
14+
contract ERC721BasicToken is ERC721Basic, SupportsInterfaceWithLookup {
15+
16+
bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;
17+
/*
18+
* 0x80ac58cd ===
19+
* bytes4(keccak256('balanceOf(address)')) ^
20+
* bytes4(keccak256('ownerOf(uint256)')) ^
21+
* bytes4(keccak256('approve(address,uint256)')) ^
22+
* bytes4(keccak256('getApproved(uint256)')) ^
23+
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
24+
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
25+
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
26+
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
27+
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
28+
*/
29+
30+
bytes4 private constant InterfaceId_ERC721Exists = 0x4f558e79;
31+
/*
32+
* 0x4f558e79 ===
33+
* bytes4(keccak256('exists(uint256)'))
34+
*/
35+
1436
using SafeMath for uint256;
1537
using AddressUtils for address;
1638

@@ -48,6 +70,14 @@ contract ERC721BasicToken is ERC721Basic {
4870
_;
4971
}
5072

73+
constructor()
74+
public
75+
{
76+
// register the supported interfaces to conform to ERC721 via ERC165
77+
_registerInterface(InterfaceId_ERC721);
78+
_registerInterface(InterfaceId_ERC721Exists);
79+
}
80+
5181
/**
5282
* @dev Gets the balance of the specified address
5383
* @param _owner address to query the balance of

contracts/token/ERC721/ERC721Token.sol

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pragma solidity ^0.4.23;
22

33
import "./ERC721.sol";
44
import "./ERC721BasicToken.sol";
5+
import "../../introspection/SupportsInterfaceWithLookup.sol";
56

67

78
/**
@@ -10,7 +11,24 @@ import "./ERC721BasicToken.sol";
1011
* Moreover, it includes approve all functionality using operator terminology
1112
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
1213
*/
13-
contract ERC721Token is ERC721, ERC721BasicToken {
14+
contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
15+
16+
bytes4 private constant InterfaceId_ERC721Enumerable = 0x780e9d63;
17+
/**
18+
* 0x780e9d63 ===
19+
* bytes4(keccak256('totalSupply()')) ^
20+
* bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^
21+
* bytes4(keccak256('tokenByIndex(uint256)'))
22+
*/
23+
24+
bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
25+
/**
26+
* 0x5b5e139f ===
27+
* bytes4(keccak256('name()')) ^
28+
* bytes4(keccak256('symbol()')) ^
29+
* bytes4(keccak256('tokenURI(uint256)'))
30+
*/
31+
1432
// Token name
1533
string internal name_;
1634

@@ -38,6 +56,10 @@ contract ERC721Token is ERC721, ERC721BasicToken {
3856
constructor(string _name, string _symbol) public {
3957
name_ = _name;
4058
symbol_ = _symbol;
59+
60+
// register the supported interfaces to conform to ERC721 via ERC165
61+
_registerInterface(InterfaceId_ERC721Enumerable);
62+
_registerInterface(InterfaceId_ERC721Metadata);
4163
}
4264

4365
/**

0 commit comments

Comments
 (0)