difftreelog
misk: * Add docs. * Detailed changelog. * Move lambd is_erc721 to separate function is_erc721_metadata_compatible.
in: master
3 files changed
pallets/common/CHANGELOG.MDdiffbeforeafterboth223All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.445## [0.1.3] - 2022-07-256### Add7- Some static property keys and values.85## [0.1.2] - 2022-07-209## [0.1.2] - 2022-07-206107### Fixed11### Fixed8129- Some methods in `#[solidity_interface]` for `CollectionHandle` had invalid13- Some methods in `#[solidity_interface]` for `CollectionHandle` had invalid10 mutability modifiers, causing invalid stub/abi generation.14 mutability modifiers, causing invalid stub/abi generation.11151213## [0.1.3] - 2022-07-2514### Add15- Some static property keys and values.pallets/nonfungible/CHANGELOG.mddiffbeforeafterboth445## [0.1.2] - 2022-07-255## [0.1.2] - 2022-07-256### Changed6### Changed7- New alghoritm for retrieving `token_iri`.7- New `token_uri` retrieval logic:889 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`.1112 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 suffix14 otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).159## [0.1.1] - 2022-07-1416## [0.1.1] - 2022-07-1410### Added17### Added1118pallets/nonfungible/src/erc.rsdiffbeforeafterboth216 }216 }217217218 /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.218 /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.219 /// @dev Throws if `tokenId` is not a valid NFT. URIs are defined in RFC219 ///220 /// 3986. The URI may point to a JSON file that conforms to the "ERC721220 /// @dev If the collection has a `url` property and it is not empty, it is returned.221 /// Metadata JSON Schema".221 /// 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`.222 ///223 /// If the property `baseURI` is empty or absent, return "" (empty string)224 /// otherwise, if property `suffix` present and is non-empty, return concatenation of baseURI and suffix225 /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).222 /// @return token's const_metadata226 /// @return token's const_metadata223 #[solidity(rename_selector = "tokenURI")]227 #[solidity(rename_selector = "tokenURI")]224 fn token_uri(&self, token_id: uint256) -> Result<string> {228 fn token_uri(&self, token_id: uint256) -> Result<string> {225 let is_erc721 = || {226 if let Some(shema_name) =227 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::schema_name())228 {229 let shema_name = shema_name.into_inner();230 shema_name == property_value::ERC721_METADATA231 } else {232 false233 }234 };235236 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;229 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;237230238 if let Ok(url) = get_token_property(self, token_id_u32, &key::url()) {231 if let Ok(url) = get_token_property(self, token_id_u32, &key::url()) {239 if !url.is_empty() {232 if !url.is_empty() {240 return Ok(url);233 return Ok(url);241 }234 }242 } else if !is_erc721() {235 } else if !is_erc721_metadata_compatible::<T>(self.id) {243 return Err("tokenURI not set".into());236 return Err("tokenURI not set".into());244 }237 }245238566 Err("Property tokenURI not found".into())559 Err("Property tokenURI not found".into())567}560}561562fn is_erc721_metadata_compatible<T: Config>(collection_id: CollectionId) -> bool {563 if let Some(shema_name) =564 pallet_common::Pallet::<T>::get_collection_property(collection_id, &key::schema_name())565 {566 let shema_name = shema_name.into_inner();567 shema_name == property_value::ERC721_METADATA568 } else {569 false570 }571}568572569fn get_token_permission<T: Config>(573fn get_token_permission<T: Config>(570 collection_id: CollectionId,574 collection_id: CollectionId,