* 4.6.0-rc.0 * Fix release script to only release @openzeppelin/contracts (cherry picked from commit2bd75a44bb) * make ERC2981:royaltyInfo public (#3305) (cherry picked from commitd2832ca7a9) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * add transpilation guards to the crosschain mocks (#3306) (cherry picked from commit9af5af8fff) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Fix tests on upgradeable contracts after transpilation (cherry picked from commit0762479dd5) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Remove unused constructor argument (cherry picked from commit69c3781043) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * Bump minimum Solidity version for Initializable.sol to 0.8.2 (#3328) (cherry picked from commitcb14ea3c5c) * Fix update-comment script to ignore invalid tags (cherry picked from commit848fef5b6c) Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com> * 4.6.0 Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
64 lines
2.0 KiB
Solidity
64 lines
2.0 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC1155/extensions/ERC1155URIStorage.sol)
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
import "../../../utils/Strings.sol";
|
|
import "../ERC1155.sol";
|
|
|
|
/**
|
|
* @dev ERC1155 token with storage based token URI management.
|
|
* Inspired by the ERC721URIStorage extension
|
|
*
|
|
* _Available since v4.6._
|
|
*/
|
|
abstract contract ERC1155URIStorage is ERC1155 {
|
|
using Strings for uint256;
|
|
|
|
// Optional base URI
|
|
string private _baseURI = "";
|
|
|
|
// Optional mapping for token URIs
|
|
mapping(uint256 => string) private _tokenURIs;
|
|
|
|
/**
|
|
* @dev See {IERC1155MetadataURI-uri}.
|
|
*
|
|
* This implementation returns the concatenation of the `_baseURI`
|
|
* and the token-specific uri if the latter is set
|
|
*
|
|
* This enables the following behaviors:
|
|
*
|
|
* - if `_tokenURIs[tokenId]` is set, then the result is the concatenation
|
|
* of `_baseURI` and `_tokenURIs[tokenId]` (keep in mind that `_baseURI`
|
|
* is empty per default);
|
|
*
|
|
* - if `_tokenURIs[tokenId]` is NOT set then we fallback to `super.uri()`
|
|
* which in most cases will contain `ERC1155._uri`;
|
|
*
|
|
* - if `_tokenURIs[tokenId]` is NOT set, and if the parents do not have a
|
|
* uri value set, then the result is empty.
|
|
*/
|
|
function uri(uint256 tokenId) public view virtual override returns (string memory) {
|
|
string memory tokenURI = _tokenURIs[tokenId];
|
|
|
|
// If token URI is set, concatenate base URI and tokenURI (via abi.encodePacked).
|
|
return bytes(tokenURI).length > 0 ? string(abi.encodePacked(_baseURI, tokenURI)) : super.uri(tokenId);
|
|
}
|
|
|
|
/**
|
|
* @dev Sets `tokenURI` as the tokenURI of `tokenId`.
|
|
*/
|
|
function _setURI(uint256 tokenId, string memory tokenURI) internal virtual {
|
|
_tokenURIs[tokenId] = tokenURI;
|
|
emit URI(uri(tokenId), tokenId);
|
|
}
|
|
|
|
/**
|
|
* @dev Sets `baseURI` as the `_baseURI` for all tokens
|
|
*/
|
|
function _setBaseURI(string memory baseURI) internal virtual {
|
|
_baseURI = baseURI;
|
|
}
|
|
}
|