From 64ab594ad6e577962a6148933b170e29641818a5 Mon Sep 17 00:00:00 2001 From: Jordan <1364262+EvilJordan@users.noreply.github.com> Date: Mon, 1 Jun 2020 16:17:32 -0400 Subject: [PATCH] Modify token presets "mint" function as virtual to allow extending (#2257) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Modify token presets "mint" function as virtual to allow extending in parent contracts * Update ERC20PresetMinterPauser.sol * Update ERC721PresetMinterPauserAutoId.sol * Update CHANGELOG.md Co-authored-by: Nicolás Venturo --- CHANGELOG.md | 1 + contracts/presets/ERC20PresetMinterPauser.sol | 8 ++++---- contracts/presets/ERC721PresetMinterPauserAutoId.sol | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d655c4752e..690074f961f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Improvements * `ReentrancyGuard`: reduced overhead of using the `nonReentrant` modifier. ([#2171](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2171)) * `AccessControl`: added a `RoleAdminChanged` event to `_setAdminRole`. ([#2214](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2214)) + * Made all `public` functions in the token preset contracts `virtual`. ([#2257](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2257)) ## 3.0.1 (2020-04-27) diff --git a/contracts/presets/ERC20PresetMinterPauser.sol b/contracts/presets/ERC20PresetMinterPauser.sol index cc8574e0f2c..f6397452957 100644 --- a/contracts/presets/ERC20PresetMinterPauser.sol +++ b/contracts/presets/ERC20PresetMinterPauser.sol @@ -48,7 +48,7 @@ contract ERC20PresetMinterPauser is Context, AccessControl, ERC20Burnable, ERC20 * * - the caller must have the `MINTER_ROLE`. */ - function mint(address to, uint256 amount) public { + function mint(address to, uint256 amount) public virtual { require(hasRole(MINTER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have minter role to mint"); _mint(to, amount); } @@ -62,7 +62,7 @@ contract ERC20PresetMinterPauser is Context, AccessControl, ERC20Burnable, ERC20 * * - the caller must have the `PAUSER_ROLE`. */ - function pause() public { + function pause() public virtual { require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to pause"); _pause(); } @@ -76,12 +76,12 @@ contract ERC20PresetMinterPauser is Context, AccessControl, ERC20Burnable, ERC20 * * - the caller must have the `PAUSER_ROLE`. */ - function unpause() public { + function unpause() public virtual { require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have pauser role to unpause"); _unpause(); } - function _beforeTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Pausable) { + function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20, ERC20Pausable) { super._beforeTokenTransfer(from, to, amount); } } diff --git a/contracts/presets/ERC721PresetMinterPauserAutoId.sol b/contracts/presets/ERC721PresetMinterPauserAutoId.sol index 38095fc3c00..3515a59a190 100644 --- a/contracts/presets/ERC721PresetMinterPauserAutoId.sol +++ b/contracts/presets/ERC721PresetMinterPauserAutoId.sol @@ -59,7 +59,7 @@ contract ERC721PresetMinterPauserAutoId is Context, AccessControl, ERC721Burnabl * * - the caller must have the `MINTER_ROLE`. */ - function mint(address to) public { + function mint(address to) public virtual { require(hasRole(MINTER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have minter role to mint"); // We can just use balanceOf to create the new tokenId because tokens @@ -77,7 +77,7 @@ contract ERC721PresetMinterPauserAutoId is Context, AccessControl, ERC721Burnabl * * - the caller must have the `PAUSER_ROLE`. */ - function pause() public { + function pause() public virtual { require(hasRole(PAUSER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have pauser role to pause"); _pause(); } @@ -91,12 +91,12 @@ contract ERC721PresetMinterPauserAutoId is Context, AccessControl, ERC721Burnabl * * - the caller must have the `PAUSER_ROLE`. */ - function unpause() public { + function unpause() public virtual { require(hasRole(PAUSER_ROLE, _msgSender()), "ERC721PresetMinterPauserAutoId: must have pauser role to unpause"); _unpause(); } - function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Pausable) { + function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721, ERC721Pausable) { super._beforeTokenTransfer(from, to, tokenId); } }