Skip to content

Commit

Permalink
Merge branch 'main' into ERC-1155-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges authored Sep 4, 2024
2 parents 30b6f89 + b8040df commit 9c57d1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/module/token/metadata/BatchMetadataERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {

/// @notice Callback function for ERC721Metadata.tokenURI
function onTokenURI(uint256 _id) public view returns (string memory) {
string memory batchUri = _getBaseURI(_id);

return string(abi.encodePacked(batchUri, _id.toString()));
(string memory batchUri, uint256 indexInBatch) = _getBaseURI(_id);
return string(abi.encodePacked(batchUri, indexInBatch.toString()));
}

/// @notice Callback function for updating metadata
Expand Down Expand Up @@ -158,14 +157,18 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @dev Returns the baseURI for a token. The intended metadata URI for the token is baseURI + tokenId.
function _getBaseURI(uint256 _tokenId) internal view returns (string memory) {
/// @dev Returns the baseURI for a token. The intended metadata URI for the token is baseURI + indexInBatch.
function _getBaseURI(uint256 _tokenId) internal view returns (string memory baseUri, uint256 indexInBatch) {
uint256[] memory rangeEnds = _batchMetadataStorage().tokenIdRangeEnd;
uint256 numOfBatches = rangeEnds.length;

for (uint256 i = 0; i < numOfBatches; i += 1) {
if (_tokenId < rangeEnds[i]) {
return _batchMetadataStorage().baseURIOfTokenIdRange[rangeEnds[i]];
uint256 rangeStart = 0;
if (i > 0) {
rangeStart = rangeEnds[i - 1];
}
return (_batchMetadataStorage().baseURIOfTokenIdRange[rangeEnds[i]], _tokenId - rangeStart);
}
}
revert BatchMetadataNoMetadataForTokenId();
Expand Down
4 changes: 2 additions & 2 deletions test/module/metadata/BatchMetadataERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ contract BatchMetadataERC1155Test is Test {
// read state from core
assertEq(core.uri(1), "ipfs://base/1");
assertEq(core.uri(99), "ipfs://base/99");
assertEq(core.uri(100), "ipfs://base2/100");
assertEq(core.uri(199), "ipfs://base2/199");
assertEq(core.uri(100), "ipfs://base2/0");
assertEq(core.uri(199), "ipfs://base2/99");
}

function test_revert_uploadMetadata() public {
Expand Down
4 changes: 2 additions & 2 deletions test/module/metadata/BatchMetadataERC721.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ contract BatchMetadataERC721Test is Test {
// read state from core
assertEq(core.tokenURI(1), "ipfs://base/1");
assertEq(core.tokenURI(99), "ipfs://base/99");
assertEq(core.tokenURI(100), "ipfs://base2/100");
assertEq(core.tokenURI(199), "ipfs://base2/199");
assertEq(core.tokenURI(100), "ipfs://base2/0");
assertEq(core.tokenURI(199), "ipfs://base2/99");
}

function test_revert_uploadMetadata() public {
Expand Down

0 comments on commit 9c57d1e

Please sign in to comment.