@@ -78,16 +78,20 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {
7878 /// @notice Returns all implemented callback and module functions.
7979 function getModuleConfig () external pure virtual override returns (ModuleConfig memory config ) {
8080 config.callbackFunctions = new CallbackFunction [](2 );
81- config.fallbackFunctions = new FallbackFunction [](3 );
81+ config.fallbackFunctions = new FallbackFunction [](6 );
8282
8383 config.callbackFunctions[0 ] = CallbackFunction (this .onTokenURI.selector );
8484 config.callbackFunctions[1 ] = CallbackFunction (this .updateMetadataERC721.selector );
8585
8686 config.fallbackFunctions[0 ] =
8787 FallbackFunction ({selector: this .uploadMetadata.selector , permissionBits: Role._MINTER_ROLE});
8888 config.fallbackFunctions[1 ] =
89+ FallbackFunction ({selector: this .setBaseURI.selector , permissionBits: Role._MANAGER_ROLE});
90+ config.fallbackFunctions[2 ] =
8991 FallbackFunction ({selector: this .getAllMetadataBatches.selector , permissionBits: 0 });
90- config.fallbackFunctions[2 ] = FallbackFunction ({selector: this .nextTokenIdToMint.selector , permissionBits: 0 });
92+ config.fallbackFunctions[3 ] = FallbackFunction ({selector: this .nextTokenIdToMint.selector , permissionBits: 0 });
93+ config.fallbackFunctions[4 ] = FallbackFunction ({selector: this .getBatchId.selector , permissionBits: 0 });
94+ config.fallbackFunctions[5 ] = FallbackFunction ({selector: this .getBatchRange.selector , permissionBits: 0 });
9195
9296 config.requiredInterfaces = new bytes4 [](1 );
9397 config.requiredInterfaces[0 ] = 0x80ac58cd ; // ERC721.
@@ -153,6 +157,46 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {
153157 return _batchMetadataStorage ().nextTokenIdRangeStart;
154158 }
155159
160+ /// @dev Returns the id for the batch of tokens the given tokenId belongs to.
161+ function getBatchId (uint256 _tokenId ) public view virtual returns (uint256 batchId , uint256 index ) {
162+ uint256 [] memory rangeEnds = _batchMetadataStorage ().tokenIdRangeEnd;
163+ uint256 numOfBatches = rangeEnds.length ;
164+
165+ for (uint256 i = 0 ; i < numOfBatches; i += 1 ) {
166+ if (_tokenId < rangeEnds[i]) {
167+ index = i;
168+ batchId = rangeEnds[i];
169+
170+ return (batchId, index);
171+ }
172+ }
173+ revert BatchMetadataNoMetadataForTokenId ();
174+ }
175+
176+ /// @dev returns the starting tokenId of a given batchId.
177+ function getBatchRange (uint256 _batchID ) public view returns (uint256 , uint256 ) {
178+ uint256 [] memory rangeEnds = _batchMetadataStorage ().tokenIdRangeEnd;
179+ uint256 numOfBatches = rangeEnds.length ;
180+
181+ for (uint256 i = 0 ; i < numOfBatches; i += 1 ) {
182+ if (_batchID == rangeEnds[i]) {
183+ if (i > 0 ) {
184+ return (rangeEnds[i - 1 ], rangeEnds[i] - 1 );
185+ }
186+ return (0 , rangeEnds[i] - 1 );
187+ }
188+ }
189+
190+ revert BatchMetadataNoMetadataForTokenId ();
191+ }
192+
193+ /// @dev Sets the base URI for the batch of tokens with the given batchId.
194+ function setBaseURI (uint256 _batchId , string memory _baseURI ) external virtual {
195+ _batchMetadataStorage ().baseURIOfTokenIdRange[_batchId] = _baseURI;
196+ (uint256 startTokenId ,) = getBatchRange (_batchId);
197+ emit BatchMetadataUpdate (startTokenId, _batchId);
198+ }
199+
156200 /*//////////////////////////////////////////////////////////////
157201 INTERNAL FUNCTIONS
158202 //////////////////////////////////////////////////////////////*/
0 commit comments