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
--- a/pallets/common/CHANGELOG.MD
+++ b/pallets/common/CHANGELOG.MD
@@ -2,14 +2,13 @@
 
 All notable changes to this project will be documented in this file.
 
+## [0.1.3] - 2022-07-25
+### Add
+-   Some static property keys and values.
+
 ## [0.1.2] - 2022-07-20
 
 ### Fixed
 
 -   Some methods in `#[solidity_interface]` for `CollectionHandle` had invalid
     mutability modifiers, causing invalid stub/abi generation.
-
-
-## [0.1.3] - 2022-07-25
-### Add
--   Some static property keys and values.
\ No newline at end of file
modifiedpallets/nonfungible/CHANGELOG.mddiffbeforeafterboth
44
5## [0.1.2] - 2022-07-255## [0.1.2] - 2022-07-25
6### Changed6### Changed
7- New alghoritm for retrieving `token_iri`.7- New `token_uri` retrieval logic:
88
9 If the collection has a `url` property and it is not empty, it is returned.
10 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`.
11
12 If the property `baseURI` is empty or absent, return "" (empty string)
13 otherwise, if property `suffix` present and is non-empty, return concatenation of baseURI and suffix
14 otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
15
9## [0.1.1] - 2022-07-1416## [0.1.1] - 2022-07-14
10### Added17### Added
1118
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,