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::{CollectionHandle, Pallet as PalletCommon, Error as CommonError, CommonWeightInfo};57use pallet_evm::account::CrossAccountId;58use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};59use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};60use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};6162#[cfg(test)]63mod mock;6465#[cfg(test)]66mod tests;6768mod eth;69mod sponsorship;70pub use sponsorship::UniqueSponsorshipHandler;71pub use eth::sponsoring::UniqueEthSponsorshipHandler;7273pub use eth::UniqueErcSupport;7475pub mod common;76use common::CommonWeights;77pub mod dispatch;78use dispatch::dispatch_call;7980#[cfg(feature = "runtime-benchmarks")]81mod benchmarking;82pub mod weights;83use weights::WeightInfo;8485decl_error! {86 87 pub enum Error for Module<T: Config> {88 89 CollectionDecimalPointLimitExceeded,90 91 ConfirmUnsetSponsorFail,92 93 EmptyArgument,94 }95}9697pub trait Config:98 system::Config99 + pallet_evm_coder_substrate::Config100 + pallet_common::Config101 + pallet_nonfungible::Config102 + pallet_refungible::Config103 + pallet_fungible::Config104 + Sized105 + TypeInfo106{107 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;108109 110 type WeightInfo: WeightInfo;111}112113decl_event! {114 pub enum Event<T>115 where116 <T as frame_system::Config>::AccountId,117 <T as pallet_evm::account::Config>::CrossAccountId,118 {119 120 121 122 123 124 CollectionSponsorRemoved(CollectionId),125126 127 128 129 130 131 132 133 CollectionAdminAdded(CollectionId, CrossAccountId),134135 136 137 138 139 140 141 142 CollectionOwnedChanged(CollectionId, AccountId),143144 145 146 147 148 149 150 151 CollectionSponsorSet(CollectionId, AccountId),152153 154 155 156 157 158 ConstOnChainSchemaSet(CollectionId),159160 161 162 163 164 165 166 167 SponsorshipConfirmed(CollectionId, AccountId),168169 170 171 172 173 174 175 176 CollectionAdminRemoved(CollectionId, CrossAccountId),177178 179 180 181 182 183 184 185 AllowListAddressRemoved(CollectionId, CrossAccountId),186187 188 189 190 191 192 193 194 AllowListAddressAdded(CollectionId, CrossAccountId),195196 197 198 199 200 201 CollectionLimitSet(CollectionId),202203 204 205 206 207 208 MintPermissionSet(CollectionId),209210 211 212 213 214 215 OffchainSchemaSet(CollectionId),216217 218 219 220 221 222 223 224 PublicAccessModeSet(CollectionId, AccessMode),225226 227 228 229 230 231 SchemaVersionSet(CollectionId),232233 234 235 236 237 238 VariableOnChainSchemaSet(CollectionId),239 }240}241242type SelfWeightOf<T> = <T as Config>::WeightInfo;243244245246247248249250251252253254255256257258259260261262263264265266decl_storage! {267 trait Store for Module<T: Config> as Unique {268269 270 271 ChainVersion: u64;272 273274 275 276 277 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;278 279 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;280 281 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;282 283 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>;284 285286 287 288 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;289 290 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;291 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;292 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>;293 }294}295296decl_module! {297 pub struct Module<T: Config> for enum Call298 where299 origin: T::Origin300 {301 type Error = Error<T>;302303 fn deposit_event() = default;304305 fn on_initialize(_now: T::BlockNumber) -> Weight {306 0307 }308309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 #[weight = <SelfWeightOf<T>>::create_collection()]326 #[transactional]327 #[deprecated]328 pub fn create_collection(origin,329 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,330 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,331 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,332 mode: CollectionMode) -> DispatchResult {333 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {334 name: collection_name,335 description: collection_description,336 token_prefix,337 mode,338 ..Default::default()339 };340 Self::create_collection_ex(origin, data)341 }342343 344 345 346 #[weight = <SelfWeightOf<T>>::create_collection()]347 #[transactional]348 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {349 let owner = ensure_signed(origin)?;350351 let _id = match data.mode {352 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},353 CollectionMode::Fungible(decimal_points) => {354 355 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);356 <PalletFungible<T>>::init_collection(owner, data)?357 }358 CollectionMode::ReFungible => {359 <PalletRefungible<T>>::init_collection(owner, data)?360 }361 };362363 Ok(())364 }365366 367 368 369 370 371 372 373 374 375 #[weight = <SelfWeightOf<T>>::destroy_collection()]376 #[transactional]377 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {378 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);379380 let collection = <CollectionHandle<T>>::try_get(collection_id)?;381 collection.check_is_owner(&sender)?;382383 384385 match collection.mode {386 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,387 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,388 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,389 }390391 <NftTransferBasket<T>>::remove_prefix(collection_id, None);392 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);393 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);394395 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);396 <NftApproveBasket<T>>::remove_prefix(collection_id, None);397 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);398 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);399400 Ok(())401 }402403 404 405 406 407 408 409 410 411 412 413 414 415 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]416 #[transactional]417 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{418419 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);420 let collection = <CollectionHandle<T>>::try_get(collection_id)?;421422 <PalletCommon<T>>::toggle_allowlist(423 &collection,424 &sender,425 &address,426 true,427 )?;428429 Self::deposit_event(Event::<T>::AllowListAddressAdded(430 collection_id,431 address432 ));433434 Ok(())435 }436437 438 439 440 441 442 443 444 445 446 447 448 449 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]450 #[transactional]451 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{452453 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);454 let collection = <CollectionHandle<T>>::try_get(collection_id)?;455456 <PalletCommon<T>>::toggle_allowlist(457 &collection,458 &sender,459 &address,460 false,461 )?;462463 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(464 collection_id,465 address466 ));467468 Ok(())469 }470471 472 473 474 475 476 477 478 479 480 481 482 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]483 #[transactional]484 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult485 {486 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);487488 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;489 target_collection.check_is_owner(&sender)?;490491 target_collection.access = mode.clone();492493 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(494 collection_id,495 mode496 ));497498 target_collection.save()499 }500501 502 503 504 505 506 507 508 509 510 511 512 513 514 #[weight = <SelfWeightOf<T>>::set_mint_permission()]515 #[transactional]516 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult517 {518 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);519520 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;521 target_collection.check_is_owner(&sender)?;522523 target_collection.mint_mode = mint_permission;524525 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(526 collection_id527 ));528529 target_collection.save()530 }531532 533 534 535 536 537 538 539 540 541 542 543 #[weight = <SelfWeightOf<T>>::change_collection_owner()]544 #[transactional]545 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {546547 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);548549 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;550 target_collection.check_is_owner(&sender)?;551552 target_collection.owner = new_owner.clone();553 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(554 collection_id,555 new_owner556 ));557558 target_collection.save()559 }560561 562 563 564 565 566 567 568 569 570 571 572 573 574 #[weight = <SelfWeightOf<T>>::add_collection_admin()]575 #[transactional]576 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {577 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);578 let collection = <CollectionHandle<T>>::try_get(collection_id)?;579580 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(581 collection_id,582 new_admin_id.clone()583 ));584585 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)586 }587588 589 590 591 592 593 594 595 596 597 598 599 600 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]601 #[transactional]602 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {603 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);604 let collection = <CollectionHandle<T>>::try_get(collection_id)?;605606 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(607 collection_id,608 account_id.clone()609 ));610611 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)612 }613614 615 616 617 618 619 620 621 622 623 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]624 #[transactional]625 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {626 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);627628 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;629 target_collection.check_is_owner(&sender)?;630631 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());632633 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(634 collection_id,635 new_sponsor636 ));637638 target_collection.save()639 }640641 642 643 644 645 646 647 648 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]649 #[transactional]650 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {651 let sender = ensure_signed(origin)?;652653 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;654 ensure!(655 target_collection.sponsorship.pending_sponsor() == Some(&sender),656 Error::<T>::ConfirmUnsetSponsorFail657 );658659 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());660661 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(662 collection_id,663 sender664 ));665666 target_collection.save()667 }668669 670 671 672 673 674 675 676 677 678 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]679 #[transactional]680 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {681 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);682683 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;684 target_collection.check_is_owner(&sender)?;685686 target_collection.sponsorship = SponsorshipState::Disabled;687688 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(689 collection_id690 ));691 target_collection.save()692 }693694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 #[weight = <CommonWeights<T>>::create_item()]713 #[transactional]714 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {715 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);716717 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))718 }719720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]739 #[transactional]740 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {741 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);742 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);743744 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))745 }746747 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]748 #[transactional]749 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {750 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);751752 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))753 }754755 756757 758 759 760 761 762 763 764 765 766 767 768 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]769 #[transactional]770 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {771 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);772 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;773 target_collection.check_is_owner(&sender)?;774775 776777 target_collection.limits.transfers_enabled = Some(value);778 target_collection.save()779 }780781 782 783 784 785 786 787 788 789 790 791 792 793 794 #[weight = <CommonWeights<T>>::burn_item()]795 #[transactional]796 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {797 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);798799 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;800 if value == 1 {801 <NftTransferBasket<T>>::remove(collection_id, item_id);802 <NftApproveBasket<T>>::remove(collection_id, item_id);803 }804 805 806 807 Ok(post_info)808 }809810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 #[weight = <CommonWeights<T>>::burn_from()]827 #[transactional]828 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {829 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);830831 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))832 }833834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 #[weight = <CommonWeights<T>>::transfer()]858 #[transactional]859 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {860 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);861862 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))863 }864865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 #[weight = <CommonWeights<T>>::approve()]881 #[transactional]882 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {883 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);884885 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))886 }887888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 #[weight = <CommonWeights<T>>::transfer_from()]908 #[transactional]909 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {910 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);911912 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))913 }914915 916 917 918 919 920 921 922 923 924 925 926 927 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]928 #[transactional]929 pub fn set_variable_meta_data (930 origin,931 collection_id: CollectionId,932 item_id: TokenId,933 data: BoundedVec<u8, CustomDataLimit>,934 ) -> DispatchResultWithPostInfo {935 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);936937 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))938 }939940 941 942 943 944 945 946 947 948 949 950 951 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]952 #[transactional]953 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {954 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);955 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;956957 ensure!(958 target_collection.meta_update_permission != MetaUpdatePermission::None,959 <CommonError<T>>::MetadataFlagFrozen,960 );961 target_collection.check_is_owner(&sender)?;962963 target_collection.meta_update_permission = value;964965 target_collection.save()966 }967968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 #[weight = <SelfWeightOf<T>>::set_schema_version()]983 #[transactional]984 pub fn set_schema_version(985 origin,986 collection_id: CollectionId,987 version: SchemaVersion988 ) -> DispatchResult {989 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);990 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;991 target_collection.check_is_owner_or_admin(&sender)?;992 target_collection.schema_version = version;993994 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(995 collection_id996 ));997998 target_collection.save()999 }10001001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1014 #[transactional]1015 pub fn set_offchain_schema(1016 origin,1017 collection_id: CollectionId,1018 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1019 ) -> DispatchResult {1020 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1021 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1022 target_collection.check_is_owner_or_admin(&sender)?;10231024 target_collection.offchain_schema = schema;10251026 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1027 collection_id1028 ));10291030 target_collection.save()1031 }10321033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1046 #[transactional]1047 pub fn set_const_on_chain_schema (1048 origin,1049 collection_id: CollectionId,1050 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1051 ) -> DispatchResult {1052 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1053 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1054 target_collection.check_is_owner_or_admin(&sender)?;10551056 target_collection.const_on_chain_schema = schema;10571058 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1059 collection_id1060 ));10611062 target_collection.save()1063 }10641065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1078 #[transactional]1079 pub fn set_variable_on_chain_schema (1080 origin,1081 collection_id: CollectionId,1082 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1083 ) -> DispatchResult {1084 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1085 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1086 target_collection.check_is_owner_or_admin(&sender)?;10871088 target_collection.variable_on_chain_schema = schema;10891090 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1091 collection_id1092 ));10931094 target_collection.save()1095 }10961097 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1098 #[transactional]1099 pub fn set_collection_limits(1100 origin,1101 collection_id: CollectionId,1102 new_limit: CollectionLimits,1103 ) -> DispatchResult {1104 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1105 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1106 target_collection.check_is_owner(&sender)?;1107 let old_limit = &target_collection.limits;11081109 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11101111 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1112 collection_id1113 ));11141115 target_collection.save()1116 }1117 }1118}