difftreelog
feat(rmrk-proxy) delete-resource
in: master
1 file changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth103 nft_id: RmrkNftId,103 nft_id: RmrkNftId,104 resource_id: RmrkResourceId,104 resource_id: RmrkResourceId,105 },105 },106 ResourceRemoval {107 nft_id: RmrkNftId,108 resource_id: RmrkResourceId,109 },106 }110 }107111108 #[pallet::error]112 #[pallet::error]120 CollectionUnknown,124 CollectionUnknown,121 NoPermission,125 NoPermission,122 CollectionFullOrLocked,126 CollectionFullOrLocked,123 // todo add resource errors?127 ResourceDoesntExist,124 }128 }125129126 #[pallet::call]130 #[pallet::call]160 Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,164 Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,161 ]165 ]162 .into_iter(),166 .into_iter(),163 )?; //collection_id_res?;167 )?;164 let rmrk_collection_id = <CollectionIndex<T>>::get();168 let rmrk_collection_id = <CollectionIndex<T>>::get();165169166 <CollectionIndexMap<T>>::insert(rmrk_collection_id, unique_collection_id);170 <CollectionIndexMap<T>>::insert(rmrk_collection_id, unique_collection_id);307 .into_iter(),311 .into_iter(),308 )?,312 )?,309 )?, // todo possibly add limits to the collection if rmrk warrants them313 )?, // todo possibly add limits to the collection if rmrk warrants them310 Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?, // todo create resource priorities?314 Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?,311 ]315 ]312 .into_iter(),316 .into_iter(),313 )317 )505 Ok(())509 Ok(())506 }510 }511512 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]513 #[transactional]514 pub fn remove_resource(515 origin: OriginFor<T>,516 collection_id: RmrkCollectionId,517 nft_id: RmrkNftId,518 resource_id: RmrkResourceId,519 ) -> DispatchResult {520 let sender = ensure_signed(origin.clone())?;521522 Self::resource_remove(523 sender,524 Self::unique_collection_id(collection_id)?,525 nft_id.into(),526 resource_id.into(),527 )?;528529 Self::deposit_event(Event::ResourceRemoval {530 nft_id,531 resource_id,532 });533 Ok(())534 }507 }535 }508}536}509537518 Ok(scoped_key)546 Ok(scoped_key)519 }547 }520548549 // todo think about renaming these521 pub fn rmrk_property<E: Encode>(550 pub fn rmrk_property<E: Encode>(522 // todo think about renaming this523 rmrk_key: RmrkProperty,551 rmrk_key: RmrkProperty,524 value: &E,552 value: &E,525 ) -> Result<Property, DispatchError> {553 ) -> Result<Property, DispatchError> {624652625 let sender = T::CrossAccountId::from_sub(sender);653 let sender = T::CrossAccountId::from_sub(sender);626 let budget = budget::Value::new(10);654 let budget = budget::Value::new(10);627 let pending = <PalletStructure<T>>::check_indirectly_owned(655 let pending = !<PalletStructure<T>>::check_indirectly_owned(628 sender.clone(),656 sender.clone(),629 collection_id,657 collection_id,630 token_id,658 token_id,659 Ok(resource_id.0)687 Ok(resource_id.0)660 }688 }689690 fn resource_remove(691 sender: T::AccountId,692 collection_id: CollectionId,693 nft_id: TokenId,694 resource_id: TokenId,695 ) -> DispatchResult {696 let collection =697 Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;698 ensure!(collection.owner == sender, Error::<T>::NoPermission);699700 let resource_collection_id: CollectionId =701 Self::get_nft_property_decoded(collection_id, nft_id, ResourceCollection)?;702 let resource_collection =703 Self::get_typed_nft_collection(resource_collection_id, misc::CollectionType::Resource)?;704 ensure!(705 <PalletNft<T>>::token_exists(&resource_collection, resource_id),706 Error::<T>::ResourceDoesntExist707 );708709 let budget = up_data_structs::budget::Value::new(10);710 let topmost_owner =711 <PalletStructure<T>>::find_topmost_owner(collection_id, nft_id, &budget)?;712713 let sender = T::CrossAccountId::from_sub(sender);714 if topmost_owner == sender {715 <PalletNft<T>>::burn(&collection, &sender, nft_id)716 .map_err(Self::map_common_err_to_proxy)?;717 } else {718 <PalletNft<T>>::set_scoped_token_property(719 collection_id,720 nft_id,721 PropertyScope::Rmrk,722 Self::rmrk_property(PendingResourceRemoval, &true)?,723 )?;724 }725726 Ok(())727 }661728662 fn change_collection_owner(729 fn change_collection_owner(663 collection_id: CollectionId,730 collection_id: CollectionId,