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};2829pub use frame_support::{30 construct_runtime, decl_module, decl_storage, decl_error, decl_event,31 dispatch::DispatchResult,32 ensure, fail, parameter_types,33 traits::{34 ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness,35 IsSubType, WithdrawReasons,36 },37 weights::{38 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},39 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,40 WeightToFeePolynomial, DispatchClass,41 },42 StorageValue, transactional,43 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},44 BoundedVec,45};46use scale_info::TypeInfo;47use frame_system::{self as system, ensure_signed};48use sp_runtime::{sp_std::prelude::Vec};49use up_data_structs::{50 MAX_DECIMAL_POINTS, VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,51 OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,52 MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,53 CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,54 CreateCollectionData, CustomDataLimit, CreateItemExData,55};56use pallet_common::{57 CollectionHandle, Pallet as PalletCommon, Error as CommonError,58 CommonWeightInfo,59};60use pallet_evm::account::CrossAccountId;61use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};62use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};63use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};6465#[cfg(test)]66mod mock;6768#[cfg(test)]69mod tests;7071mod eth;72mod sponsorship;73pub use sponsorship::UniqueSponsorshipHandler;74pub use eth::sponsoring::UniqueEthSponsorshipHandler;7576pub use eth::UniqueErcSupport;7778pub mod common;79use common::CommonWeights;80pub mod dispatch;81use dispatch::dispatch_call;8283#[cfg(feature = "runtime-benchmarks")]84mod benchmarking;85pub mod weights;86use weights::WeightInfo;8788decl_error! {89 90 pub enum Error for Module<T: Config> {91 92 CollectionDecimalPointLimitExceeded,93 94 ConfirmUnsetSponsorFail,95 96 EmptyArgument,97 }98}99100pub trait Config:101 system::Config102 + pallet_evm_coder_substrate::Config103 + pallet_common::Config104 + pallet_nonfungible::Config105 + pallet_refungible::Config106 + pallet_fungible::Config107 + Sized108 + TypeInfo109{110 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;111112 113 type WeightInfo: WeightInfo;114}115116decl_event! {117 pub enum Event<T>118 where119 <T as frame_system::Config>::AccountId,120 <T as pallet_evm::account::Config>::CrossAccountId,121 {122 123 124 125 126 127 CollectionSponsorRemoved(CollectionId),128129 130 131 132 133 134 135 136 CollectionAdminAdded(CollectionId, CrossAccountId),137138 139 140 141 142 143 144 145 CollectionOwnedChanged(CollectionId, AccountId),146147 148 149 150 151 152 153 154 CollectionSponsorSet(CollectionId, AccountId),155156 157 158 159 160 161 ConstOnChainSchemaSet(CollectionId),162163 164 165 166 167 168 169 170 SponsorshipConfirmed(CollectionId, AccountId),171172 173 174 175 176 177 178 179 CollectionAdminRemoved(CollectionId, CrossAccountId),180181 182 183 184 185 186 187 188 AllowListAddressRemoved(CollectionId, CrossAccountId),189190 191 192 193 194 195 196 197 AllowListAddressAdded(CollectionId, CrossAccountId),198199 200 201 202 203 204 CollectionLimitSet(CollectionId),205206 207 208 209 210 211 MintPermissionSet(CollectionId),212213 214 215 216 217 218 OffchainSchemaSet(CollectionId),219220 221 222 223 224 225 226 227 PublicAccessModeSet(CollectionId, AccessMode),228229 230 231 232 233 234 SchemaVersionSet(CollectionId),235236 237 238 239 240 241 VariableOnChainSchemaSet(CollectionId),242 }243}244245type SelfWeightOf<T> = <T as Config>::WeightInfo;246247248249250251252253254255256257258259260261262263264265266267268269decl_storage! {270 trait Store for Module<T: Config> as Unique {271272 273 274 ChainVersion: u64;275 276277 278 279 280 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;281 282 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;283 284 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;285 286 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>;287 288289 290 291 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;292 293 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;294 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;295 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>;296 }297}298299decl_module! {300 pub struct Module<T: Config> for enum Call301 where302 origin: T::Origin303 {304 type Error = Error<T>;305306 fn deposit_event() = default;307308 fn on_initialize(_now: T::BlockNumber) -> Weight {309 0310 }311312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 #[weight = <SelfWeightOf<T>>::create_collection()]329 #[transactional]330 #[deprecated]331 pub fn create_collection(origin,332 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,333 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,334 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,335 mode: CollectionMode) -> DispatchResult {336 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {337 name: collection_name,338 description: collection_description,339 token_prefix,340 mode,341 ..Default::default()342 };343 Self::create_collection_ex(origin, data)344 }345346 347 348 349 #[weight = <SelfWeightOf<T>>::create_collection()]350 #[transactional]351 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {352 let owner = ensure_signed(origin)?;353354 let _id = match data.mode {355 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},356 CollectionMode::Fungible(decimal_points) => {357 358 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);359 <PalletFungible<T>>::init_collection(owner, data)?360 }361 CollectionMode::ReFungible => {362 <PalletRefungible<T>>::init_collection(owner, data)?363 }364 };365366 Ok(())367 }368369 370 371 372 373 374 375 376 377 378 #[weight = <SelfWeightOf<T>>::destroy_collection()]379 #[transactional]380 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {381 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);382383 let collection = <CollectionHandle<T>>::try_get(collection_id)?;384 collection.check_is_owner(&sender)?;385386 387388 match collection.mode {389 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,390 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,391 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,392 }393394 <NftTransferBasket<T>>::remove_prefix(collection_id, None);395 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);396 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);397398 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);399 <NftApproveBasket<T>>::remove_prefix(collection_id, None);400 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);401 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);402403 Ok(())404 }405406 407 408 409 410 411 412 413 414 415 416 417 418 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]419 #[transactional]420 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{421422 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);423 let collection = <CollectionHandle<T>>::try_get(collection_id)?;424425 <PalletCommon<T>>::toggle_allowlist(426 &collection,427 &sender,428 &address,429 true,430 )?;431432 Self::deposit_event(Event::<T>::AllowListAddressAdded(433 collection_id,434 address435 ));436437 Ok(())438 }439440 441 442 443 444 445 446 447 448 449 450 451 452 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]453 #[transactional]454 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{455456 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);457 let collection = <CollectionHandle<T>>::try_get(collection_id)?;458459 <PalletCommon<T>>::toggle_allowlist(460 &collection,461 &sender,462 &address,463 false,464 )?;465466 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(467 collection_id,468 address469 ));470471 Ok(())472 }473474 475 476 477 478 479 480 481 482 483 484 485 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]486 #[transactional]487 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult488 {489 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);490491 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;492 target_collection.check_is_owner(&sender)?;493494 target_collection.access = mode.clone();495496 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(497 collection_id,498 mode499 ));500501 target_collection.save()502 }503504 505 506 507 508 509 510 511 512 513 514 515 516 517 #[weight = <SelfWeightOf<T>>::set_mint_permission()]518 #[transactional]519 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult520 {521 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);522523 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;524 target_collection.check_is_owner(&sender)?;525526 target_collection.mint_mode = mint_permission;527528 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(529 collection_id530 ));531532 target_collection.save()533 }534535 536 537 538 539 540 541 542 543 544 545 546 #[weight = <SelfWeightOf<T>>::change_collection_owner()]547 #[transactional]548 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {549550 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);551552 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;553 target_collection.check_is_owner(&sender)?;554555 target_collection.owner = new_owner.clone();556 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(557 collection_id,558 new_owner559 ));560561 target_collection.save()562 }563564 565 566 567 568 569 570 571 572 573 574 575 576 577 #[weight = <SelfWeightOf<T>>::add_collection_admin()]578 #[transactional]579 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {580 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);581 let collection = <CollectionHandle<T>>::try_get(collection_id)?;582583 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(584 collection_id,585 new_admin_id.clone()586 ));587588 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)589 }590591 592 593 594 595 596 597 598 599 600 601 602 603 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]604 #[transactional]605 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {606 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);607 let collection = <CollectionHandle<T>>::try_get(collection_id)?;608609 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(610 collection_id,611 account_id.clone()612 ));613614 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)615 }616617 618 619 620 621 622 623 624 625 626 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]627 #[transactional]628 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> 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::Unconfirmed(new_sponsor.clone());635636 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(637 collection_id,638 new_sponsor639 ));640641 target_collection.save()642 }643644 645 646 647 648 649 650 651 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]652 #[transactional]653 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {654 let sender = ensure_signed(origin)?;655656 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;657 ensure!(658 target_collection.sponsorship.pending_sponsor() == Some(&sender),659 Error::<T>::ConfirmUnsetSponsorFail660 );661662 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());663664 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(665 collection_id,666 sender667 ));668669 target_collection.save()670 }671672 673 674 675 676 677 678 679 680 681 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]682 #[transactional]683 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {684 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);685686 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;687 target_collection.check_is_owner(&sender)?;688689 target_collection.sponsorship = SponsorshipState::Disabled;690691 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(692 collection_id693 ));694 target_collection.save()695 }696697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 #[weight = <CommonWeights<T>>::create_item()]716 #[transactional]717 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {718 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);719720 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))721 }722723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]742 #[transactional]743 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {744 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);745 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);746747 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))748 }749750 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]751 #[transactional]752 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {753 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);754755 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))756 }757758 759760 761 762 763 764 765 766 767 768 769 770 771 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]772 #[transactional]773 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {774 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);775 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;776 target_collection.check_is_owner(&sender)?;777778 779780 target_collection.limits.transfers_enabled = Some(value);781 target_collection.save()782 }783784 785 786 787 788 789 790 791 792 793 794 795 796 797 #[weight = <CommonWeights<T>>::burn_item()]798 #[transactional]799 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {800 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);801802 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;803 if value == 1 {804 <NftTransferBasket<T>>::remove(collection_id, item_id);805 <NftApproveBasket<T>>::remove(collection_id, item_id);806 }807 808 809 810 Ok(post_info)811 }812813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 #[weight = <CommonWeights<T>>::burn_from()]830 #[transactional]831 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {832 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);833834 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))835 }836837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 #[weight = <CommonWeights<T>>::transfer()]861 #[transactional]862 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {863 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);864865 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))866 }867868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 #[weight = <CommonWeights<T>>::approve()]884 #[transactional]885 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {886 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);887888 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))889 }890891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 #[weight = <CommonWeights<T>>::transfer_from()]911 #[transactional]912 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {913 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);914915 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))916 }917918 919 920 921 922 923 924 925 926 927 928 929 930 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]931 #[transactional]932 pub fn set_variable_meta_data (933 origin,934 collection_id: CollectionId,935 item_id: TokenId,936 data: BoundedVec<u8, CustomDataLimit>,937 ) -> DispatchResultWithPostInfo {938 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);939940 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))941 }942943 944 945 946 947 948 949 950 951 952 953 954 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]955 #[transactional]956 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {957 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);958 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;959960 ensure!(961 target_collection.meta_update_permission != MetaUpdatePermission::None,962 <CommonError<T>>::MetadataFlagFrozen,963 );964 target_collection.check_is_owner(&sender)?;965966 target_collection.meta_update_permission = value;967968 target_collection.save()969 }970971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 #[weight = <SelfWeightOf<T>>::set_schema_version()]986 #[transactional]987 pub fn set_schema_version(988 origin,989 collection_id: CollectionId,990 version: SchemaVersion991 ) -> DispatchResult {992 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);993 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;994 target_collection.check_is_owner_or_admin(&sender)?;995 target_collection.schema_version = version;996997 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(998 collection_id999 ));10001001 target_collection.save()1002 }10031004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1017 #[transactional]1018 pub fn set_offchain_schema(1019 origin,1020 collection_id: CollectionId,1021 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1022 ) -> DispatchResult {1023 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1024 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1025 target_collection.check_is_owner_or_admin(&sender)?;10261027 target_collection.offchain_schema = schema;10281029 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1030 collection_id1031 ));10321033 target_collection.save()1034 }10351036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1049 #[transactional]1050 pub fn set_const_on_chain_schema (1051 origin,1052 collection_id: CollectionId,1053 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1054 ) -> DispatchResult {1055 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1056 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1057 target_collection.check_is_owner_or_admin(&sender)?;10581059 target_collection.const_on_chain_schema = schema;10601061 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1062 collection_id1063 ));10641065 target_collection.save()1066 }10671068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1081 #[transactional]1082 pub fn set_variable_on_chain_schema (1083 origin,1084 collection_id: CollectionId,1085 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1086 ) -> DispatchResult {1087 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1088 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1089 target_collection.check_is_owner_or_admin(&sender)?;10901091 target_collection.variable_on_chain_schema = schema;10921093 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1094 collection_id1095 ));10961097 target_collection.save()1098 }10991100 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1101 #[transactional]1102 pub fn set_collection_limits(1103 origin,1104 collection_id: CollectionId,1105 new_limit: CollectionLimits,1106 ) -> DispatchResult {1107 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1108 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1109 target_collection.check_is_owner(&sender)?;1110 let old_limit = &target_collection.limits;11111112 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11131114 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1115 collection_id1116 ));11171118 target_collection.save()1119 }1120 }1121}