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;7576pub use pallet::*;77use frame_support::pallet_prelude::*;78use frame_system::pallet_prelude::*;79pub mod eth;8081#[cfg(feature = "runtime-benchmarks")]82pub mod benchmarking;83pub mod weights;8485#[frame_support::pallet]86pub mod pallet {87 use super::*;8889 use frame_support::{90 dispatch::DispatchResult,91 ensure, fail,92 weights::{Weight},93 pallet_prelude::{*},94 BoundedVec,95 storage::Key,96 };97 use frame_system::pallet_prelude::*;98 use scale_info::TypeInfo;99 use frame_system::{self as system, ensure_signed, ensure_root};100 use sp_std::{vec, vec::Vec};101 use up_data_structs::{102 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,103 MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,104 MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,105 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode,106 TokenId, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,107 PropertyKeyPermission,108 };109 use pallet_evm::account::CrossAccountId;110 use pallet_common::{111 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,112 dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,113 };114 use weights::WeightInfo;115116 117 pub const NESTING_BUDGET: u32 = 5;118119 120 #[pallet::error]121 pub enum Error<T> {122 123 CollectionDecimalPointLimitExceeded,124 125 EmptyArgument,126 127 RepartitionCalledOnNonRefungibleCollection,128 }129130 131 #[pallet::config]132 pub trait Config: frame_system::Config + pallet_common::Config + Sized + TypeInfo {133 134 type WeightInfo: WeightInfo;135136 137 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;138139 140 type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;141 }142143 #[pallet::pallet]144 pub struct Pallet<T>(_);145146 pub type SelfWeightOf<T> = <T as Config>::WeightInfo;147148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170171 172 173 #[pallet::storage]174 pub type ChainVersion<T> = StorageValue<_, u64, ValueQuery>;175 176177 178 179 180 #[pallet::storage]181 #[pallet::getter(fn create_item_busket)]182 pub type CreateItemBasket<T: Config> = StorageMap<183 Hasher = Blake2_128Concat,184 Key = (CollectionId, T::AccountId),185 Value = T::BlockNumber,186 QueryKind = OptionQuery,187 >;188 189 #[pallet::storage]190 #[pallet::getter(fn nft_transfer_basket)]191 pub type NftTransferBasket<T: Config> = StorageDoubleMap<192 Hasher1 = Blake2_128Concat,193 Key1 = CollectionId,194 Hasher2 = Blake2_128Concat,195 Key2 = TokenId,196 Value = T::BlockNumber,197 QueryKind = OptionQuery,198 >;199 200 #[pallet::storage]201 #[pallet::getter(fn fungible_transfer_basket)]202 pub type FungibleTransferBasket<T: Config> = StorageDoubleMap<203 Hasher1 = Blake2_128Concat,204 Key1 = CollectionId,205 Hasher2 = Twox64Concat,206 Key2 = T::AccountId,207 Value = T::BlockNumber,208 QueryKind = OptionQuery,209 >;210 211 #[pallet::storage]212 #[pallet::getter(fn refungible_transfer_basket)]213 pub type ReFungibleTransferBasket<T: Config> = StorageNMap<214 Key = (215 Key<Blake2_128Concat, CollectionId>,216 Key<Blake2_128Concat, TokenId>,217 Key<Twox64Concat, T::AccountId>,218 ),219 Value = T::BlockNumber,220 QueryKind = OptionQuery,221 >;222 223224 225 #[pallet::storage]226 #[pallet::getter(fn token_property_basket)]227 pub type TokenPropertyBasket<T: Config> = StorageDoubleMap<228 Hasher1 = Blake2_128Concat,229 Key1 = CollectionId,230 Hasher2 = Blake2_128Concat,231 Key2 = TokenId,232 Value = T::BlockNumber,233 QueryKind = OptionQuery,234 >;235236 237 #[pallet::storage]238 #[pallet::getter(fn nft_approve_basket)]239 pub type NftApproveBasket<T: Config> = StorageDoubleMap<240 Hasher1 = Blake2_128Concat,241 Key1 = CollectionId,242 Hasher2 = Blake2_128Concat,243 Key2 = TokenId,244 Value = T::BlockNumber,245 QueryKind = OptionQuery,246 >;247 248 #[pallet::storage]249 #[pallet::getter(fn fungible_approve_basket)]250 pub type FungibleApproveBasket<T: Config> = StorageDoubleMap<251 Hasher1 = Blake2_128Concat,252 Key1 = CollectionId,253 Hasher2 = Twox64Concat,254 Key2 = T::AccountId,255 Value = T::BlockNumber,256 QueryKind = OptionQuery,257 >;258 259 #[pallet::storage]260 #[pallet::getter(fn refungible_approve_basket)]261 pub type RefungibleApproveBasket<T: Config> = StorageNMap<262 Key = (263 Key<Blake2_128Concat, CollectionId>,264 Key<Blake2_128Concat, TokenId>,265 Key<Twox64Concat, T::AccountId>,266 ),267 Value = T::BlockNumber,268 QueryKind = OptionQuery,269 >;270271 #[pallet::extra_constants]272 impl<T: Config> Pallet<T> {273 274 fn nesting_budget() -> u32 {275 NESTING_BUDGET276 }277278 279 fn max_collection_name_length() -> u32 {280 MAX_COLLECTION_NAME_LENGTH281 }282283 284 fn max_collection_description_length() -> u32 {285 MAX_COLLECTION_DESCRIPTION_LENGTH286 }287288 289 fn max_token_prefix_length() -> u32 {290 MAX_TOKEN_PREFIX_LENGTH291 }292293 294 fn collection_admins_limit() -> u32 {295 COLLECTION_ADMINS_LIMIT296 }297298 299 fn max_property_key_length() -> u32 {300 MAX_PROPERTY_KEY_LENGTH301 }302303 304 fn max_property_value_length() -> u32 {305 MAX_PROPERTY_VALUE_LENGTH306 }307308 309 fn max_properties_per_item() -> u32 {310 MAX_PROPERTIES_PER_ITEM311 }312313 314 fn max_collection_properties_size() -> u32 {315 MAX_COLLECTION_PROPERTIES_SIZE316 }317318 319 fn max_token_properties_size() -> u32 {320 MAX_TOKEN_PROPERTIES_SIZE321 }322323 324 fn nft_default_collection_limits() -> CollectionLimits {325 CollectionLimits::with_default_limits(CollectionMode::NFT)326 }327328 329 fn rft_default_collection_limits() -> CollectionLimits {330 CollectionLimits::with_default_limits(CollectionMode::ReFungible)331 }332333 334 fn ft_default_collection_limits() -> CollectionLimits {335 CollectionLimits::with_default_limits(CollectionMode::Fungible(0))336 }337 }338339 340 #[pallet::call]341 impl<T: Config> Pallet<T> {342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 #[pallet::call_index(0)]368 #[pallet::weight(<SelfWeightOf<T>>::create_collection())]369 pub fn create_collection(370 origin: OriginFor<T>,371 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,372 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,373 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,374 mode: CollectionMode,375 ) -> DispatchResult {376 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {377 name: collection_name,378 description: collection_description,379 token_prefix,380 mode,381 ..Default::default()382 };383 Self::create_collection_ex(origin, data)384 }385386 387 388 389 390 391 392 393 394 395 396 397 #[pallet::call_index(1)]398 #[pallet::weight(<SelfWeightOf<T>>::create_collection())]399 pub fn create_collection_ex(400 origin: OriginFor<T>,401 data: CreateCollectionData<T::AccountId>,402 ) -> DispatchResult {403 let sender = ensure_signed(origin)?;404405 406 let sender = T::CrossAccountId::from_sub(sender);407 let _id =408 T::CollectionDispatch::create(sender.clone(), sender, data, Default::default())?;409410 Ok(())411 }412413 414 415 416 417 418 419 420 421 422 #[pallet::call_index(2)]423 #[pallet::weight(<SelfWeightOf<T>>::destroy_collection())]424 pub fn destroy_collection(425 origin: OriginFor<T>,426 collection_id: CollectionId,427 ) -> DispatchResult {428 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);429430 Self::destroy_collection_internal(sender, collection_id)431 }432433 434 435 436 437 438 439 440 441 442 443 444 #[pallet::call_index(3)]445 #[pallet::weight(<SelfWeightOf<T>>::add_to_allow_list())]446 pub fn add_to_allow_list(447 origin: OriginFor<T>,448 collection_id: CollectionId,449 address: T::CrossAccountId,450 ) -> DispatchResult {451 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);452 let collection = <CollectionHandle<T>>::try_get(collection_id)?;453 collection.check_is_internal()?;454455 <PalletCommon<T>>::toggle_allowlist(&collection, &sender, &address, true)?;456457 Ok(())458 }459460 461 462 463 464 465 466 467 468 469 470 471 #[pallet::call_index(4)]472 #[pallet::weight(<SelfWeightOf<T>>::remove_from_allow_list())]473 pub fn remove_from_allow_list(474 origin: OriginFor<T>,475 collection_id: CollectionId,476 address: T::CrossAccountId,477 ) -> DispatchResult {478 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);479 let collection = <CollectionHandle<T>>::try_get(collection_id)?;480 collection.check_is_internal()?;481482 <PalletCommon<T>>::toggle_allowlist(&collection, &sender, &address, false)?;483484 Ok(())485 }486487 488 489 490 491 492 493 494 495 496 497 #[pallet::call_index(5)]498 #[pallet::weight(<SelfWeightOf<T>>::change_collection_owner())]499 pub fn change_collection_owner(500 origin: OriginFor<T>,501 collection_id: CollectionId,502 new_owner: T::AccountId,503 ) -> DispatchResult {504 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);505 let new_owner = T::CrossAccountId::from_sub(new_owner);506 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;507 target_collection.change_owner(sender, new_owner.clone())508 }509510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 #[pallet::call_index(6)]527 #[pallet::weight(<SelfWeightOf<T>>::add_collection_admin())]528 pub fn add_collection_admin(529 origin: OriginFor<T>,530 collection_id: CollectionId,531 new_admin_id: T::CrossAccountId,532 ) -> DispatchResult {533 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);534 let collection = <CollectionHandle<T>>::try_get(collection_id)?;535 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)536 }537538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 #[pallet::call_index(7)]553 #[pallet::weight(<SelfWeightOf<T>>::remove_collection_admin())]554 pub fn remove_collection_admin(555 origin: OriginFor<T>,556 collection_id: CollectionId,557 account_id: T::CrossAccountId,558 ) -> DispatchResult {559 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);560 let collection = <CollectionHandle<T>>::try_get(collection_id)?;561 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)562 }563564 565 566 567 568 569 570 571 572 573 574 575 576 577 #[pallet::call_index(8)]578 #[pallet::weight(<SelfWeightOf<T>>::set_collection_sponsor())]579 pub fn set_collection_sponsor(580 origin: OriginFor<T>,581 collection_id: CollectionId,582 new_sponsor: T::AccountId,583 ) -> DispatchResult {584 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);585 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;586 target_collection.set_sponsor(&sender, new_sponsor.clone())587 }588589 590 591 592 593 594 595 596 597 598 599 600 601 602 #[pallet::call_index(9)]603 #[pallet::weight(<SelfWeightOf<T>>::confirm_sponsorship())]604 pub fn confirm_sponsorship(605 origin: OriginFor<T>,606 collection_id: CollectionId,607 ) -> DispatchResult {608 let sender = ensure_signed(origin)?;609 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;610 target_collection.confirm_sponsorship(&sender)611 }612613 614 615 616 617 618 619 620 621 622 #[pallet::call_index(10)]623 #[pallet::weight(<SelfWeightOf<T>>::remove_collection_sponsor())]624 pub fn remove_collection_sponsor(625 origin: OriginFor<T>,626 collection_id: CollectionId,627 ) -> DispatchResult {628 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);629 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;630 target_collection.remove_sponsor(&sender)631 }632633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 #[pallet::call_index(11)]652 #[pallet::weight(T::CommonWeightInfo::create_item(&data))]653 pub fn create_item(654 origin: OriginFor<T>,655 collection_id: CollectionId,656 owner: T::CrossAccountId,657 data: CreateItemData,658 ) -> DispatchResultWithPostInfo {659 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);660 let budget = budget::Value::new(NESTING_BUDGET);661662 dispatch_tx::<T, _>(collection_id, |d| {663 d.create_item(sender, owner, data, &budget)664 })665 }666667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 #[pallet::call_index(12)]686 #[pallet::weight(T::CommonWeightInfo::create_multiple_items(&items_data))]687 pub fn create_multiple_items(688 origin: OriginFor<T>,689 collection_id: CollectionId,690 owner: T::CrossAccountId,691 items_data: Vec<CreateItemData>,692 ) -> DispatchResultWithPostInfo {693 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);694 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);695 let budget = budget::Value::new(NESTING_BUDGET);696697 dispatch_tx::<T, _>(collection_id, |d| {698 d.create_multiple_items(sender, owner, items_data, &budget)699 })700 }701702 703 704 705 706 707 708 709 710 711 712 713 714 #[pallet::call_index(13)]715 #[pallet::weight(T::CommonWeightInfo::set_collection_properties(properties.len() as u32))]716 pub fn set_collection_properties(717 origin: OriginFor<T>,718 collection_id: CollectionId,719 properties: Vec<Property>,720 ) -> DispatchResultWithPostInfo {721 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);722723 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);724725 dispatch_tx::<T, _>(collection_id, |d| {726 d.set_collection_properties(sender, properties)727 })728 }729730 731 732 733 734 735 736 737 738 739 740 741 742 #[pallet::call_index(14)]743 #[pallet::weight(T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32))]744 pub fn delete_collection_properties(745 origin: OriginFor<T>,746 collection_id: CollectionId,747 property_keys: Vec<PropertyKey>,748 ) -> DispatchResultWithPostInfo {749 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);750751 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);752753 dispatch_tx::<T, _>(collection_id, |d| {754 d.delete_collection_properties(&sender, property_keys)755 })756 }757758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 #[pallet::call_index(15)]777 #[pallet::weight(T::CommonWeightInfo::set_token_properties(properties.len() as u32))]778 pub fn set_token_properties(779 origin: OriginFor<T>,780 collection_id: CollectionId,781 token_id: TokenId,782 properties: Vec<Property>,783 ) -> DispatchResultWithPostInfo {784 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);785786 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);787 let budget = budget::Value::new(NESTING_BUDGET);788789 dispatch_tx::<T, _>(collection_id, |d| {790 d.set_token_properties(sender, token_id, properties, &budget)791 })792 }793794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 #[pallet::call_index(16)]810 #[pallet::weight(T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32))]811 pub fn delete_token_properties(812 origin: OriginFor<T>,813 collection_id: CollectionId,814 token_id: TokenId,815 property_keys: Vec<PropertyKey>,816 ) -> DispatchResultWithPostInfo {817 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);818819 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);820 let budget = budget::Value::new(NESTING_BUDGET);821822 dispatch_tx::<T, _>(collection_id, |d| {823 d.delete_token_properties(sender, token_id, property_keys, &budget)824 })825 }826827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 #[pallet::call_index(17)]843 #[pallet::weight(T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32))]844 pub fn set_token_property_permissions(845 origin: OriginFor<T>,846 collection_id: CollectionId,847 property_permissions: Vec<PropertyKeyPermission>,848 ) -> DispatchResultWithPostInfo {849 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);850851 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);852853 dispatch_tx::<T, _>(collection_id, |d| {854 d.set_token_property_permissions(&sender, property_permissions)855 })856 }857858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 #[pallet::call_index(18)]874 #[pallet::weight(T::CommonWeightInfo::create_multiple_items_ex(&data))]875 pub fn create_multiple_items_ex(876 origin: OriginFor<T>,877 collection_id: CollectionId,878 data: CreateItemExData<T::CrossAccountId>,879 ) -> DispatchResultWithPostInfo {880 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);881 let budget = budget::Value::new(NESTING_BUDGET);882883 dispatch_tx::<T, _>(collection_id, |d| {884 d.create_multiple_items_ex(sender, data, &budget)885 })886 }887888 889 890 891 892 893 894 895 896 897 898 #[pallet::call_index(19)]899 #[pallet::weight(<SelfWeightOf<T>>::set_transfers_enabled_flag())]900 pub fn set_transfers_enabled_flag(901 origin: OriginFor<T>,902 collection_id: CollectionId,903 value: bool,904 ) -> DispatchResult {905 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);906 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;907 target_collection.check_is_internal()?;908 target_collection.check_is_owner(&sender)?;909910 911912 target_collection.limits.transfers_enabled = Some(value);913 target_collection.save()914 }915916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 #[pallet::call_index(20)]933 #[pallet::weight(T::CommonWeightInfo::burn_item())]934 pub fn burn_item(935 origin: OriginFor<T>,936 collection_id: CollectionId,937 item_id: TokenId,938 value: u128,939 ) -> DispatchResultWithPostInfo {940 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);941942 let post_info =943 dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;944 if value == 1 {945 <NftTransferBasket<T>>::remove(collection_id, item_id);946 <NftApproveBasket<T>>::remove(collection_id, item_id);947 }948 949 950 951 Ok(post_info)952 }953954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 #[pallet::call_index(21)]978 #[pallet::weight(T::CommonWeightInfo::burn_from())]979 pub fn burn_from(980 origin: OriginFor<T>,981 collection_id: CollectionId,982 from: T::CrossAccountId,983 item_id: TokenId,984 value: u128,985 ) -> DispatchResultWithPostInfo {986 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);987 let budget = budget::Value::new(NESTING_BUDGET);988989 dispatch_tx::<T, _>(collection_id, |d| {990 d.burn_from(sender, from, item_id, value, &budget)991 })992 }993994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 #[pallet::call_index(22)]1016 #[pallet::weight(T::CommonWeightInfo::transfer())]1017 pub fn transfer(1018 origin: OriginFor<T>,1019 recipient: T::CrossAccountId,1020 collection_id: CollectionId,1021 item_id: TokenId,1022 value: u128,1023 ) -> DispatchResultWithPostInfo {1024 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1025 let budget = budget::Value::new(NESTING_BUDGET);10261027 dispatch_tx::<T, _>(collection_id, |d| {1028 d.transfer(sender, recipient, item_id, value, &budget)1029 })1030 }10311032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 #[pallet::call_index(23)]1048 #[pallet::weight(T::CommonWeightInfo::approve())]1049 pub fn approve(1050 origin: OriginFor<T>,1051 spender: T::CrossAccountId,1052 collection_id: CollectionId,1053 item_id: TokenId,1054 amount: u128,1055 ) -> DispatchResultWithPostInfo {1056 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);10571058 dispatch_tx::<T, _>(collection_id, |d| {1059 d.approve(sender, spender, item_id, amount)1060 })1061 }10621063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 #[pallet::call_index(24)]1080 #[pallet::weight(T::CommonWeightInfo::approve_from())]1081 pub fn approve_from(1082 origin: OriginFor<T>,1083 from: T::CrossAccountId,1084 to: T::CrossAccountId,1085 collection_id: CollectionId,1086 item_id: TokenId,1087 amount: u128,1088 ) -> DispatchResultWithPostInfo {1089 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);10901091 dispatch_tx::<T, _>(collection_id, |d| {1092 d.approve_from(sender, from, to, item_id, amount)1093 })1094 }10951096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 #[pallet::call_index(25)]1121 #[pallet::weight(T::CommonWeightInfo::transfer_from())]1122 pub fn transfer_from(1123 origin: OriginFor<T>,1124 from: T::CrossAccountId,1125 recipient: T::CrossAccountId,1126 collection_id: CollectionId,1127 item_id: TokenId,1128 value: u128,1129 ) -> DispatchResultWithPostInfo {1130 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1131 let budget = budget::Value::new(NESTING_BUDGET);11321133 dispatch_tx::<T, _>(collection_id, |d| {1134 d.transfer_from(sender, from, recipient, item_id, value, &budget)1135 })1136 }11371138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 #[pallet::call_index(26)]1151 #[pallet::weight(<SelfWeightOf<T>>::set_collection_limits())]1152 pub fn set_collection_limits(1153 origin: OriginFor<T>,1154 collection_id: CollectionId,1155 new_limit: CollectionLimits,1156 ) -> DispatchResult {1157 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1158 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1159 <PalletCommon<T>>::update_limits(&sender, &mut target_collection, new_limit)1160 }11611162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 #[pallet::call_index(27)]1175 #[pallet::weight(<SelfWeightOf<T>>::set_collection_limits())]1176 pub fn set_collection_permissions(1177 origin: OriginFor<T>,1178 collection_id: CollectionId,1179 new_permission: CollectionPermissions,1180 ) -> DispatchResult {1181 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1182 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1183 <PalletCommon<T>>::update_permissions(&sender, &mut target_collection, new_permission)1184 }11851186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 #[pallet::call_index(28)]1198 #[pallet::weight(T::RefungibleExtensionsWeightInfo::repartition())]1199 pub fn repartition(1200 origin: OriginFor<T>,1201 collection_id: CollectionId,1202 token_id: TokenId,1203 amount: u128,1204 ) -> DispatchResultWithPostInfo {1205 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1206 dispatch_tx::<T, _>(collection_id, |d| {1207 if let Some(refungible_extensions) = d.refungible_extensions() {1208 refungible_extensions.repartition(&sender, token_id, amount)1209 } else {1210 fail!(<Error<T>>::RepartitionCalledOnNonRefungibleCollection)1211 }1212 })1213 }12141215 1216 1217 1218 1219 1220 1221 1222 1223 1224 #[pallet::call_index(29)]1225 #[pallet::weight(T::CommonWeightInfo::set_allowance_for_all())]1226 pub fn set_allowance_for_all(1227 origin: OriginFor<T>,1228 collection_id: CollectionId,1229 operator: T::CrossAccountId,1230 approve: bool,1231 ) -> DispatchResultWithPostInfo {1232 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1233 dispatch_tx::<T, _>(collection_id, |d| {1234 d.set_allowance_for_all(sender, operator, approve)1235 })1236 }12371238 1239 1240 1241 1242 1243 #[pallet::call_index(30)]1244 #[pallet::weight(<SelfWeightOf<T>>::force_repair_collection())]1245 pub fn force_repair_collection(1246 origin: OriginFor<T>,1247 collection_id: CollectionId,1248 ) -> DispatchResult {1249 ensure_root(origin)?;1250 <PalletCommon<T>>::repair_collection(collection_id)1251 }12521253 1254 1255 1256 1257 1258 1259 #[pallet::call_index(31)]1260 #[pallet::weight(T::CommonWeightInfo::force_repair_item())]1261 pub fn force_repair_item(1262 origin: OriginFor<T>,1263 collection_id: CollectionId,1264 item_id: TokenId,1265 ) -> DispatchResultWithPostInfo {1266 ensure_root(origin)?;1267 dispatch_tx::<T, _>(collection_id, |d| d.repair_item(item_id))1268 }1269 }12701271 impl<T: Config> Pallet<T> {1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 pub fn force_set_sponsor(1282 sponsor: T::AccountId,1283 collection_id: CollectionId,1284 ) -> DispatchResult {1285 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1286 target_collection.force_set_sponsor(sponsor.clone())1287 }12881289 1290 1291 1292 1293 1294 1295 1296 1297 pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {1298 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1299 target_collection.force_remove_sponsor()1300 }13011302 #[inline(always)]1303 pub(crate) fn destroy_collection_internal(1304 sender: T::CrossAccountId,1305 collection_id: CollectionId,1306 ) -> DispatchResult {1307 let collection = <CollectionHandle<T>>::try_get(collection_id)?;1308 collection.check_is_internal()?;13091310 T::CollectionDispatch::destroy(sender, collection)?;13111312 1313 13141315 let _ = <NftTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1316 let _ = <FungibleTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1317 let _ = <ReFungibleTransferBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);13181319 let _ = <NftApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1320 let _ = <FungibleApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1321 let _ = <RefungibleApproveBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);13221323 Ok(())1324 }1325 }1326}