From ec515115a2dc90090726d0420d876a6a2a15b8cd Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Mon, 25 Jul 2022 15:14:55 +0000 Subject: [PATCH] misk: * Add docs. * Detailed changelog. * Move lambd is_erc721 to separate function is_erc721_metadata_compatible. --- --- 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 --- 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 --- 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 { - let is_erc721 = || { - if let Some(shema_name) = - pallet_common::Pallet::::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::(self.id) { return Err("tokenURI not set".into()); } @@ -566,6 +559,17 @@ Err("Property tokenURI not found".into()) } +fn is_erc721_metadata_compatible(collection_id: CollectionId) -> bool { + if let Some(shema_name) = + pallet_common::Pallet::::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( collection_id: CollectionId, key: &PropertyKey, -- gitstuff