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, MAX_COLLECTION_NAME_LENGTH,39 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData,40 CollectionLimits, CollectionId, CollectionMode, TokenId, SchemaVersion, SponsorshipState,41 CreateCollectionData, CreateItemExData, budget, CollectionField, Property, PropertyKey,42 PropertyKeyPermission,43};44use pallet_evm::account::CrossAccountId;45use pallet_common::{46 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_call,47 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>;245 pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;246247 248 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;249 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;250 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>;251 }252}253254decl_module! {255 pub struct Module<T: Config> for enum Call256 where257 origin: T::Origin258 {259 type Error = Error<T>;260261 fn deposit_event() = default;262263 fn on_initialize(_now: T::BlockNumber) -> Weight {264 0265 }266267 fn on_runtime_upgrade() -> Weight {268 let limit = None;269270 <VariableMetaDataBasket<T>>::remove_all(limit);271272 0273 }274275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 #[weight = <SelfWeightOf<T>>::create_collection()]292 #[transactional]293 #[deprecated]294 pub fn create_collection(origin,295 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,296 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,297 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,298 mode: CollectionMode) -> DispatchResult {299 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {300 name: collection_name,301 description: collection_description,302 token_prefix,303 mode,304 ..Default::default()305 };306 Self::create_collection_ex(origin, data)307 }308309 310 311 312 #[weight = <SelfWeightOf<T>>::create_collection()]313 #[transactional]314 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {315 let sender = ensure_signed(origin)?;316317 318319 T::CollectionDispatch::create(sender, data)?;320321 Ok(())322 }323324 325 326 327 328 329 330 331 332 333 #[weight = <SelfWeightOf<T>>::destroy_collection()]334 #[transactional]335 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {336 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);337 let collection = <CollectionHandle<T>>::try_get(collection_id)?;338339 340341 T::CollectionDispatch::destroy(sender, collection)?;342343 <NftTransferBasket<T>>::remove_prefix(collection_id, None);344 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);345 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);346347 <NftApproveBasket<T>>::remove_prefix(collection_id, None);348 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);349 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);350351 Ok(())352 }353354 355 356 357 358 359 360 361 362 363 364 365 366 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]367 #[transactional]368 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{369370 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);371 let collection = <CollectionHandle<T>>::try_get(collection_id)?;372373 <PalletCommon<T>>::toggle_allowlist(374 &collection,375 &sender,376 &address,377 true,378 )?;379380 Self::deposit_event(Event::<T>::AllowListAddressAdded(381 collection_id,382 address383 ));384385 Ok(())386 }387388 389 390 391 392 393 394 395 396 397 398 399 400 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]401 #[transactional]402 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{403404 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);405 let collection = <CollectionHandle<T>>::try_get(collection_id)?;406407 <PalletCommon<T>>::toggle_allowlist(408 &collection,409 &sender,410 &address,411 false,412 )?;413414 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(415 collection_id,416 address417 ));418419 Ok(())420 }421422 423 424 425 426 427 428 429 430 431 432 433 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]434 #[transactional]435 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult436 {437 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);438439 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;440 target_collection.check_is_owner(&sender)?;441442 target_collection.access = mode.clone();443444 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(445 collection_id,446 mode447 ));448449 target_collection.save()450 }451452 453 454 455 456 457 458 459 460 461 462 463 464 465 #[weight = <SelfWeightOf<T>>::set_mint_permission()]466 #[transactional]467 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult468 {469 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);470471 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;472 target_collection.check_is_owner(&sender)?;473474 target_collection.mint_mode = mint_permission;475476 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(477 collection_id478 ));479480 target_collection.save()481 }482483 484 485 486 487 488 489 490 491 492 493 494 #[weight = <SelfWeightOf<T>>::change_collection_owner()]495 #[transactional]496 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {497498 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.owner = new_owner.clone();504 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(505 collection_id,506 new_owner507 ));508509 target_collection.save()510 }511512 513 514 515 516 517 518 519 520 521 522 523 524 525 #[weight = <SelfWeightOf<T>>::add_collection_admin()]526 #[transactional]527 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {528 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);529 let collection = <CollectionHandle<T>>::try_get(collection_id)?;530531 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(532 collection_id,533 new_admin_id.clone()534 ));535536 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)537 }538539 540 541 542 543 544 545 546 547 548 549 550 551 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]552 #[transactional]553 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {554 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);555 let collection = <CollectionHandle<T>>::try_get(collection_id)?;556557 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(558 collection_id,559 account_id.clone()560 ));561562 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)563 }564565 566 567 568 569 570 571 572 573 574 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]575 #[transactional]576 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {577 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);578579 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;580 target_collection.check_is_owner(&sender)?;581582 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());583584 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(585 collection_id,586 new_sponsor587 ));588589 target_collection.save()590 }591592 593 594 595 596 597 598 599 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]600 #[transactional]601 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {602 let sender = ensure_signed(origin)?;603604 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;605 ensure!(606 target_collection.sponsorship.pending_sponsor() == Some(&sender),607 Error::<T>::ConfirmUnsetSponsorFail608 );609610 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());611612 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(613 collection_id,614 sender615 ));616617 target_collection.save()618 }619620 621 622 623 624 625 626 627 628 629 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]630 #[transactional]631 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {632 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);633634 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;635 target_collection.check_is_owner(&sender)?;636637 target_collection.sponsorship = SponsorshipState::Disabled;638639 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(640 collection_id641 ));642 target_collection.save()643 }644645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 #[weight = T::CommonWeightInfo::create_item()]664 #[transactional]665 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {666 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);667 let budget = budget::Value::new(2);668669 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))670 }671672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 #[weight = T::CommonWeightInfo::create_multiple_items(items_data.len() as u32)]691 #[transactional]692 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> 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(2);696697 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))698 }699700 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]701 #[transactional]702 pub fn set_collection_properties(703 origin,704 collection_id: CollectionId,705 properties: Vec<Property>706 ) -> DispatchResultWithPostInfo {707 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);708709 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);710711 dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))712 }713714 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]715 #[transactional]716 pub fn delete_collection_properties(717 origin,718 collection_id: CollectionId,719 property_keys: Vec<PropertyKey>,720 ) -> DispatchResultWithPostInfo {721 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);722723 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);724725 dispatch_call::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))726 }727728 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]729 #[transactional]730 pub fn set_token_properties(731 origin,732 collection_id: CollectionId,733 token_id: TokenId,734 properties: Vec<Property>735 ) -> DispatchResultWithPostInfo {736 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);737738 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);739740 dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))741 }742743 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]744 #[transactional]745 pub fn delete_token_properties(746 origin,747 collection_id: CollectionId,748 token_id: TokenId,749 property_keys: Vec<PropertyKey>750 ) -> DispatchResultWithPostInfo {751 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);752753 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);754755 dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))756 }757758 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]759 #[transactional]760 pub fn set_property_permissions(761 origin,762 collection_id: CollectionId,763 property_permissions: Vec<PropertyKeyPermission>,764 ) -> DispatchResultWithPostInfo {765 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);766767 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);768769 dispatch_call::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))770 }771772 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]773 #[transactional]774 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {775 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);776 let budget = budget::Value::new(2);777778 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))779 }780781 782783 784 785 786 787 788 789 790 791 792 793 794 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]795 #[transactional]796 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {797 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);798 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;799 target_collection.check_is_owner(&sender)?;800801 802803 target_collection.limits.transfers_enabled = Some(value);804 target_collection.save()805 }806807 808 809 810 811 812 813 814 815 816 817 818 819 820 #[weight = T::CommonWeightInfo::burn_item()]821 #[transactional]822 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {823 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);824825 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;826 if value == 1 {827 <NftTransferBasket<T>>::remove(collection_id, item_id);828 <NftApproveBasket<T>>::remove(collection_id, item_id);829 }830 831 832 833 Ok(post_info)834 }835836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 #[weight = T::CommonWeightInfo::burn_from()]853 #[transactional]854 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {855 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);856 let budget = budget::Value::new(2);857858 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))859 }860861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 #[weight = T::CommonWeightInfo::transfer()]885 #[transactional]886 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {887 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);888 let budget = budget::Value::new(2);889890 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))891 }892893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 #[weight = T::CommonWeightInfo::approve()]909 #[transactional]910 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {911 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);912913 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))914 }915916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 #[weight = T::CommonWeightInfo::transfer_from()]936 #[transactional]937 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {938 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);939 let budget = budget::Value::new(2);940941 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))942 }943944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 #[weight = <SelfWeightOf<T>>::set_schema_version()]959 #[transactional]960 pub fn set_schema_version(961 origin,962 collection_id: CollectionId,963 version: SchemaVersion964 ) -> DispatchResult {965 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);966 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;967 target_collection.check_is_owner_or_admin(&sender)?;968 target_collection.schema_version = version;969970 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(971 collection_id972 ));973974 target_collection.save()975 }976977 978 979 980 981 982 983 984 985 986 987 988 989 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]990 #[transactional]991 pub fn set_offchain_schema(992 origin,993 collection_id: CollectionId,994 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,995 ) -> DispatchResult {996 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);997 let collection = <CollectionHandle<T>>::try_get(collection_id)?;998999 10001001 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;10021003 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1004 collection_id1005 ));1006 Ok(())1007 }10081009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1022 #[transactional]1023 pub fn set_const_on_chain_schema (1024 origin,1025 collection_id: CollectionId,1026 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1027 ) -> DispatchResult {1028 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1029 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10301031 10321033 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;10341035 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1036 collection_id1037 ));1038 Ok(())1039 }10401041 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1042 #[transactional]1043 pub fn set_collection_limits(1044 origin,1045 collection_id: CollectionId,1046 new_limit: CollectionLimits,1047 ) -> DispatchResult {1048 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1049 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1050 target_collection.check_is_owner(&sender)?;1051 let old_limit = &target_collection.limits;10521053 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10541055 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1056 collection_id1057 ));10581059 target_collection.save()1060 }1061 }1062}