diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index bf38f1e..da5fe98 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,3 +1,4 @@ # Github Actions automatically updated formatting with forge fmt\nf3389931e6f7d25a65c1ba2d055c8a43606b40e5 # Github Actions automatically updated formatting with forge fmt\n3b40d0f5cfd25b67a335ee2c8d7c9660d5bfd7f5 # Github Actions automatically updated formatting with forge fmt\n2d96311b29055c5b9a0b632176ce3b8d78a23a89 +# Github Actions automatically updated formatting with forge fmt\ne2d336bbb0331c7716c16fed64f51be6c270ad02 diff --git a/src/dynamic-traits/DynamicTraits.sol b/src/dynamic-traits/DynamicTraits.sol index 88cb176..26014a0 100644 --- a/src/dynamic-traits/DynamicTraits.sol +++ b/src/dynamic-traits/DynamicTraits.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.19; import {EnumerableSet} from "openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol"; import {IERC7496} from "./interfaces/IERC7496.sol"; -abstract contract DynamicTraits is IERC7496 { +contract DynamicTraits is IERC7496 { using EnumerableSet for EnumerableSet.Bytes32Set; /// @notice Thrown when a new trait value is not different from the existing value @@ -58,13 +58,14 @@ abstract contract DynamicTraits is IERC7496 { } /** - * @notice Set the value of a trait for a given token ID. If newTrait is bytes32(0), sets the zero value hash. - * Reverts if the trait value is the zero value hash. + * @notice Set the value of a trait for a given token ID. + * Reverts if the trait value is unchanged. + * @dev IMPORTANT: Override this method with access role restriction. * @param tokenId The token ID to set the trait value for * @param traitKey The trait key to set the value of * @param newValue The new trait value to set */ - function _setTrait(uint256 tokenId, bytes32 traitKey, bytes32 newValue) internal { + function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 newValue) public virtual { bytes32 existingValue = _traits[tokenId][traitKey]; if (existingValue == newValue) { diff --git a/src/dynamic-traits/ERC721DynamicTraits.sol b/src/dynamic-traits/ERC721DynamicTraits.sol index 49e3bdd..0a41074 100644 --- a/src/dynamic-traits/ERC721DynamicTraits.sol +++ b/src/dynamic-traits/ERC721DynamicTraits.sol @@ -10,11 +10,11 @@ contract ERC721DynamicTraits is DynamicTraits, Ownable, ERC721 { _traitMetadataURI = "https://example.com"; } - function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 value) external virtual override onlyOwner { + function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 value) public virtual override onlyOwner { // Revert if the token doesn't exist. _requireOwned(tokenId); - _setTrait(tokenId, traitKey, value); + DynamicTraits.setTrait(tokenId, traitKey, value); } function getTraitValue(uint256 tokenId, bytes32 traitKey) diff --git a/src/dynamic-traits/ERC721OnchainTraits.sol b/src/dynamic-traits/ERC721OnchainTraits.sol index 7744754..d4ca9c1 100644 --- a/src/dynamic-traits/ERC721OnchainTraits.sol +++ b/src/dynamic-traits/ERC721OnchainTraits.sol @@ -10,11 +10,11 @@ contract ERC721OnchainTraits is OnchainTraits, ERC721 { _traitMetadataURI = "https://example.com"; } - function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 value) external virtual override onlyOwner { + function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 value) public virtual override onlyOwner { // Revert if the token doesn't exist. _requireOwned(tokenId); - _setTrait(tokenId, traitKey, value); + DynamicTraits.setTrait(tokenId, traitKey, value); } function getTraitValue(uint256 tokenId, bytes32 traitKey) diff --git a/src/dynamic-traits/OnchainTraits.sol b/src/dynamic-traits/OnchainTraits.sol index e45c92e..8fc4b33 100644 --- a/src/dynamic-traits/OnchainTraits.sol +++ b/src/dynamic-traits/OnchainTraits.sol @@ -111,7 +111,7 @@ abstract contract OnchainTraits is Ownable, DynamicTraits { * @param traitKey The trait key to get the value of * @param newValue The new trait value */ - function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 newValue) external virtual override { + function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 newValue) public virtual override { TraitLabelStorage memory labelStorage = traitLabelStorage[traitKey]; StoredTraitLabel storedTraitLabel = labelStorage.storedLabel; if (!StoredTraitLabelLib.exists(storedTraitLabel)) { @@ -122,7 +122,7 @@ abstract contract OnchainTraits is Ownable, DynamicTraits { if (labelStorage.valuesRequireValidation) { TraitLabelLib.validateAcceptableValue(StoredTraitLabelLib.load(storedTraitLabel), traitKey, newValue); } - _setTrait(tokenId, traitKey, newValue); + DynamicTraits.setTrait(tokenId, traitKey, newValue); } /** diff --git a/src/dynamic-traits/interfaces/IERC7496.sol b/src/dynamic-traits/interfaces/IERC7496.sol index be74b95..130fa92 100644 --- a/src/dynamic-traits/interfaces/IERC7496.sol +++ b/src/dynamic-traits/interfaces/IERC7496.sol @@ -5,9 +5,9 @@ import {IERC165} from "forge-std/interfaces/IERC165.sol"; interface IERC7496 is IERC165 { /* Events */ - event TraitUpdated(bytes32 indexed traitKey, uint256 indexed tokenId, bytes32 trait); - event TraitUpdatedBulkRange(bytes32 indexed traitKeyPattern, uint256 fromTokenId, uint256 toTokenId); - event TraitUpdatedBulkList(bytes32 indexed traitKeyPattern, uint256[] tokenIds); + event TraitUpdated(bytes32 indexed traitKey, uint256 tokenId, bytes32 trait); + event TraitUpdatedBulkRange(bytes32 indexed traitKey, uint256 fromTokenId, uint256 toTokenId, bytes32 traitValue); + event TraitUpdatedBulkList(bytes32 indexed traitKey, uint256[] tokenIds, bytes32 traitValue); event TraitMetadataURIUpdated(); /* Getters */ diff --git a/test/dynamic-traits/ERC721DynamicTraits.t.sol b/test/dynamic-traits/ERC721DynamicTraits.t.sol index cb94565..2857f2f 100644 --- a/test/dynamic-traits/ERC721DynamicTraits.t.sol +++ b/test/dynamic-traits/ERC721DynamicTraits.t.sol @@ -21,9 +21,11 @@ contract ERC721DynamicTraitsTest is Test { ERC721DynamicTraitsMintable token; /* Events */ - event TraitUpdated(bytes32 indexed traitKey, uint256 indexed tokenId, bytes32 value); - event TraitUpdatedBulkConsecutive(bytes32 indexed traitKeyPattern, uint256 fromTokenId, uint256 toTokenId); - event TraitUpdatedBulkList(bytes32 indexed traitKeyPattern, uint256[] tokenIds); + event TraitUpdated(bytes32 indexed traitKey, uint256 tokenId, bytes32 traitValue); + event TraitUpdatedBulkConsecutive( + bytes32 indexed traitKeyPattern, uint256 fromTokenId, uint256 toTokenId, bytes32 traitValue + ); + event TraitUpdatedBulkList(bytes32 indexed traitKeyPattern, uint256[] tokenIds, bytes32 traitValue); event TraitMetadataURIUpdated(); function setUp() public {