123456#![recursion_limit = "1024"]7#![cfg_attr(not(feature = "std"), no_std)]8#![allow(9 clippy::too_many_arguments,10 clippy::unnecessary_mut_passed,11 clippy::unused_unit12)]1314extern crate alloc;1516pub use serde::{Serialize, Deserialize};1718pub use frame_support::{19 construct_runtime, decl_module, decl_storage, decl_error, decl_event,20 dispatch::DispatchResult,21 ensure, fail, parameter_types,22 traits::{23 ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness,24 IsSubType, WithdrawReasons,25 },26 weights::{27 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},28 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,29 WeightToFeePolynomial, DispatchClass,30 },31 StorageValue, transactional,32 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},33 BoundedVec,34};35use scale_info::TypeInfo;36use frame_system::{self as system, ensure_signed};37use sp_runtime::{sp_std::prelude::Vec};38use up_data_structs::{39 MAX_DECIMAL_POINTS,40 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, OFFCHAIN_SCHEMA_LIMIT,41 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,42 MAX_TOKEN_PREFIX_LENGTH, AccessMode, Collection, CreateItemData, CollectionLimits,43 CollectionId, CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,44 CreateCollectionData, CustomDataLimit,45};46use pallet_common::{47 account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,48 CommonWeightInfo,49};50use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};51use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};52use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};5354#[cfg(test)]55mod mock;5657#[cfg(test)]58mod tests;5960mod eth;61mod sponsorship;62pub use sponsorship::UniqueSponsorshipHandler;63pub use eth::sponsoring::UniqueEthSponsorshipHandler;6465pub use eth::UniqueErcSupport;6667pub mod common;68use common::CommonWeights;69pub mod dispatch;70use dispatch::dispatch_call;7172#[cfg(feature = "runtime-benchmarks")]73mod benchmarking;74pub mod weights;75use weights::WeightInfo;7677decl_error! {78 79 pub enum Error for Module<T: Config> {80 81 CollectionDecimalPointLimitExceeded,82 83 ConfirmUnsetSponsorFail,84 85 EmptyArgument,86 }87}8889pub trait Config:90 system::Config91 + pallet_evm_coder_substrate::Config92 + pallet_common::Config93 + pallet_nonfungible::Config94 + pallet_refungible::Config95 + pallet_fungible::Config96 + Sized97 + TypeInfo98{99 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;100101 102 type WeightInfo: WeightInfo;103}104105decl_event! {106 pub enum Event<T>107 where108 <T as frame_system::Config>::AccountId,109 <T as pallet_common::Config>::CrossAccountId,110 {111 112 113 114 115 116 CollectionSponsorRemoved(CollectionId),117118 119 120 121 122 123 124 125 CollectionAdminAdded(CollectionId, CrossAccountId),126127 128 129 130 131 132 133 134 CollectionOwnedChanged(CollectionId, AccountId),135136 137 138 139 140 141 142 143 CollectionSponsorSet(CollectionId, AccountId),144145 146 147 148 149 150 ConstOnChainSchemaSet(CollectionId),151152 153 154 155 156 157 158 159 SponsorshipConfirmed(CollectionId, AccountId),160161 162 163 164 165 166 167 168 CollectionAdminRemoved(CollectionId, CrossAccountId),169170 171 172 173 174 175 176 177 AllowListAddressRemoved(CollectionId, CrossAccountId),178179 180 181 182 183 184 185 186 AllowListAddressAdded(CollectionId, CrossAccountId),187188 189 190 191 192 193 CollectionLimitSet(CollectionId),194195 196 197 198 199 200 MintPermissionSet(CollectionId),201202 203 204 205 206 207 OffchainSchemaSet(CollectionId),208209 210 211 212 213 214 215 216 PublicAccessModeSet(CollectionId, AccessMode),217218 219 220 221 222 223 SchemaVersionSet(CollectionId),224225 226 227 228 229 230 VariableOnChainSchemaSet(CollectionId),231 }232}233234type SelfWeightOf<T> = <T as Config>::WeightInfo;235236237238239240241242243244245246247248249250251252253254255256257258decl_storage! {259 trait Store for Module<T: Config> as Unique {260261 262 263 ChainVersion: u64;264 265266 267 268 269 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;270 271 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;272 273 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;274 275 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>;276 277278 279 280 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;281 282 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;283 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;284 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>;285 }286}287288decl_module! {289 pub struct Module<T: Config> for enum Call290 where291 origin: T::Origin292 {293 type Error = Error<T>;294295 fn deposit_event() = default;296297 fn on_initialize(_now: T::BlockNumber) -> Weight {298 0299 }300301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 #[weight = <SelfWeightOf<T>>::create_collection()]318 #[transactional]319 #[deprecated]320 pub fn create_collection(origin,321 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,322 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,323 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,324 mode: CollectionMode) -> DispatchResult {325 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {326 name: collection_name,327 description: collection_description,328 token_prefix,329 mode,330 ..Default::default()331 };332 Self::create_collection_ex(origin, data)333 }334335 336 337 338 #[weight = <SelfWeightOf<T>>::create_collection()]339 #[transactional]340 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {341 let owner = ensure_signed(origin)?;342343 let _id = match data.mode {344 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},345 CollectionMode::Fungible(decimal_points) => {346 347 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);348 <PalletFungible<T>>::init_collection(owner, data)?349 }350 CollectionMode::ReFungible => {351 <PalletRefungible<T>>::init_collection(owner, data)?352 }353 };354355 Ok(())356 }357358 359 360 361 362 363 364 365 366 367 #[weight = <SelfWeightOf<T>>::destroy_collection()]368 #[transactional]369 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {370 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);371372 let collection = <CollectionHandle<T>>::try_get(collection_id)?;373 collection.check_is_owner(&sender)?;374375 376377 match collection.mode {378 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,379 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,380 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,381 }382383 <NftTransferBasket<T>>::remove_prefix(collection_id, None);384 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);385 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);386387 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);388 <NftApproveBasket<T>>::remove_prefix(collection_id, None);389 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);390 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);391392 Ok(())393 }394395 396 397 398 399 400 401 402 403 404 405 406 407 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]408 #[transactional]409 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{410411 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);412 let collection = <CollectionHandle<T>>::try_get(collection_id)?;413414 <PalletCommon<T>>::toggle_allowlist(415 &collection,416 &sender,417 &address,418 true,419 )?;420421 Self::deposit_event(Event::<T>::AllowListAddressAdded(422 collection_id,423 address424 ));425426 Ok(())427 }428429 430 431 432 433 434 435 436 437 438 439 440 441 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]442 #[transactional]443 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{444445 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);446 let collection = <CollectionHandle<T>>::try_get(collection_id)?;447448 <PalletCommon<T>>::toggle_allowlist(449 &collection,450 &sender,451 &address,452 false,453 )?;454455 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(456 collection_id,457 address458 ));459460 Ok(())461 }462463 464 465 466 467 468 469 470 471 472 473 474 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]475 #[transactional]476 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult477 {478 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);479480 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;481 target_collection.check_is_owner(&sender)?;482483 target_collection.access = mode.clone();484485 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(486 collection_id,487 mode488 ));489490 target_collection.save()491 }492493 494 495 496 497 498 499 500 501 502 503 504 505 506 #[weight = <SelfWeightOf<T>>::set_mint_permission()]507 #[transactional]508 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult509 {510 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);511512 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;513 target_collection.check_is_owner(&sender)?;514515 target_collection.mint_mode = mint_permission;516517 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(518 collection_id519 ));520521 target_collection.save()522 }523524 525 526 527 528 529 530 531 532 533 534 535 #[weight = <SelfWeightOf<T>>::change_collection_owner()]536 #[transactional]537 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {538539 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);540541 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;542 target_collection.check_is_owner(&sender)?;543544 target_collection.owner = new_owner.clone();545 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(546 collection_id,547 new_owner548 ));549550 target_collection.save()551 }552553 554 555 556 557 558 559 560 561 562 563 564 565 566 #[weight = <SelfWeightOf<T>>::add_collection_admin()]567 #[transactional]568 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {569 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);570 let collection = <CollectionHandle<T>>::try_get(collection_id)?;571572 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(573 collection_id,574 new_admin_id.clone()575 ));576577 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)578 }579580 581 582 583 584 585 586 587 588 589 590 591 592 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]593 #[transactional]594 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {595 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);596 let collection = <CollectionHandle<T>>::try_get(collection_id)?;597598 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(599 collection_id,600 account_id.clone()601 ));602603 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)604 }605606 607 608 609 610 611 612 613 614 615 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]616 #[transactional]617 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {618 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);619620 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;621 target_collection.check_is_owner(&sender)?;622623 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());624625 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(626 collection_id,627 new_sponsor628 ));629630 target_collection.save()631 }632633 634 635 636 637 638 639 640 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]641 #[transactional]642 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {643 let sender = ensure_signed(origin)?;644645 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;646 ensure!(647 target_collection.sponsorship.pending_sponsor() == Some(&sender),648 Error::<T>::ConfirmUnsetSponsorFail649 );650651 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());652653 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(654 collection_id,655 sender656 ));657658 target_collection.save()659 }660661 662 663 664 665 666 667 668 669 670 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]671 #[transactional]672 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {673 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);674675 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;676 target_collection.check_is_owner(&sender)?;677678 target_collection.sponsorship = SponsorshipState::Disabled;679680 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(681 collection_id682 ));683 target_collection.save()684 }685686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 #[weight = <CommonWeights<T>>::create_item()]705 #[transactional]706 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {707 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);708709 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))710 }711712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]731 #[transactional]732 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {733 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);734 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);735736 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))737 }738739 740741 742 743 744 745 746 747 748 749 750 751 752 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]753 #[transactional]754 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {755 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);756 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;757 target_collection.check_is_owner(&sender)?;758759 760761 target_collection.limits.transfers_enabled = Some(value);762 target_collection.save()763 }764765 766 767 768 769 770 771 772 773 774 775 776 777 778 #[weight = <CommonWeights<T>>::burn_item()]779 #[transactional]780 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {781 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);782783 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;784 if value == 1 {785 <NftTransferBasket<T>>::remove(collection_id, item_id);786 <NftApproveBasket<T>>::remove(collection_id, item_id);787 }788 789 790 791 Ok(post_info)792 }793794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 #[weight = <CommonWeights<T>>::burn_from()]811 #[transactional]812 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {813 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);814815 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))816 }817818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 #[weight = <CommonWeights<T>>::transfer()]842 #[transactional]843 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {844 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);845846 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))847 }848849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 #[weight = <CommonWeights<T>>::approve()]865 #[transactional]866 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {867 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);868869 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))870 }871872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 #[weight = <CommonWeights<T>>::transfer_from()]892 #[transactional]893 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {894 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);895896 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))897 }898899 900 901 902 903 904 905 906 907 908 909 910 911 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]912 #[transactional]913 pub fn set_variable_meta_data (914 origin,915 collection_id: CollectionId,916 item_id: TokenId,917 data: BoundedVec<u8, CustomDataLimit>,918 ) -> DispatchResultWithPostInfo {919 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);920921 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))922 }923924 925 926 927 928 929 930 931 932 933 934 935 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]936 #[transactional]937 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {938 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);939 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;940941 ensure!(942 target_collection.meta_update_permission != MetaUpdatePermission::None,943 <CommonError<T>>::MetadataFlagFrozen,944 );945 target_collection.check_is_owner(&sender)?;946947 target_collection.meta_update_permission = value;948949 target_collection.save()950 }951952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 #[weight = <SelfWeightOf<T>>::set_schema_version()]967 #[transactional]968 pub fn set_schema_version(969 origin,970 collection_id: CollectionId,971 version: SchemaVersion972 ) -> DispatchResult {973 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);974 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;975 target_collection.check_is_owner_or_admin(&sender)?;976 target_collection.schema_version = version;977978 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(979 collection_id980 ));981982 target_collection.save()983 }984985 986 987 988 989 990 991 992 993 994 995 996 997 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]998 #[transactional]999 pub fn set_offchain_schema(1000 origin,1001 collection_id: CollectionId,1002 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1003 ) -> DispatchResult {1004 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1005 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1006 target_collection.check_is_owner_or_admin(&sender)?;10071008 target_collection.offchain_schema = schema;10091010 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1011 collection_id1012 ));10131014 target_collection.save()1015 }10161017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1030 #[transactional]1031 pub fn set_const_on_chain_schema (1032 origin,1033 collection_id: CollectionId,1034 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1035 ) -> DispatchResult {1036 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1037 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1038 target_collection.check_is_owner_or_admin(&sender)?;10391040 target_collection.const_on_chain_schema = schema;10411042 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1043 collection_id1044 ));10451046 target_collection.save()1047 }10481049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1062 #[transactional]1063 pub fn set_variable_on_chain_schema (1064 origin,1065 collection_id: CollectionId,1066 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1067 ) -> DispatchResult {1068 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1069 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1070 target_collection.check_is_owner_or_admin(&sender)?;10711072 target_collection.variable_on_chain_schema = schema;10731074 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1075 collection_id1076 ));10771078 target_collection.save()1079 }10801081 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1082 #[transactional]1083 pub fn set_collection_limits(1084 origin,1085 collection_id: CollectionId,1086 new_limit: CollectionLimits,1087 ) -> DispatchResult {1088 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1089 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1090 target_collection.check_is_owner(&sender)?;1091 let old_limit = &target_collection.limits;10921093 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10941095 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1096 collection_id1097 ));10981099 target_collection.save()1100 }1101 }1102}