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 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, 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, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,42 CreateItemExData, budget, CollectionField, Property, PropertyKeyPermission,43};44use pallet_evm::account::CrossAccountId;45use pallet_common::{46 CollectionHandle, Pallet as PalletCommon, Error as CommonError, 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),194195 196 197 198 199 200 VariableOnChainSchemaSet(CollectionId),201 }202}203204type SelfWeightOf<T> = <T as Config>::WeightInfo;205206207208209210211212213214215216217218219220221222223224225226227228decl_storage! {229 trait Store for Module<T: Config> as Unique {230231 232 233 ChainVersion: u64;234 235236 237 238 239 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;240 241 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;242 243 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;244 245 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>;246 247248 249 250 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;251 252 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;253 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;254 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>;255 }256}257258decl_module! {259 pub struct Module<T: Config> for enum Call260 where261 origin: T::Origin262 {263 type Error = Error<T>;264265 fn deposit_event() = default;266267 fn on_initialize(_now: T::BlockNumber) -> Weight {268 0269 }270271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 #[weight = <SelfWeightOf<T>>::create_collection()]288 #[transactional]289 #[deprecated]290 pub fn create_collection(origin,291 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,292 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,293 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,294 mode: CollectionMode) -> DispatchResult {295 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {296 name: collection_name,297 description: collection_description,298 token_prefix,299 mode,300 ..Default::default()301 };302 Self::create_collection_ex(origin, data)303 }304305 306 307 308 #[weight = <SelfWeightOf<T>>::create_collection()]309 #[transactional]310 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {311 let sender = ensure_signed(origin)?;312313 314315 T::CollectionDispatch::create(sender, data)?;316317 Ok(())318 }319320 321 322 323 324 325 326 327 328 329 #[weight = <SelfWeightOf<T>>::destroy_collection()]330 #[transactional]331 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {332 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);333 let collection = <CollectionHandle<T>>::try_get(collection_id)?;334335 336337 T::CollectionDispatch::destroy(sender, collection)?;338339 <NftTransferBasket<T>>::remove_prefix(collection_id, None);340 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);341 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);342343 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);344 <NftApproveBasket<T>>::remove_prefix(collection_id, None);345 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);346 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);347348 Ok(())349 }350351 352 353 354 355 356 357 358 359 360 361 362 363 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]364 #[transactional]365 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{366367 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);368 let collection = <CollectionHandle<T>>::try_get(collection_id)?;369370 <PalletCommon<T>>::toggle_allowlist(371 &collection,372 &sender,373 &address,374 true,375 )?;376377 Self::deposit_event(Event::<T>::AllowListAddressAdded(378 collection_id,379 address380 ));381382 Ok(())383 }384385 386 387 388 389 390 391 392 393 394 395 396 397 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]398 #[transactional]399 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{400401 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);402 let collection = <CollectionHandle<T>>::try_get(collection_id)?;403404 <PalletCommon<T>>::toggle_allowlist(405 &collection,406 &sender,407 &address,408 false,409 )?;410411 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(412 collection_id,413 address414 ));415416 Ok(())417 }418419 420 421 422 423 424 425 426 427 428 429 430 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]431 #[transactional]432 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult433 {434 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);435436 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;437 target_collection.check_is_owner(&sender)?;438439 target_collection.access = mode.clone();440441 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(442 collection_id,443 mode444 ));445446 target_collection.save()447 }448449 450 451 452 453 454 455 456 457 458 459 460 461 462 #[weight = <SelfWeightOf<T>>::set_mint_permission()]463 #[transactional]464 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> 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.mint_mode = mint_permission;472473 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(474 collection_id475 ));476477 target_collection.save()478 }479480 481 482 483 484 485 486 487 488 489 490 491 #[weight = <SelfWeightOf<T>>::change_collection_owner()]492 #[transactional]493 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {494495 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);496497 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;498 target_collection.check_is_owner(&sender)?;499500 target_collection.owner = new_owner.clone();501 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(502 collection_id,503 new_owner504 ));505506 target_collection.save()507 }508509 510 511 512 513 514 515 516 517 518 519 520 521 522 #[weight = <SelfWeightOf<T>>::add_collection_admin()]523 #[transactional]524 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {525 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);526 let collection = <CollectionHandle<T>>::try_get(collection_id)?;527528 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(529 collection_id,530 new_admin_id.clone()531 ));532533 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)534 }535536 537 538 539 540 541 542 543 544 545 546 547 548 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]549 #[transactional]550 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {551 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);552 let collection = <CollectionHandle<T>>::try_get(collection_id)?;553554 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(555 collection_id,556 account_id.clone()557 ));558559 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)560 }561562 563 564 565 566 567 568 569 570 571 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]572 #[transactional]573 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {574 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);575576 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;577 target_collection.check_is_owner(&sender)?;578579 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());580581 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(582 collection_id,583 new_sponsor584 ));585586 target_collection.save()587 }588589 590 591 592 593 594 595 596 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]597 #[transactional]598 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {599 let sender = ensure_signed(origin)?;600601 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;602 ensure!(603 target_collection.sponsorship.pending_sponsor() == Some(&sender),604 Error::<T>::ConfirmUnsetSponsorFail605 );606607 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());608609 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(610 collection_id,611 sender612 ));613614 target_collection.save()615 }616617 618 619 620 621 622 623 624 625 626 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]627 #[transactional]628 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {629 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);630631 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;632 target_collection.check_is_owner(&sender)?;633634 target_collection.sponsorship = SponsorshipState::Disabled;635636 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(637 collection_id638 ));639 target_collection.save()640 }641642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 #[weight = T::CommonWeightInfo::create_item()]661 #[transactional]662 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {663 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);664 let budget = budget::Value::new(2);665666 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))667 }668669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 #[weight = T::CommonWeightInfo::create_multiple_items(items_data.len() as u32)]688 #[transactional]689 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {690 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);691 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);692 let budget = budget::Value::new(2);693694 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))695 }696697 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]698 #[transactional]699 pub fn set_collection_properties(700 origin,701 collection_id: CollectionId,702 properties: Vec<Property>703 ) -> DispatchResultWithPostInfo {704 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);705706 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);707708 dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))709 }710711 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]712 #[transactional]713 pub fn set_token_properties(714 origin,715 collection_id: CollectionId,716 token_id: TokenId,717 properties: Vec<Property>718 ) -> DispatchResultWithPostInfo {719 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);720721 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);722723 dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))724 }725726 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]727 #[transactional]728 pub fn set_property_permissions(729 origin,730 collection_id: CollectionId,731 property_permissions: Vec<PropertyKeyPermission>,732 ) -> DispatchResultWithPostInfo {733 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);734735 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);736737 dispatch_call::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))738 }739740 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]741 #[transactional]742 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {743 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);744 let budget = budget::Value::new(2);745746 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))747 }748749 750751 752 753 754 755 756 757 758 759 760 761 762 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]763 #[transactional]764 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {765 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);766 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;767 target_collection.check_is_owner(&sender)?;768769 770771 target_collection.limits.transfers_enabled = Some(value);772 target_collection.save()773 }774775 776 777 778 779 780 781 782 783 784 785 786 787 788 #[weight = T::CommonWeightInfo::burn_item()]789 #[transactional]790 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {791 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);792793 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;794 if value == 1 {795 <NftTransferBasket<T>>::remove(collection_id, item_id);796 <NftApproveBasket<T>>::remove(collection_id, item_id);797 }798 799 800 801 Ok(post_info)802 }803804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 #[weight = T::CommonWeightInfo::burn_from()]821 #[transactional]822 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {823 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);824 let budget = budget::Value::new(2);825826 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))827 }828829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 #[weight = T::CommonWeightInfo::transfer()]853 #[transactional]854 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, 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.transfer(sender, recipient, item_id, value, &budget))859 }860861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 #[weight = T::CommonWeightInfo::approve()]877 #[transactional]878 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {879 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);880881 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))882 }883884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 #[weight = T::CommonWeightInfo::transfer_from()]904 #[transactional]905 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {906 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);907 let budget = budget::Value::new(2);908909 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))910 }911912 913 914 915 916 917 918 919 920 921 922 923 924 #[weight = T::CommonWeightInfo::set_variable_metadata(data.len() as u32)]925 #[transactional]926 pub fn set_variable_meta_data (927 origin,928 collection_id: CollectionId,929 item_id: TokenId,930 data: BoundedVec<u8, CustomDataLimit>,931 ) -> DispatchResultWithPostInfo {932 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);933934 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))935 }936937 938 939 940 941 942 943 944 945 946 947 948 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]949 #[transactional]950 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {951 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);952 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;953954 ensure!(955 target_collection.meta_update_permission != MetaUpdatePermission::None,956 <CommonError<T>>::MetadataFlagFrozen,957 );958 target_collection.check_is_owner(&sender)?;959960 target_collection.meta_update_permission = value;961962 target_collection.save()963 }964965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 #[weight = <SelfWeightOf<T>>::set_schema_version()]980 #[transactional]981 pub fn set_schema_version(982 origin,983 collection_id: CollectionId,984 version: SchemaVersion985 ) -> DispatchResult {986 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);987 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;988 target_collection.check_is_owner_or_admin(&sender)?;989 target_collection.schema_version = version;990991 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(992 collection_id993 ));994995 target_collection.save()996 }997998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1011 #[transactional]1012 pub fn set_offchain_schema(1013 origin,1014 collection_id: CollectionId,1015 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1016 ) -> DispatchResult {1017 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1018 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10191020 10211022 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;10231024 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1025 collection_id1026 ));1027 Ok(())1028 }10291030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1043 #[transactional]1044 pub fn set_const_on_chain_schema (1045 origin,1046 collection_id: CollectionId,1047 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1048 ) -> DispatchResult {1049 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1050 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10511052 10531054 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;10551056 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1057 collection_id1058 ));1059 Ok(())1060 }10611062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1075 #[transactional]1076 pub fn set_variable_on_chain_schema (1077 origin,1078 collection_id: CollectionId,1079 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1080 ) -> DispatchResult {1081 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1082 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10831084 10851086 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::VariableOnChainSchema, schema.into_inner())?;10871088 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1089 collection_id1090 ));1091 Ok(())1092 }10931094 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1095 #[transactional]1096 pub fn set_collection_limits(1097 origin,1098 collection_id: CollectionId,1099 new_limit: CollectionLimits,1100 ) -> DispatchResult {1101 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1102 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1103 target_collection.check_is_owner(&sender)?;1104 let old_limit = &target_collection.limits;11051106 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11071108 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1109 collection_id1110 ));11111112 target_collection.save()1113 }1114 }1115}