draft-ERC6909ContentURI.sol 1.5 KB

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