123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#![recursion_limit = "1024"]67#![cfg_attr(not(feature = "std"), no_std)]68#![allow(69 clippy::too_many_arguments,70 clippy::unnecessary_mut_passed,71 clippy::unused_unit72)]7374extern crate alloc;7576use frame_support::{77 decl_module, decl_storage, decl_error, decl_event,78 dispatch::DispatchResult,79 ensure, fail,80 weights::{Weight},81 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},82 BoundedVec,83};84use scale_info::TypeInfo;85use frame_system::{self as system, ensure_signed};86use sp_std::{vec, vec::Vec};87use up_data_structs::{88 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,89 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,90 SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,91 PropertyKeyPermission,92};93use pallet_evm::account::CrossAccountId;94use pallet_common::{95 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,96 dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,97};98pub mod eth;99100#[cfg(feature = "runtime-benchmarks")]101pub mod benchmarking;102pub mod weights;103use weights::WeightInfo;104105106pub const NESTING_BUDGET: u32 = 5;107108decl_error! {109 110 pub enum Error for Module<T: Config> {111 112 CollectionDecimalPointLimitExceeded,113 114 ConfirmUnsetSponsorFail,115 116 EmptyArgument,117 118 RepartitionCalledOnNonRefungibleCollection,119 }120}121122123pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {124 125 type RuntimeEvent: From<Event<Self>> + Into<<Self as frame_system::Config>::RuntimeEvent>;126127 128 type WeightInfo: WeightInfo;129130 131 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;132133 134 type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;135}136137decl_event! {138 pub enum Event<T>139 where140 <T as frame_system::Config>::AccountId,141 <T as pallet_evm::account::Config>::CrossAccountId,142 {143 144 145 146 147 CollectionSponsorRemoved(CollectionId),148149 150 151 152 153 154 CollectionAdminAdded(CollectionId, CrossAccountId),155156 157 158 159 160 161 CollectionOwnedChanged(CollectionId, AccountId),162163 164 165 166 167 168 CollectionSponsorSet(CollectionId, AccountId),169170 171 172 173 174 175 SponsorshipConfirmed(CollectionId, AccountId),176177 178 179 180 181 182 CollectionAdminRemoved(CollectionId, CrossAccountId),183184 185 186 187 188 189 AllowListAddressRemoved(CollectionId, CrossAccountId),190191 192 193 194 195 196 AllowListAddressAdded(CollectionId, CrossAccountId),197198 199 200 201 202 CollectionLimitSet(CollectionId),203204 205 206 207 208 CollectionPermissionSet(CollectionId),209 }210}211212type SelfWeightOf<T> = <T as Config>::WeightInfo;213214215216217218219220221222223224225226227228229230231232233234235236decl_storage! {237 trait Store for Module<T: Config> as Unique {238239 240 241 ChainVersion: u64;242 243244 245 246 247 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;248 249 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;250 251 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;252 253 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;254 255256 257 258 #[deprecated]259 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;260 261 pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;262263 264 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;265 266 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;267 268 pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;269 }270}271272decl_module! {273 274 pub struct Module<T: Config> for enum Call275 where276 origin: T::RuntimeOrigin277 {278 type Error = Error<T>;279280 pub fn deposit_event() = default;281282 fn on_initialize(_now: T::BlockNumber) -> Weight {283 Weight::zero()284 }285286 fn on_runtime_upgrade() -> Weight {287 Weight::zero()288 }289290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 #[weight = <SelfWeightOf<T>>::create_collection()]313 #[deprecated(note = "`create_collection_ex` is more up-to-date and advanced, prefer it instead")]314 pub fn create_collection(315 origin,316 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,317 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,318 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,319 mode: CollectionMode320 ) -> DispatchResult {321 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {322 name: collection_name,323 description: collection_description,324 token_prefix,325 mode,326 ..Default::default()327 };328 Self::create_collection_ex(origin, data)329 }330331 332 333 334 335 336 337 338 339 340 341 342 #[weight = <SelfWeightOf<T>>::create_collection()]343 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {344 let sender = ensure_signed(origin)?;345346 347 let sender = T::CrossAccountId::from_sub(sender);348 let _id = T::CollectionDispatch::create(sender.clone(), sender, data, Default::default())?;349350 Ok(())351 }352353 354 355 356 357 358 359 360 361 362 #[weight = <SelfWeightOf<T>>::destroy_collection()]363 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {364 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);365366 Self::destroy_collection_internal(sender, collection_id)367 }368369 370 371 372 373 374 375 376 377 378 379 380 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]381 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{382383 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);384 let collection = <CollectionHandle<T>>::try_get(collection_id)?;385 collection.check_is_internal()?;386387 <PalletCommon<T>>::toggle_allowlist(388 &collection,389 &sender,390 &address,391 true,392 )?;393394 Self::deposit_event(Event::<T>::AllowListAddressAdded(395 collection_id,396 address397 ));398399 Ok(())400 }401402 403 404 405 406 407 408 409 410 411 412 413 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]414 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{415416 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);417 let collection = <CollectionHandle<T>>::try_get(collection_id)?;418 collection.check_is_internal()?;419420 <PalletCommon<T>>::toggle_allowlist(421 &collection,422 &sender,423 &address,424 false,425 )?;426427 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(428 collection_id,429 address430 ));431432 Ok(())433 }434435 436 437 438 439 440 441 442 443 444 445 #[weight = <SelfWeightOf<T>>::change_collection_owner()]446 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {447448 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);449450 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;451 target_collection.check_is_internal()?;452 target_collection.check_is_owner(&sender)?;453454 target_collection.owner = new_owner.clone();455 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(456 collection_id,457 new_owner458 ));459460 target_collection.save()461 }462463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 #[weight = <SelfWeightOf<T>>::add_collection_admin()]480 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {481 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);482 let collection = <CollectionHandle<T>>::try_get(collection_id)?;483 collection.check_is_internal()?;484485 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(486 collection_id,487 new_admin_id.clone()488 ));489490 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)491 }492493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]508 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {509 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);510 let collection = <CollectionHandle<T>>::try_get(collection_id)?;511 collection.check_is_internal()?;512513 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(514 collection_id,515 account_id.clone()516 ));517518 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)519 }520521 522 523 524 525 526 527 528 529 530 531 532 533 534 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]535 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {536 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);537538 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;539 target_collection.check_is_owner_or_admin(&sender)?;540 target_collection.check_is_internal()?;541542 target_collection.set_sponsor(new_sponsor.clone())?;543544 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(545 collection_id,546 new_sponsor547 ));548549 target_collection.save()550 }551552 553 554 555 556 557 558 559 560 561 562 563 564 565 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]566 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {567 let sender = ensure_signed(origin)?;568569 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;570 target_collection.check_is_internal()?;571 ensure!(572 target_collection.confirm_sponsorship(&sender)?,573 Error::<T>::ConfirmUnsetSponsorFail574 );575576 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(577 collection_id,578 sender579 ));580581 target_collection.save()582 }583584 585 586 587 588 589 590 591 592 593 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]594 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {595 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);596597 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;598 target_collection.check_is_internal()?;599 target_collection.check_is_owner(&sender)?;600601 target_collection.sponsorship = SponsorshipState::Disabled;602603 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(604 collection_id605 ));606 target_collection.save()607 }608609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 #[weight = T::CommonWeightInfo::create_item()]628 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {629 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);630 let budget = budget::Value::new(NESTING_BUDGET);631632 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))633 }634635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]654 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {655 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);656 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);657 let budget = budget::Value::new(NESTING_BUDGET);658659 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))660 }661662 663 664 665 666 667 668 669 670 671 672 673 674 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]675 pub fn set_collection_properties(676 origin,677 collection_id: CollectionId,678 properties: Vec<Property>679 ) -> DispatchResultWithPostInfo {680 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);681682 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);683684 dispatch_tx::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))685 }686687 688 689 690 691 692 693 694 695 696 697 698 699 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]700 pub fn delete_collection_properties(701 origin,702 collection_id: CollectionId,703 property_keys: Vec<PropertyKey>,704 ) -> DispatchResultWithPostInfo {705 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);706707 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);708709 dispatch_tx::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))710 }711712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]731 pub fn set_token_properties(732 origin,733 collection_id: CollectionId,734 token_id: TokenId,735 properties: Vec<Property>736 ) -> DispatchResultWithPostInfo {737 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);738739 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);740 let budget = budget::Value::new(NESTING_BUDGET);741742 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties, &budget))743 }744745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]761 pub fn delete_token_properties(762 origin,763 collection_id: CollectionId,764 token_id: TokenId,765 property_keys: Vec<PropertyKey>766 ) -> DispatchResultWithPostInfo {767 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);768769 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);770 let budget = budget::Value::new(NESTING_BUDGET);771772 dispatch_tx::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys, &budget))773 }774775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 #[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)]791 pub fn set_token_property_permissions(792 origin,793 collection_id: CollectionId,794 property_permissions: Vec<PropertyKeyPermission>,795 ) -> DispatchResultWithPostInfo {796 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);797798 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);799800 dispatch_tx::<T, _>(collection_id, |d| d.set_token_property_permissions(&sender, property_permissions))801 }802803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]819 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {820 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);821 let budget = budget::Value::new(NESTING_BUDGET);822823 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))824 }825826 827 828 829 830 831 832 833 834 835 836 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]837 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {838 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);839 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;840 target_collection.check_is_internal()?;841 target_collection.check_is_owner(&sender)?;842843 844845 target_collection.limits.transfers_enabled = Some(value);846 target_collection.save()847 }848849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 #[weight = T::CommonWeightInfo::burn_item()]866 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {867 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);868869 let post_info = dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;870 if value == 1 {871 <NftTransferBasket<T>>::remove(collection_id, item_id);872 <NftApproveBasket<T>>::remove(collection_id, item_id);873 }874 875 876 877 Ok(post_info)878 }879880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 #[weight = T::CommonWeightInfo::burn_from()]904 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {905 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);906 let budget = budget::Value::new(NESTING_BUDGET);907908 dispatch_tx::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))909 }910911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 #[weight = T::CommonWeightInfo::transfer()]933 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {934 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);935 let budget = budget::Value::new(NESTING_BUDGET);936937 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))938 }939940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 #[weight = T::CommonWeightInfo::approve()]956 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {957 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);958959 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))960 }961962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 #[weight = T::CommonWeightInfo::transfer_from()]987 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {988 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);989 let budget = budget::Value::new(NESTING_BUDGET);990991 dispatch_tx::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))992 }993994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1007 pub fn set_collection_limits(1008 origin,1009 collection_id: CollectionId,1010 new_limit: CollectionLimits,1011 ) -> DispatchResult {1012 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1013 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1014 target_collection.check_is_internal()?;1015 target_collection.check_is_owner_or_admin(&sender)?;1016 let old_limit = &target_collection.limits;10171018 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10191020 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1021 collection_id1022 ));10231024 target_collection.save()1025 }10261027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1040 pub fn set_collection_permissions(1041 origin,1042 collection_id: CollectionId,1043 new_permission: CollectionPermissions,1044 ) -> DispatchResult {1045 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1046 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1047 target_collection.check_is_internal()?;1048 target_collection.check_is_owner_or_admin(&sender)?;1049 let old_limit = &target_collection.permissions;10501051 target_collection.permissions = <PalletCommon<T>>::clamp_permissions(target_collection.mode.clone(), &old_limit, new_permission)?;10521053 <Pallet<T>>::deposit_event(Event::<T>::CollectionPermissionSet(1054 collection_id1055 ));10561057 target_collection.save()1058 }10591060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 #[weight = T::RefungibleExtensionsWeightInfo::repartition()]1072 pub fn repartition(1073 origin,1074 collection_id: CollectionId,1075 token_id: TokenId,1076 amount: u128,1077 ) -> DispatchResultWithPostInfo {1078 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1079 dispatch_tx::<T, _>(collection_id, |d| {1080 if let Some(refungible_extensions) = d.refungible_extensions() {1081 refungible_extensions.repartition(&sender, token_id, amount)1082 } else {1083 fail!(<Error<T>>::RepartitionCalledOnNonRefungibleCollection)1084 }1085 })1086 }1087 }1088}10891090impl<T: Config> Pallet<T> {1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 pub fn force_set_sponsor(sponsor: T::AccountId, collection_id: CollectionId) -> DispatchResult {1101 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1102 target_collection.check_is_internal()?;1103 target_collection.set_sponsor(sponsor.clone())?;11041105 Self::deposit_event(Event::<T>::CollectionSponsorSet(1106 collection_id,1107 sponsor.clone(),1108 ));11091110 ensure!(1111 target_collection.confirm_sponsorship(&sponsor)?,1112 Error::<T>::ConfirmUnsetSponsorFail1113 );11141115 Self::deposit_event(Event::<T>::SponsorshipConfirmed(collection_id, sponsor));11161117 target_collection.save()1118 }11191120 1121 1122 1123 1124 1125 1126 1127 1128 pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {1129 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1130 target_collection.check_is_internal()?;1131 target_collection.sponsorship = SponsorshipState::Disabled;11321133 Self::deposit_event(Event::<T>::CollectionSponsorRemoved(collection_id));11341135 target_collection.save()1136 }11371138 #[inline(always)]1139 pub(crate) fn destroy_collection_internal(1140 sender: T::CrossAccountId,1141 collection_id: CollectionId,1142 ) -> DispatchResult {1143 let collection = <CollectionHandle<T>>::try_get(collection_id)?;1144 collection.check_is_internal()?;11451146 T::CollectionDispatch::destroy(sender, collection)?;11471148 1149 11501151 let _ = <NftTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1152 let _ = <FungibleTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1153 let _ = <ReFungibleTransferBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);11541155 let _ = <NftApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1156 let _ = <FungibleApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1157 let _ = <RefungibleApproveBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);11581159 Ok(())1160 }1161}