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)]2425use frame_support::{26 decl_module, decl_storage, decl_error, decl_event,27 dispatch::DispatchResult,28 ensure,29 weights::{Weight},30 transactional,31 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},32 BoundedVec,33};34use scale_info::TypeInfo;35use frame_system::{self as system, ensure_signed};36use sp_runtime::{sp_std::prelude::Vec};37use up_data_structs::{38 CONST_ON_CHAIN_SCHEMA_LIMIT, OFFCHAIN_SCHEMA_LIMIT,39 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,40 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,41 SchemaVersion, SponsorshipState, CreateCollectionData,42 CreateItemExData, budget, CollectionField, Property, PropertyKey, PropertyKeyPermission,43};44use pallet_evm::account::CrossAccountId;45use pallet_common::{46 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo,47 dispatch::dispatch_call, dispatch::CollectionDispatch,48};4950#[cfg(feature = "runtime-benchmarks")]51mod benchmarking;52pub mod weights;53use weights::WeightInfo;5455decl_error! {56 57 pub enum Error for Module<T: Config> {58 59 CollectionDecimalPointLimitExceeded,60 61 ConfirmUnsetSponsorFail,62 63 EmptyArgument,64 }65}6667pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {68 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;6970 71 type WeightInfo: WeightInfo;72 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;73}7475decl_event! {76 pub enum Event<T>77 where78 <T as frame_system::Config>::AccountId,79 <T as pallet_evm::account::Config>::CrossAccountId,80 {81 82 83 84 85 86 CollectionSponsorRemoved(CollectionId),8788 89 90 91 92 93 94 95 CollectionAdminAdded(CollectionId, CrossAccountId),9697 98 99 100 101 102 103 104 CollectionOwnedChanged(CollectionId, AccountId),105106 107 108 109 110 111 112 113 CollectionSponsorSet(CollectionId, AccountId),114115 116 117 118 119 120 ConstOnChainSchemaSet(CollectionId),121122 123 124 125 126 127 128 129 SponsorshipConfirmed(CollectionId, AccountId),130131 132 133 134 135 136 137 138 CollectionAdminRemoved(CollectionId, CrossAccountId),139140 141 142 143 144 145 146 147 AllowListAddressRemoved(CollectionId, CrossAccountId),148149 150 151 152 153 154 155 156 AllowListAddressAdded(CollectionId, CrossAccountId),157158 159 160 161 162 163 CollectionLimitSet(CollectionId),164165 166 167 168 169 170 MintPermissionSet(CollectionId),171172 173 174 175 176 177 OffchainSchemaSet(CollectionId),178179 180 181 182 183 184 185 186 PublicAccessModeSet(CollectionId, AccessMode),187188 189 190 191 192 193 SchemaVersionSet(CollectionId),194 }195}196197type SelfWeightOf<T> = <T as Config>::WeightInfo;198199200201202203204205206207208209210211212213214215216217218219220221decl_storage! {222 trait Store for Module<T: Config> as Unique {223224 225 226 ChainVersion: u64;227 228229 230 231 232 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;233 234 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;235 236 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;237 238 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>;239 240241 242 243 #[deprecated]244 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;245246 247 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;248 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;249 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>;250 }251}252253decl_module! {254 pub struct Module<T: Config> for enum Call255 where256 origin: T::Origin257 {258 type Error = Error<T>;259260 fn deposit_event() = default;261262 fn on_initialize(_now: T::BlockNumber) -> Weight {263 0264 }265266 fn on_runtime_upgrade() -> Weight {267 let limit = None;268269 <VariableMetaDataBasket<T>>::remove_all(limit);270271 0272 }273274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 #[weight = <SelfWeightOf<T>>::create_collection()]291 #[transactional]292 #[deprecated]293 pub fn create_collection(origin,294 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,295 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,296 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,297 mode: CollectionMode) -> DispatchResult {298 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {299 name: collection_name,300 description: collection_description,301 token_prefix,302 mode,303 ..Default::default()304 };305 Self::create_collection_ex(origin, data)306 }307308 309 310 311 #[weight = <SelfWeightOf<T>>::create_collection()]312 #[transactional]313 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {314 let sender = ensure_signed(origin)?;315316 317318 T::CollectionDispatch::create(sender, data)?;319320 Ok(())321 }322323 324 325 326 327 328 329 330 331 332 #[weight = <SelfWeightOf<T>>::destroy_collection()]333 #[transactional]334 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {335 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);336 let collection = <CollectionHandle<T>>::try_get(collection_id)?;337338 339340 T::CollectionDispatch::destroy(sender, collection)?;341342 <NftTransferBasket<T>>::remove_prefix(collection_id, None);343 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);344 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);345346 <NftApproveBasket<T>>::remove_prefix(collection_id, None);347 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);348 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);349350 Ok(())351 }352353 354 355 356 357 358 359 360 361 362 363 364 365 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]366 #[transactional]367 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{368369 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);370 let collection = <CollectionHandle<T>>::try_get(collection_id)?;371372 <PalletCommon<T>>::toggle_allowlist(373 &collection,374 &sender,375 &address,376 true,377 )?;378379 Self::deposit_event(Event::<T>::AllowListAddressAdded(380 collection_id,381 address382 ));383384 Ok(())385 }386387 388 389 390 391 392 393 394 395 396 397 398 399 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]400 #[transactional]401 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{402403 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);404 let collection = <CollectionHandle<T>>::try_get(collection_id)?;405406 <PalletCommon<T>>::toggle_allowlist(407 &collection,408 &sender,409 &address,410 false,411 )?;412413 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(414 collection_id,415 address416 ));417418 Ok(())419 }420421 422 423 424 425 426 427 428 429 430 431 432 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]433 #[transactional]434 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult435 {436 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);437438 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;439 target_collection.check_is_owner(&sender)?;440441 target_collection.access = mode.clone();442443 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(444 collection_id,445 mode446 ));447448 target_collection.save()449 }450451 452 453 454 455 456 457 458 459 460 461 462 463 464 #[weight = <SelfWeightOf<T>>::set_mint_permission()]465 #[transactional]466 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult467 {468 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);469470 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;471 target_collection.check_is_owner(&sender)?;472473 target_collection.mint_mode = mint_permission;474475 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(476 collection_id477 ));478479 target_collection.save()480 }481482 483 484 485 486 487 488 489 490 491 492 493 #[weight = <SelfWeightOf<T>>::change_collection_owner()]494 #[transactional]495 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {496497 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);498499 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;500 target_collection.check_is_owner(&sender)?;501502 target_collection.owner = new_owner.clone();503 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(504 collection_id,505 new_owner506 ));507508 target_collection.save()509 }510511 512 513 514 515 516 517 518 519 520 521 522 523 524 #[weight = <SelfWeightOf<T>>::add_collection_admin()]525 #[transactional]526 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {527 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);528 let collection = <CollectionHandle<T>>::try_get(collection_id)?;529530 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(531 collection_id,532 new_admin_id.clone()533 ));534535 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)536 }537538 539 540 541 542 543 544 545 546 547 548 549 550 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]551 #[transactional]552 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {553 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);554 let collection = <CollectionHandle<T>>::try_get(collection_id)?;555556 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(557 collection_id,558 account_id.clone()559 ));560561 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)562 }563564 565 566 567 568 569 570 571 572 573 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]574 #[transactional]575 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {576 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);577578 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;579 target_collection.check_is_owner(&sender)?;580581 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());582583 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(584 collection_id,585 new_sponsor586 ));587588 target_collection.save()589 }590591 592 593 594 595 596 597 598 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]599 #[transactional]600 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {601 let sender = ensure_signed(origin)?;602603 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;604 ensure!(605 target_collection.sponsorship.pending_sponsor() == Some(&sender),606 Error::<T>::ConfirmUnsetSponsorFail607 );608609 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());610611 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(612 collection_id,613 sender614 ));615616 target_collection.save()617 }618619 620 621 622 623 624 625 626 627 628 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]629 #[transactional]630 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {631 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);632633 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;634 target_collection.check_is_owner(&sender)?;635636 target_collection.sponsorship = SponsorshipState::Disabled;637638 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(639 collection_id640 ));641 target_collection.save()642 }643644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 #[weight = T::CommonWeightInfo::create_item()]663 #[transactional]664 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {665 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);666 let budget = budget::Value::new(2);667668 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))669 }670671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 #[weight = T::CommonWeightInfo::create_multiple_items(items_data.len() as u32)]690 #[transactional]691 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {692 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);693 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);694 let budget = budget::Value::new(2);695696 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))697 }698699 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]700 #[transactional]701 pub fn set_collection_properties(702 origin,703 collection_id: CollectionId,704 properties: Vec<Property>705 ) -> DispatchResultWithPostInfo {706 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);707708 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);709710 dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))711 }712713 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]714 #[transactional]715 pub fn delete_collection_properties(716 origin,717 collection_id: CollectionId,718 property_keys: Vec<PropertyKey>,719 ) -> DispatchResultWithPostInfo {720 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);721722 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);723724 dispatch_call::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))725 }726727 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]728 #[transactional]729 pub fn set_token_properties(730 origin,731 collection_id: CollectionId,732 token_id: TokenId,733 properties: Vec<Property>734 ) -> DispatchResultWithPostInfo {735 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);736737 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);738739 dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))740 }741742 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]743 #[transactional]744 pub fn delete_token_properties(745 origin,746 collection_id: CollectionId,747 token_id: TokenId,748 property_keys: Vec<PropertyKey>749 ) -> DispatchResultWithPostInfo {750 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);751752 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);753754 dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))755 }756757 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]758 #[transactional]759 pub fn set_property_permissions(760 origin,761 collection_id: CollectionId,762 property_permissions: Vec<PropertyKeyPermission>,763 ) -> DispatchResultWithPostInfo {764 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);765766 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);767768 dispatch_call::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))769 }770771 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]772 #[transactional]773 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {774 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);775 let budget = budget::Value::new(2);776777 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))778 }779780 781782 783 784 785 786 787 788 789 790 791 792 793 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]794 #[transactional]795 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {796 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);797 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;798 target_collection.check_is_owner(&sender)?;799800 801802 target_collection.limits.transfers_enabled = Some(value);803 target_collection.save()804 }805806 807 808 809 810 811 812 813 814 815 816 817 818 819 #[weight = T::CommonWeightInfo::burn_item()]820 #[transactional]821 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {822 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);823824 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;825 if value == 1 {826 <NftTransferBasket<T>>::remove(collection_id, item_id);827 <NftApproveBasket<T>>::remove(collection_id, item_id);828 }829 830 831 832 Ok(post_info)833 }834835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 #[weight = T::CommonWeightInfo::burn_from()]852 #[transactional]853 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {854 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);855 let budget = budget::Value::new(2);856857 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))858 }859860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 #[weight = T::CommonWeightInfo::transfer()]884 #[transactional]885 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {886 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);887 let budget = budget::Value::new(2);888889 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))890 }891892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 #[weight = T::CommonWeightInfo::approve()]908 #[transactional]909 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {910 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);911912 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))913 }914915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 #[weight = T::CommonWeightInfo::transfer_from()]935 #[transactional]936 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {937 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);938 let budget = budget::Value::new(2);939940 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))941 }942943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 #[weight = <SelfWeightOf<T>>::set_schema_version()]958 #[transactional]959 pub fn set_schema_version(960 origin,961 collection_id: CollectionId,962 version: SchemaVersion963 ) -> DispatchResult {964 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);965 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;966 target_collection.check_is_owner_or_admin(&sender)?;967 target_collection.schema_version = version;968969 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(970 collection_id971 ));972973 target_collection.save()974 }975976 977 978 979 980 981 982 983 984 985 986 987 988 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]989 #[transactional]990 pub fn set_offchain_schema(991 origin,992 collection_id: CollectionId,993 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,994 ) -> DispatchResult {995 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);996 let collection = <CollectionHandle<T>>::try_get(collection_id)?;997998 9991000 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;10011002 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1003 collection_id1004 ));1005 Ok(())1006 }10071008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1021 #[transactional]1022 pub fn set_const_on_chain_schema (1023 origin,1024 collection_id: CollectionId,1025 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1026 ) -> DispatchResult {1027 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1028 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10291030 10311032 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;10331034 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1035 collection_id1036 ));1037 Ok(())1038 }10391040 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1041 #[transactional]1042 pub fn set_collection_limits(1043 origin,1044 collection_id: CollectionId,1045 new_limit: CollectionLimits,1046 ) -> DispatchResult {1047 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1048 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1049 target_collection.check_is_owner(&sender)?;1050 let old_limit = &target_collection.limits;10511052 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10531054 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1055 collection_id1056 ));10571058 target_collection.save()1059 }1060 }1061}