difftreelog
feat(rmrk) add reject_nft
in: master
1 file changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth133 ResourceDoesntExist,133 ResourceDoesntExist,134 CannotSendToDescendentOrSelf,134 CannotSendToDescendentOrSelf,135 CannotAcceptNonOwnedNft,135 CannotAcceptNonOwnedNft,136 CannotRejectNonOwnedNft,136 }137 }137138138 #[pallet::call]139 #[pallet::call]353 Self::destroy_nft(354 Self::destroy_nft(354 cross_sender,355 cross_sender,355 Self::unique_collection_id(collection_id)?,356 Self::unique_collection_id(collection_id)?,356 misc::CollectionType::Regular,357 nft_id.into(),357 nft_id.into(),358 )?;358 ).map_err(Self::map_unique_err_to_proxy)?;359359360 Self::deposit_event(Event::NFTBurned {360 Self::deposit_event(Event::NFTBurned {361 owner: sender,361 owner: sender,505 Ok(())505 Ok(())506 }506 }507508 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]509 #[transactional]510 pub fn reject_nft(511 origin: OriginFor<T>,512 collection_id: RmrkCollectionId,513 nft_id: RmrkNftId,514 ) -> DispatchResult {515 let sender = ensure_signed(origin)?;516 let cross_sender = T::CrossAccountId::from_sub(sender);517518 let collection_id = Self::unique_collection_id(collection_id)?;519 let nft_id = nft_id.into();520521 Self::destroy_nft(522 cross_sender,523 collection_id,524 nft_id525 ).map_err(|err| {526 if err == <CommonError<T>>::NoPermission.into()527 || err == <CommonError<T>>::ApprovedValueTooLow.into() {528 <Error<T>>::CannotRejectNonOwnedNft.into()529 } else {530 Self::map_unique_err_to_proxy(err)531 }532 })?;533534 Ok(())535 }507536508 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]537 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]509 #[transactional]538 #[transactional]778 fn destroy_nft(807 fn destroy_nft(779 sender: T::CrossAccountId,808 sender: T::CrossAccountId,780 collection_id: CollectionId,809 collection_id: CollectionId,781 collection_type: misc::CollectionType,782 token_id: TokenId,810 token_id: TokenId,783 ) -> DispatchResult {811 ) -> DispatchResult {784 let collection = Self::get_typed_nft_collection(collection_id, collection_type)?;812 let collection = Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;785813786 <PalletNft<T>>::burn(&collection, &sender, token_id)814 let token_data = <TokenData<T>>::get((collection_id, token_id))787 .map_err(Self::map_unique_err_to_proxy)?;815 .ok_or(<Error<T>>::NoAvailableNftId)?;816817 let from = token_data.owner;788818789 Ok(())819 let budget = budget::Value::new(NESTING_BUDGET);820821 <PalletNft<T>>::burn_from(&collection, &sender, &from, token_id, &budget)790 }822 }791823792 fn resource_add(824 fn resource_add(