1234567891011121314151617#![recursion_limit = "1024"]18#![cfg_attr(not(feature = "std"), no_std)]19#![allow(20 clippy::too_many_arguments,21 clippy::unnecessary_mut_passed,22 clippy::unused_unit23)]2425extern crate alloc;2627pub use serde::{Serialize, Deserialize};2829use frame_support::{30 decl_module, decl_storage, decl_error, decl_event,31 dispatch::DispatchResult,32 ensure,33 weights::{Weight},34 transactional,35 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},36 BoundedVec,37};38use scale_info::TypeInfo;39use frame_system::{self as system, ensure_signed};40use sp_runtime::{sp_std::prelude::Vec};41use up_data_structs::{42 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, OFFCHAIN_SCHEMA_LIMIT,43 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,44 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,45 SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,46 CreateItemExData, budget, CollectionField,47};48use pallet_evm::account::CrossAccountId;49use pallet_common::{50 CollectionHandle, Pallet as PalletCommon, Error as CommonError, CommonWeightInfo,51 dispatch::dispatch_call, dispatch::CollectionDispatch,52};5354#[cfg(test)]55mod mock;5657#[cfg(test)]58mod tests;5960mod eth;61mod sponsorship;62pub use sponsorship::{UniqueSponsorshipHandler, UniqueSponsorshipPredict};63pub use eth::sponsoring::UniqueEthSponsorshipHandler;6465pub mod common;66use common::CommonWeights;6768#[cfg(feature = "runtime-benchmarks")]69mod benchmarking;70pub mod weights;71use weights::WeightInfo;7273pub trait SponsorshipPredict<T: Config> {74 fn predict(collection: CollectionId, account: T::CrossAccountId, token: TokenId) -> Option<u64>75 where76 u64: From<<T as frame_system::Config>::BlockNumber>;77}7879decl_error! {80 81 pub enum Error for Module<T: Config> {82 83 CollectionDecimalPointLimitExceeded,84 85 ConfirmUnsetSponsorFail,86 87 EmptyArgument,88 }89}9091pub trait Config:92 system::Config93 + pallet_evm_coder_substrate::Config94 + pallet_common::Config95 + pallet_nonfungible::Config96 + pallet_refungible::Config97 + pallet_fungible::Config98 + Sized99 + TypeInfo100{101 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;102103 104 type WeightInfo: WeightInfo;105}106107decl_event! {108 pub enum Event<T>109 where110 <T as frame_system::Config>::AccountId,111 <T as pallet_evm::account::Config>::CrossAccountId,112 {113 114 115 116 117 118 CollectionSponsorRemoved(CollectionId),119120 121 122 123 124 125 126 127 CollectionAdminAdded(CollectionId, CrossAccountId),128129 130 131 132 133 134 135 136 CollectionOwnedChanged(CollectionId, AccountId),137138 139 140 141 142 143 144 145 CollectionSponsorSet(CollectionId, AccountId),146147 148 149 150 151 152 ConstOnChainSchemaSet(CollectionId),153154 155 156 157 158 159 160 161 SponsorshipConfirmed(CollectionId, AccountId),162163 164 165 166 167 168 169 170 CollectionAdminRemoved(CollectionId, CrossAccountId),171172 173 174 175 176 177 178 179 AllowListAddressRemoved(CollectionId, CrossAccountId),180181 182 183 184 185 186 187 188 AllowListAddressAdded(CollectionId, CrossAccountId),189190 191 192 193 194 195 CollectionLimitSet(CollectionId),196197 198 199 200 201 202 MintPermissionSet(CollectionId),203204 205 206 207 208 209 OffchainSchemaSet(CollectionId),210211 212 213 214 215 216 217 218 PublicAccessModeSet(CollectionId, AccessMode),219220 221 222 223 224 225 SchemaVersionSet(CollectionId),226227 228 229 230 231 232 VariableOnChainSchemaSet(CollectionId),233 }234}235236type SelfWeightOf<T> = <T as Config>::WeightInfo;237238239240241242243244245246247248249250251252253254255256257258259260decl_storage! {261 trait Store for Module<T: Config> as Unique {262263 264 265 ChainVersion: u64;266 267268 269 270 271 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;272 273 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;274 275 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;276 277 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>;278 279280 281 282 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;283 284 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;285 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;286 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>;287 }288}289290decl_module! {291 pub struct Module<T: Config> for enum Call292 where293 origin: T::Origin294 {295 type Error = Error<T>;296297 fn deposit_event() = default;298299 fn on_initialize(_now: T::BlockNumber) -> Weight {300 0301 }302303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 #[weight = <SelfWeightOf<T>>::create_collection()]320 #[transactional]321 #[deprecated]322 pub fn create_collection(origin,323 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,324 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,325 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,326 mode: CollectionMode) -> DispatchResult {327 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {328 name: collection_name,329 description: collection_description,330 token_prefix,331 mode,332 ..Default::default()333 };334 Self::create_collection_ex(origin, data)335 }336337 338 339 340 #[weight = <SelfWeightOf<T>>::create_collection()]341 #[transactional]342 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {343 let sender = ensure_signed(origin)?;344345 346347 T::CollectionDispatch::create(sender, data)?;348349 Ok(())350 }351352 353 354 355 356 357 358 359 360 361 #[weight = <SelfWeightOf<T>>::destroy_collection()]362 #[transactional]363 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {364 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);365 let collection = <CollectionHandle<T>>::try_get(collection_id)?;366367 368369 T::CollectionDispatch::destroy(sender, collection)?;370371 <NftTransferBasket<T>>::remove_prefix(collection_id, None);372 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);373 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);374375 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);376 <NftApproveBasket<T>>::remove_prefix(collection_id, None);377 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);378 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);379380 Ok(())381 }382383 384 385 386 387 388 389 390 391 392 393 394 395 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]396 #[transactional]397 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{398399 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);400 let collection = <CollectionHandle<T>>::try_get(collection_id)?;401402 <PalletCommon<T>>::toggle_allowlist(403 &collection,404 &sender,405 &address,406 true,407 )?;408409 Self::deposit_event(Event::<T>::AllowListAddressAdded(410 collection_id,411 address412 ));413414 Ok(())415 }416417 418 419 420 421 422 423 424 425 426 427 428 429 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]430 #[transactional]431 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{432433 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);434 let collection = <CollectionHandle<T>>::try_get(collection_id)?;435436 <PalletCommon<T>>::toggle_allowlist(437 &collection,438 &sender,439 &address,440 false,441 )?;442443 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(444 collection_id,445 address446 ));447448 Ok(())449 }450451 452 453 454 455 456 457 458 459 460 461 462 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]463 #[transactional]464 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult465 {466 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);467468 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;469 target_collection.check_is_owner(&sender)?;470471 target_collection.access = mode.clone();472473 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(474 collection_id,475 mode476 ));477478 target_collection.save()479 }480481 482 483 484 485 486 487 488 489 490 491 492 493 494 #[weight = <SelfWeightOf<T>>::set_mint_permission()]495 #[transactional]496 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult497 {498 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);499500 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;501 target_collection.check_is_owner(&sender)?;502503 target_collection.mint_mode = mint_permission;504505 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(506 collection_id507 ));508509 target_collection.save()510 }511512 513 514 515 516 517 518 519 520 521 522 523 #[weight = <SelfWeightOf<T>>::change_collection_owner()]524 #[transactional]525 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {526527 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);528529 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;530 target_collection.check_is_owner(&sender)?;531532 target_collection.owner = new_owner.clone();533 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(534 collection_id,535 new_owner536 ));537538 target_collection.save()539 }540541 542 543 544 545 546 547 548 549 550 551 552 553 554 #[weight = <SelfWeightOf<T>>::add_collection_admin()]555 #[transactional]556 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {557 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);558 let collection = <CollectionHandle<T>>::try_get(collection_id)?;559560 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(561 collection_id,562 new_admin_id.clone()563 ));564565 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)566 }567568 569 570 571 572 573 574 575 576 577 578 579 580 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]581 #[transactional]582 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {583 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);584 let collection = <CollectionHandle<T>>::try_get(collection_id)?;585586 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(587 collection_id,588 account_id.clone()589 ));590591 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)592 }593594 595 596 597 598 599 600 601 602 603 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]604 #[transactional]605 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {606 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);607608 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;609 target_collection.check_is_owner(&sender)?;610611 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());612613 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(614 collection_id,615 new_sponsor616 ));617618 target_collection.save()619 }620621 622 623 624 625 626 627 628 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]629 #[transactional]630 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {631 let sender = ensure_signed(origin)?;632633 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;634 ensure!(635 target_collection.sponsorship.pending_sponsor() == Some(&sender),636 Error::<T>::ConfirmUnsetSponsorFail637 );638639 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());640641 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(642 collection_id,643 sender644 ));645646 target_collection.save()647 }648649 650 651 652 653 654 655 656 657 658 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]659 #[transactional]660 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {661 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);662663 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;664 target_collection.check_is_owner(&sender)?;665666 target_collection.sponsorship = SponsorshipState::Disabled;667668 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(669 collection_id670 ));671 target_collection.save()672 }673674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 #[weight = <CommonWeights<T>>::create_item()]693 #[transactional]694 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {695 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);696 let budget = budget::Value::new(2);697698 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))699 }700701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]720 #[transactional]721 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {722 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);723 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);724 let budget = budget::Value::new(2);725726 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))727 }728729 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]730 #[transactional]731 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {732 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);733 let budget = budget::Value::new(2);734735 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))736 }737738 739740 741 742 743 744 745 746 747 748 749 750 751 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]752 #[transactional]753 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {754 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);755 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;756 target_collection.check_is_owner(&sender)?;757758 759760 target_collection.limits.transfers_enabled = Some(value);761 target_collection.save()762 }763764 765 766 767 768 769 770 771 772 773 774 775 776 777 #[weight = <CommonWeights<T>>::burn_item()]778 #[transactional]779 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {780 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);781782 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;783 if value == 1 {784 <NftTransferBasket<T>>::remove(collection_id, item_id);785 <NftApproveBasket<T>>::remove(collection_id, item_id);786 }787 788 789 790 Ok(post_info)791 }792793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 #[weight = <CommonWeights<T>>::burn_from()]810 #[transactional]811 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {812 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);813 let budget = budget::Value::new(2);814815 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))816 }817818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 #[weight = <CommonWeights<T>>::transfer()]842 #[transactional]843 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {844 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);845 let budget = budget::Value::new(2);846847 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))848 }849850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 #[weight = <CommonWeights<T>>::approve()]866 #[transactional]867 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {868 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);869870 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))871 }872873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 #[weight = <CommonWeights<T>>::transfer_from()]893 #[transactional]894 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {895 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);896 let budget = budget::Value::new(2);897898 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))899 }900901 902 903 904 905 906 907 908 909 910 911 912 913 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]914 #[transactional]915 pub fn set_variable_meta_data (916 origin,917 collection_id: CollectionId,918 item_id: TokenId,919 data: BoundedVec<u8, CustomDataLimit>,920 ) -> DispatchResultWithPostInfo {921 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);922923 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))924 }925926 927 928 929 930 931 932 933 934 935 936 937 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]938 #[transactional]939 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {940 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);941 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;942943 ensure!(944 target_collection.meta_update_permission != MetaUpdatePermission::None,945 <CommonError<T>>::MetadataFlagFrozen,946 );947 target_collection.check_is_owner(&sender)?;948949 target_collection.meta_update_permission = value;950951 target_collection.save()952 }953954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 #[weight = <SelfWeightOf<T>>::set_schema_version()]969 #[transactional]970 pub fn set_schema_version(971 origin,972 collection_id: CollectionId,973 version: SchemaVersion974 ) -> DispatchResult {975 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);976 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;977 target_collection.check_is_owner_or_admin(&sender)?;978 target_collection.schema_version = version;979980 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(981 collection_id982 ));983984 target_collection.save()985 }986987 988 989 990 991 992 993 994 995 996 997 998 999 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1000 #[transactional]1001 pub fn set_offchain_schema(1002 origin,1003 collection_id: CollectionId,1004 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1005 ) -> DispatchResult {1006 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1007 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10081009 10101011 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;10121013 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1014 collection_id1015 ));1016 Ok(())1017 }10181019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1032 #[transactional]1033 pub fn set_const_on_chain_schema (1034 origin,1035 collection_id: CollectionId,1036 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1037 ) -> DispatchResult {1038 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1039 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10401041 10421043 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;10441045 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1046 collection_id1047 ));1048 Ok(())1049 }10501051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1064 #[transactional]1065 pub fn set_variable_on_chain_schema (1066 origin,1067 collection_id: CollectionId,1068 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1069 ) -> DispatchResult {1070 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1071 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10721073 10741075 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::VariableOnChainSchema, schema.into_inner())?;10761077 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1078 collection_id1079 ));1080 Ok(())1081 }10821083 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1084 #[transactional]1085 pub fn set_collection_limits(1086 origin,1087 collection_id: CollectionId,1088 new_limit: CollectionLimits,1089 ) -> DispatchResult {1090 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1091 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1092 target_collection.check_is_owner(&sender)?;1093 let old_limit = &target_collection.limits;10941095 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10961097 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1098 collection_id1099 ));11001101 target_collection.save()1102 }1103 }1104}