@@ -29,8 +29,6 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is
2929 ERC721PausableUpgradeable ,
3030 IERC721PresetMinterPauserAutoIdCustomized
3131{
32- error ErrUnauthorizedAccount (address account , bytes32 neededRole );
33-
3432 bytes32 public constant MINTER_ROLE = keccak256 ("MINTER_ROLE " );
3533 bytes32 public constant PAUSER_ROLE = keccak256 ("PAUSER_ROLE " );
3634
@@ -62,50 +60,46 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is
6260 ) internal onlyInitializing {
6361 __ERC721_init_unchained (name, symbol);
6462 __Pausable_init_unchained ();
65- __ERC721PresetMinterPauserAutoId_init_unchained (name, symbol, baseTokenURI);
63+ __ERC721PresetMinterPauserAutoId_init_unchained (baseTokenURI);
6664 }
6765
6866 function __ERC721PresetMinterPauserAutoId_init_unchained (
69- string memory ,
70- string memory ,
7167 string memory baseTokenURI
7268 ) internal onlyInitializing {
73- _baseTokenURI = baseTokenURI;
69+ _setBaseTokenURI ( baseTokenURI) ;
7470
7571 _grantRole (DEFAULT_ADMIN_ROLE, _msgSender ());
7672
7773 _grantRole (MINTER_ROLE, _msgSender ());
7874 _grantRole (PAUSER_ROLE, _msgSender ());
7975
80- ++ _tokenIdTracker;
76+ _tokenIdTracker = _firstTokenId () ;
8177 }
8278
8379 /// @inheritdoc IERC721PresetMinterPauserAutoIdCustomized
8480 function mint (
8581 address to
86- ) public virtual returns (uint256 tokenId ) {
87- address sender = _msgSender ();
88- if (! hasRole (MINTER_ROLE, sender)) revert ErrUnauthorizedAccount (sender, MINTER_ROLE);
89-
82+ ) public virtual onlyRole (MINTER_ROLE) returns (uint256 tokenId ) {
9083 tokenId = _mintFor (to);
9184 }
9285
9386 /// @inheritdoc IERC721PresetMinterPauserAutoIdCustomized
94- function pause () public virtual {
95- address sender = _msgSender ();
96- if (! hasRole (PAUSER_ROLE, sender)) revert ErrUnauthorizedAccount (sender, PAUSER_ROLE);
97-
87+ function pause () public virtual onlyRole (PAUSER_ROLE) {
9888 _pause ();
9989 }
10090
10191 /// @inheritdoc IERC721PresetMinterPauserAutoIdCustomized
102- function unpause () public virtual {
103- address sender = _msgSender ();
104- if (! hasRole (PAUSER_ROLE, sender)) revert ErrUnauthorizedAccount (sender, PAUSER_ROLE);
105-
92+ function unpause () public virtual onlyRole (PAUSER_ROLE) {
10693 _unpause ();
10794 }
10895
96+ /// @dev Allow admin to set the base token URI.
97+ function setBaseTokenURI (
98+ string calldata baseTokenURI
99+ ) public virtual onlyRole (DEFAULT_ADMIN_ROLE) {
100+ _setBaseTokenURI (baseTokenURI);
101+ }
102+
109103 /**
110104 * @dev See {IERC165-supportsInterface}.
111105 */
@@ -138,6 +132,16 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is
138132 ++ _tokenIdTracker;
139133 }
140134
135+ /// @dev Helper function to set the base token URI.
136+ function _setBaseTokenURI (
137+ string memory baseTokenURI
138+ ) internal {
139+ require (bytes (baseTokenURI).length > 0 , InvalidBaseTokenURI ());
140+
141+ _baseTokenURI = baseTokenURI;
142+ emit BaseTokenURIUpdated (baseTokenURI);
143+ }
144+
141145 /**
142146 * @dev Helper function to mint for address `to`.
143147 *
@@ -173,4 +177,9 @@ contract ERC721PresetMinterPauserAutoIdCustomizedUpgradeable is
173177 ) internal virtual override (ERC721Upgradeable , ERC721EnumerableUpgradeable ) {
174178 super ._increaseBalance (account, amount);
175179 }
180+
181+ /// @dev Allow child contract to define the first token id. Default to 1.
182+ function _firstTokenId () internal view virtual returns (uint256 ) {
183+ return 1 ;
184+ }
176185}
0 commit comments