@@ -87,7 +87,7 @@ contract DynamicTraits is IERC7496 {
8787
8888 /**
8989 * @notice Set the value of a trait for a given token ID.
90- * Reverts if the trait value is unchanged.
90+ * Reverts if the trait key is not registered or the value is unchanged.
9191 * @dev IMPORTANT: Override this method with access role restriction.
9292 * @param tokenId The token ID to set the trait value for
9393 * @param traitKey The trait key to set the value of
@@ -96,7 +96,7 @@ contract DynamicTraits is IERC7496 {
9696 function setTrait (uint256 tokenId , bytes32 traitKey , bytes32 newValue ) public virtual {
9797 DynamicTraitsStorage.Layout storage layout = DynamicTraitsStorage.layout ();
9898
99- // Revert if the trait key does not exist .
99+ // Revert if the trait key is not registered .
100100 if (! layout._validTraitKeys[traitKey]) {
101101 revert TraitDoesNotExist (traitKey);
102102 }
@@ -137,6 +137,30 @@ contract DynamicTraits is IERC7496 {
137137 emit TraitMetadataURIUpdated ();
138138 }
139139
140+ /**
141+ * @notice Set the URI for the trait metadata and register trait keys.
142+ * @param uri The new URI to set.
143+ * @param traitKeys The trait keys to register.
144+ */
145+ function _setTraitMetadataURI (string memory uri , bytes32 [] memory traitKeys ) internal virtual {
146+ DynamicTraitsStorage.Layout storage layout = DynamicTraitsStorage.layout ();
147+
148+ // Register all trait keys.
149+ uint256 length = traitKeys.length ;
150+ for (uint256 i = 0 ; i < length;) {
151+ layout._validTraitKeys[traitKeys[i]] = true ;
152+ unchecked {
153+ ++ i;
154+ }
155+ }
156+
157+ // Set the new trait metadata URI.
158+ layout._traitMetadataURI = uri;
159+
160+ // Emit the event noting the update.
161+ emit TraitMetadataURIUpdated ();
162+ }
163+
140164 /**
141165 * @notice Register a trait key as valid.
142166 * @param traitKey The trait key to register.
0 commit comments