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
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
216 }216 }
217217
218 /// @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 suffix
225 /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).
222 /// @return token's const_metadata226 /// @return token's const_metadata
223 #[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_METADATA
231 } else {
232 false
233 }
234 };
235
236 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")?;
237230
238 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 }
245238
566 Err("Property tokenURI not found".into())559 Err("Property tokenURI not found".into())
567}560}
561
562fn 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_METADATA
568 } else {
569 false
570 }
571}
568572
569fn get_token_permission<T: Config>(573fn get_token_permission<T: Config>(
570 collection_id: CollectionId,574 collection_id: CollectionId,