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

Remove enumerable from ERC721 and add an ERC721Enumerable extension #2511

Merged
merged 30 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c330fcd
Add a light variant of ERC721 (non enumerable)
Amxx Feb 3, 2021
da49687
separate metadata from ERC721 and fix behavior test
Amxx Feb 3, 2021
fb9877e
make ERC721 non enumerable and add a ERC721Enumerable
Amxx Feb 3, 2021
0fe0c01
remove old comment
Amxx Feb 3, 2021
53da911
fix lint
Amxx Feb 5, 2021
0383c05
fix test
Amxx Feb 5, 2021
b1366d6
Merge branch 'master' into feature/ERC721Light
Amxx Feb 10, 2021
a8e3db7
erc721 enumerability on using hook and erc721 data
Amxx Feb 12, 2021
44b7863
use mapping instead of array in ERC721enumerable to avoid double sstore
Amxx Feb 12, 2021
b89a7de
Merge branch 'master' into feature/ERC721Light
Amxx Feb 17, 2021
2e27c98
merge ERC721Metadata back into ERC721 (basic version without storage)
Amxx Feb 17, 2021
0f8301d
Merge branch 'feature/ERC721Light' of github.com:Amxx/openzeppelin-co…
Amxx Feb 17, 2021
2619bb1
documentation of _baseUri
Amxx Feb 17, 2021
1c76dd3
fix gsn test
Amxx Feb 17, 2021
261e750
fix preset test
Amxx Feb 17, 2021
ce3017f
add changelog entry
Amxx Feb 18, 2021
bee22d0
Merge remote-tracking branch 'upstream/master' into feature/ERC721Light
frangio Feb 18, 2021
7e36934
fix merge errors
frangio Feb 18, 2021
08183d1
Update CHANGELOG.md
Amxx Feb 19, 2021
c136072
Update contracts/token/ERC721/ERC721.sol
Amxx Feb 19, 2021
1e69ce6
Update contracts/token/ERC721/ERC721.sol
Amxx Feb 19, 2021
e1b0490
address issues raised in PR
Amxx Feb 19, 2021
5cab2bc
Merge remote-tracking branch 'Amxx/feature/ERC721Light' into feature/…
Amxx Feb 19, 2021
0313e5f
test baseURI/tokenURI mechanisms in shouldBehaveLikeERC721Metadata
Amxx Feb 19, 2021
d56cdcb
setBaseURI tests aware of target contract
Amxx Feb 19, 2021
3a0323e
Merge branch 'master' into feature/ERC721Light
Amxx Feb 19, 2021
c39ef2d
remove unsupported ?? operator
frangio Feb 19, 2021
7d74a7a
fix optimization to get string once
frangio Feb 19, 2021
ced1689
add ERC721Enumerable to docs site
frangio Feb 19, 2021
325e471
add docs for ERC721Enumerable
frangio Feb 19, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* `GSN`: Deprecate GSNv1 support in favor of upcomming support for GSNv2. ([#2521](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2521))
* `ERC165`: Remove uses of storage in the base ERC165 implementation. ERC165 based contracts now use storage-less virtual functions. Old behaviour remains available in the `ERC165Storage` extension. ([#2505](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2505))
* `Initializable`: Make initializer check stricter during construction. ([#2531](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2531))
* `ERC721`: remove enumerability of tokens from the base implementation. This feature is now provided separately through the `ERC721Enumerable` extension. ([#2511](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2511))

## 3.4.0 (2021-02-02)

Expand Down
43 changes: 43 additions & 0 deletions contracts/mocks/ERC721EnumerableMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../token/ERC721/ERC721Enumerable.sol";

/**
* @title ERC721Mock
* This mock just provides a public safeMint, mint, and burn functions for testing purposes
*/
contract ERC721EnumerableMock is ERC721Enumerable {
string private _baseTokenURI;

constructor (string memory name, string memory symbol) ERC721(name, symbol) { }

function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}

function setBaseURI(string calldata newBaseTokenURI) public {
_baseTokenURI = newBaseTokenURI;
}

function baseURI() public view returns (string memory) {
return _baseURI();
}

function mint(address to, uint256 tokenId) public {
_mint(to, tokenId);
}

function safeMint(address to, uint256 tokenId) public {
_safeMint(to, tokenId);
}

function safeMint(address to, uint256 tokenId, bytes memory _data) public {
_safeMint(to, tokenId, _data);
}

function burn(uint256 tokenId) public {
_burn(tokenId);
}
}
18 changes: 12 additions & 6 deletions contracts/mocks/ERC721Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ import "../token/ERC721/ERC721.sol";
* This mock just provides a public safeMint, mint, and burn functions for testing purposes
*/
contract ERC721Mock is ERC721 {
string private _baseTokenURI;

constructor (string memory name, string memory symbol) ERC721(name, symbol) { }

function exists(uint256 tokenId) public view returns (bool) {
return _exists(tokenId);
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}

function setTokenURI(uint256 tokenId, string memory uri) public {
_setTokenURI(tokenId, uri);
function setBaseURI(string calldata newBaseTokenURI) public {
_baseTokenURI = newBaseTokenURI;
}

function setBaseURI(string memory baseURI) public {
_setBaseURI(baseURI);
function baseURI() public view returns (string memory) {
return _baseURI();
}

function exists(uint256 tokenId) public view returns (bool) {
return _exists(tokenId);
}

function mint(address to, uint256 tokenId) public {
Expand Down
22 changes: 18 additions & 4 deletions contracts/presets/ERC721PresetMinterPauserAutoId.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "../access/AccessControl.sol";
import "../utils/Context.sol";
import "../utils/Counters.sol";
import "../token/ERC721/ERC721.sol";
import "../token/ERC721/ERC721Enumerable.sol";
import "../token/ERC721/ERC721Burnable.sol";
import "../token/ERC721/ERC721Pausable.sol";

Expand All @@ -24,28 +25,34 @@ import "../token/ERC721/ERC721Pausable.sol";
* roles, as well as the default admin role, which will let it grant both minter
* and pauser roles to other accounts.
*/
contract ERC721PresetMinterPauserAutoId is Context, AccessControl, ERC721Burnable, ERC721Pausable {
contract ERC721PresetMinterPauserAutoId is Context, AccessControl, ERC721Enumerable, ERC721Burnable, ERC721Pausable {
using Counters for Counters.Counter;

bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

Counters.Counter private _tokenIdTracker;

string private _baseTokenURI;

/**
* @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the
* account that deploys the contract.
*
* Token URIs will be autogenerated based on `baseURI` and their token IDs.
* See {ERC721-tokenURI}.
*/
constructor(string memory name, string memory symbol, string memory baseURI) ERC721(name, symbol) {
constructor(string memory name, string memory symbol, string memory baseTokenURI) ERC721(name, symbol) {
_baseTokenURI = baseTokenURI;

_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());

_setupRole(MINTER_ROLE, _msgSender());
_setupRole(PAUSER_ROLE, _msgSender());
}

_setBaseURI(baseURI);
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}

/**
Expand Down Expand Up @@ -96,7 +103,14 @@ contract ERC721PresetMinterPauserAutoId is Context, AccessControl, ERC721Burnabl
_unpause();
}

function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721, ERC721Pausable) {
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721, ERC721Enumerable, ERC721Pausable) {
super._beforeTokenTransfer(from, to, tokenId);
}

/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
}
Loading