difftreelog
feat(rmrk) make resources lazy
in: master
2 files changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth158 NftTypeEncodeError,158 NftTypeEncodeError,159 RmrkPropertyKeyIsTooLong,159 RmrkPropertyKeyIsTooLong,160 RmrkPropertyValueIsTooLong,160 RmrkPropertyValueIsTooLong,161 UnableToDecodeRmrkData,161162162 /* RMRK compatible events */163 /* RMRK compatible events */163 CollectionNotEmpty,164 CollectionNotEmpty,378 Self::rmrk_property(RoyaltyInfo, &royalty_info)?,379 Self::rmrk_property(RoyaltyInfo, &royalty_info)?,379 Self::rmrk_property(Metadata, &metadata)?,380 Self::rmrk_property(Metadata, &metadata)?,380 Self::rmrk_property(Equipped, &false)?,381 Self::rmrk_property(Equipped, &false)?,381 Self::rmrk_property(382 Self::rmrk_property(ResourceCollection, &None::<CollectionId>)?,382 ResourceCollection,383 &Self::init_collection(384 sender.clone(),385 CreateCollectionData {386 ..Default::default()387 },388 [Self::rmrk_property(389 CollectionType,390 &misc::CollectionType::Resource,391 )?]392 .into_iter(),393 )?,394 )?, // todo possibly add limits to the collection if rmrk warrants them395 Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?,383 Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?,396 ]384 ]397 .into_iter(),385 .into_iter(),702 <PalletStructure<T>>::find_topmost_owner(collection_id, nft_id, &budget)690 <PalletStructure<T>>::find_topmost_owner(collection_id, nft_id, &budget)703 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;691 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;704692705 let resource_collection_id: CollectionId =693 let resource_collection_id: Option<CollectionId> =706 Self::get_nft_property_decoded(collection_id, nft_id, ResourceCollection)694 Self::get_nft_property_decoded(collection_id, nft_id, ResourceCollection)707 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;695 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;696 697 let resource_collection_id = resource_collection_id.ok_or(<Error<T>>::ResourceDoesntExist)?;708698709 let is_pending: bool = Self::get_nft_property_decoded(699 let is_pending: bool = Self::get_nft_property_decoded(710 resource_collection_id,700 resource_collection_id,761751762 ensure!(cross_sender == nft_owner, <Error<T>>::NoPermission);752 ensure!(cross_sender == nft_owner, <Error<T>>::NoPermission);763753764 let resource_collection_id: CollectionId =754 let resource_collection_id: Option<CollectionId> =765 Self::get_nft_property_decoded(collection_id, nft_id, ResourceCollection)755 Self::get_nft_property_decoded(collection_id, nft_id, ResourceCollection)766 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;756 .map_err(|_| <Error<T>>::ResourceDoesntExist)?;757758 let resource_collection_id = resource_collection_id.ok_or(<Error<T>>::ResourceDoesntExist)?;767759768 let is_pending: bool = Self::get_nft_property_decoded(760 let is_pending: bool = Self::get_nft_property_decoded(769 resource_collection_id,761 resource_collection_id,106510571066 pub fn decode_property<D: Decode>(vec: PropertyValue) -> Result<D, DispatchError> {1058 pub fn decode_property<D: Decode>(vec: PropertyValue) -> Result<D, DispatchError> {1067 vec.decode()1059 vec.decode()1068 .map_err(|_| <Error<T>>::RmrkPropertyValueIsTooLong.into())1060 .map_err(|_| <Error<T>>::UnableToDecodeRmrkData.into())1069 }1061 }107010621071 pub fn rebind<L, S>(vec: &BoundedVec<u8, L>) -> Result<BoundedVec<u8, S>, DispatchError>1063 pub fn rebind<L, S>(vec: &BoundedVec<u8, L>) -> Result<BoundedVec<u8, S>, DispatchError>118111731182 let pending = sender != nft_owner;1174 let pending = sender != nft_owner;118311751184 let resource_collection_id: CollectionId =1176 let resource_collection_id: Option<CollectionId> =1185 Self::get_nft_property_decoded(collection_id, token_id, ResourceCollection)?;1177 Self::get_nft_property_decoded(collection_id, token_id, ResourceCollection)?;11781179 let resource_collection_id = match resource_collection_id {1180 Some(id) => id,1181 None => {1182 let resource_collection_id = Self::init_collection(1183 sender.clone(),1184 CreateCollectionData {1185 ..Default::default()1186 },1187 [1188 Self::rmrk_property(1189 CollectionType,1190 &misc::CollectionType::Resource,1191 )?1192 ]1193 .into_iter(),1194 )?;11951196 <PalletNft<T>>::set_scoped_token_property(1197 collection_id,1198 token_id,1199 PropertyScope::Rmrk,1200 Self::rmrk_property(ResourceCollection, &Some(resource_collection_id))?1201 )?;12021203 resource_collection_id1204 }1205 };12061186 let resource_collection =1207 let resource_collection =1187 Self::get_typed_nft_collection(resource_collection_id, misc::CollectionType::Resource)?;1208 Self::get_typed_nft_collection(resource_collection_id, misc::CollectionType::Resource)?;1218 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;1239 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;1219 ensure!(collection.owner == sender, Error::<T>::NoPermission);1240 ensure!(collection.owner == sender, Error::<T>::NoPermission);122012411221 let resource_collection_id: CollectionId =1242 let resource_collection_id: Option<CollectionId> =1222 Self::get_nft_property_decoded(collection_id, nft_id, ResourceCollection)?;1243 Self::get_nft_property_decoded(collection_id, nft_id, ResourceCollection)?;12441245 let resource_collection_id = resource_collection_id.ok_or(Error::<T>::ResourceDoesntExist)?;1246 1223 let resource_collection =1247 let resource_collection =1224 Self::get_typed_nft_collection(resource_collection_id, misc::CollectionType::Resource)?;1248 Self::get_typed_nft_collection(resource_collection_id, misc::CollectionType::Resource)?;runtime/common/src/runtime_apis.rsdiffbeforeafterboth339 let nft_id = TokenId(nft_id);339 let nft_id = TokenId(nft_id);340 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(Vec::new()); }340 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(Vec::new()); }341341342 let res_collection_id: CollectionId = RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::ResourceCollection)?;342 let res_collection_id: Option<CollectionId> = RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::ResourceCollection)?;343344 let res_collection_id = match res_collection_id {345 Some(id) => id,346 None => return Ok(Vec::new())347 };348343 let resource_collection = RmrkCore::get_typed_nft_collection(res_collection_id, CollectionType::Resource)?;349 let resource_collection = RmrkCore::get_typed_nft_collection(res_collection_id, CollectionType::Resource)?;344350