git.delta.rocks / unique-network / refs/commits / ec515115a2dc

difftreelog

misk: * Add docs. * Detailed changelog. * Move lambd is_erc721 to separate function is_erc721_metadata_compatible.

Trubnikov Sergey2022-07-25parent: #5273049.patch.diff
in: master

3 files changed

modifiedpallets/common/CHANGELOG.MDdiffbeforeafterboth
22
3All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.
44
5## [0.1.3] - 2022-07-25
6### Add
7- Some static property keys and values.
8
5## [0.1.2] - 2022-07-209## [0.1.2] - 2022-07-20
610
7### Fixed11### Fixed
812
9- Some methods in `#[solidity_interface]` for `CollectionHandle` had invalid13- Some methods in `#[solidity_interface]` for `CollectionHandle` had invalid
10 mutability modifiers, causing invalid stub/abi generation.14 mutability modifiers, causing invalid stub/abi generation.
1115
12
13## [0.1.3] - 2022-07-25
14### Add
15- Some static property keys and values.
modifiedpallets/nonfungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/nonfungible/CHANGELOG.md
+++ b/pallets/nonfungible/CHANGELOG.md
@@ -4,7 +4,14 @@
 
 ## [0.1.2] - 2022-07-25
 ### Changed
-- New alghoritm for retrieving `token_iri`.
+- New `token_uri` retrieval logic:
+
+      If the collection has a `url` property and it is not empty, it is returned.
+      Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
+
+      If the property `baseURI` is empty or absent, return "" (empty string)
+      otherwise, if property `suffix` present and is non-empty, return concatenation of baseURI and suffix
+      otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
 
 ## [0.1.1] - 2022-07-14
 ### Added
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -216,30 +216,23 @@
 	}
 
 	/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
-	/// @dev Throws if `tokenId` is not a valid NFT. URIs are defined in RFC
-	///  3986. The URI may point to a JSON file that conforms to the "ERC721
-	///  Metadata JSON Schema".
+	///
+	/// @dev If the collection has a `url` property and it is not empty, it is returned.
+	///		Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.
+	///
+	///		If the property `baseURI` is empty or absent, return "" (empty string)
+	///		otherwise, if property `suffix` present and is non-empty, return concatenation of baseURI and suffix
+	///		otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
 	/// @return token's const_metadata
 	#[solidity(rename_selector = "tokenURI")]
 	fn token_uri(&self, token_id: uint256) -> Result<string> {
-		let is_erc721 = || {
-			if let Some(shema_name) =
-				pallet_common::Pallet::<T>::get_collection_property(self.id, &key::schema_name())
-			{
-				let shema_name = shema_name.into_inner();
-				shema_name == property_value::ERC721_METADATA
-			} else {
-				false
-			}
-		};
-
 		let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
 
 		if let Ok(url) = get_token_property(self, token_id_u32, &key::url()) {
 			if !url.is_empty() {
 				return Ok(url);
 			}
-		} else if !is_erc721() {
+		} else if !is_erc721_metadata_compatible::<T>(self.id) {
 			return Err("tokenURI not set".into());
 		}
 
@@ -566,6 +559,17 @@
 	Err("Property tokenURI not found".into())
 }
 
+fn is_erc721_metadata_compatible<T: Config>(collection_id: CollectionId) -> bool {
+	if let Some(shema_name) =
+		pallet_common::Pallet::<T>::get_collection_property(collection_id, &key::schema_name())
+	{
+		let shema_name = shema_name.into_inner();
+		shema_name == property_value::ERC721_METADATA
+	} else {
+		false
+	}
+}
+
 fn get_token_permission<T: Config>(
 	collection_id: CollectionId,
 	key: &PropertyKey,