draft-ERC6909ContentURI.sol 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.3.0) (token/ERC6909/extensions/draft-ERC6909ContentURI.sol)
  3. pragma solidity ^0.8.20;
  4. import {ERC6909} from "../draft-ERC6909.sol";
  5. import {IERC6909ContentURI} from "../../../interfaces/draft-IERC6909.sol";
  6. /**
  7. * @dev Implementation of the Content URI extension defined in ERC6909.
  8. */
  9. contract ERC6909ContentURI is ERC6909, IERC6909ContentURI {
  10. string private _contractURI;
  11. mapping(uint256 id => string) private _tokenURIs;
  12. /// @dev Event emitted when the contract URI is changed. See https://eips.ethereum.org/EIPS/eip-7572[ERC-7572] for details.
  13. event ContractURIUpdated();
  14. /// @dev See {IERC1155-URI}
  15. event URI(string value, uint256 indexed id);
  16. /// @inheritdoc IERC6909ContentURI
  17. function contractURI() public view virtual override returns (string memory) {
  18. return _contractURI;
  19. }
  20. /// @inheritdoc IERC6909ContentURI
  21. function tokenURI(uint256 id) public view virtual override returns (string memory) {
  22. return _tokenURIs[id];
  23. }
  24. /**
  25. * @dev Sets the {contractURI} for the contract.
  26. *
  27. * Emits a {ContractURIUpdated} event.
  28. */
  29. function _setContractURI(string memory newContractURI) internal virtual {
  30. _contractURI = newContractURI;
  31. emit ContractURIUpdated();
  32. }
  33. /**
  34. * @dev Sets the {tokenURI} for a given token of type `id`.
  35. *
  36. * Emits a {URI} event.
  37. */
  38. function _setTokenURI(uint256 id, string memory newTokenURI) internal virtual {
  39. _tokenURIs[id] = newTokenURI;
  40. emit URI(newTokenURI, id);
  41. }
  42. }