git.delta.rocks / unique-network / refs/commits / 4f3a569f7f40

difftreelog

CORE-346 Fix recieving tokenURI

Trubnikov Sergey2022-05-26parent: #c269096.patch.diff
in: master

2 files changed

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
161 let key: string = "tokenURI".into(); //TODO: make static161 let key: string = "tokenURI".into(); //TODO: make static
162 let key: up_data_structs::PropertyKey = key.into_bytes().try_into()162 let key: up_data_structs::PropertyKey = key.into_bytes().try_into()
163 .map_err(|_| Error::Revert("".into()))?;163 .map_err(|_| Error::Revert("".into()))?;
164 let permission = get_permission::<T>(self.id, &key)?;164 let permission = get_token_permission::<T>(self.id, &key)?;
165 if !permission.collection_admin {165 if !permission.collection_admin {
166 return Err("Operation is not allowed".into());166 return Err("Operation is not allowed".into());
167 }167 }
168168
169 self.consume_store_reads(1)?;169 self.consume_store_reads(1)?;
170 let _token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;170 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
171
172 let properties = <TokenProperties<T>>::try_get((self.id, token_id))
173 .map_err(|_| Error::Revert("Token properties not found".into()))?;
174 if let Some(property) = properties.get(&key) {
171 Ok(string::from_utf8_lossy(175 return Ok(string::from_utf8_lossy(property).into());
172 todo!()176 }
173 )177
174 .into())178 Err("Property tokenURI not found".into())
175 }179 }
176}180}
177181
361 let key: string = "tokenURI".into(); //TODO: make static365 let key: string = "tokenURI".into(); //TODO: make static
362 let key: up_data_structs::PropertyKey = key.into_bytes().try_into()366 let key: up_data_structs::PropertyKey = key.into_bytes().try_into()
363 .map_err(|_| Error::Revert("".into()))?;367 .map_err(|_| Error::Revert("".into()))?;
364 let permission = get_permission::<T>(self.id, &key)?;368 let permission = get_token_permission::<T>(self.id, &key)?;
365 if !permission.collection_admin {369 if !permission.collection_admin {
366 return Err("Operation is not allowed".into());370 return Err("Operation is not allowed".into());
367 }371 }
407 }411 }
408}412}
409413
410fn get_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> Result<PropertyPermission> {414fn get_token_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> Result<PropertyPermission> {
411 let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)415 let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)
412 .map_err(|_| Error::Revert("No permissions for collection".into()))?;416 .map_err(|_| Error::Revert("No permissions for collection".into()))?;
413 Ok(token_property_permissions.get(key)417 let a = token_property_permissions.get(key)
414 .map(|p| p.clone())418 .map(|p| p.clone())
415 .ok_or_else(|| Error::Revert("No permission for tokenURI".into()))?)419 .ok_or_else(|| Error::Revert("No permission for tokenURI".into()))?;
420 Ok(a)
416}421}
417422
418#[solidity_interface(name = "ERC721UniqueExtensions")]423#[solidity_interface(name = "ERC721UniqueExtensions")]
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -187,7 +187,7 @@
       .isCollectionExist(collectionAddressForNonexistentCollection).call())
       .to.be.false;
     
-    const result = await collectionHelper.methods.create721Collection('Const collection', '5', '5').send();
+    const result = await collectionHelper.methods.create721Collection('Collection address exist', '7', '7').send();
     const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
     expect(await collectionHelper.methods
       .isCollectionExist(collectionIdAddress).call())