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,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 MAX_DECIMAL_POINTS, VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,39 OFFCHAIN_SCHEMA_LIMIT, AccessMode, CreateItemData, CollectionLimits, CollectionId,40 CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,41 CreateCollectionData,42};43use pallet_common::{44 account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,45 CommonWeightInfo,46};47use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};48use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};49use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};5051#[cfg(test)]52mod mock;5354#[cfg(test)]55mod tests;5657mod eth;58mod sponsorship;59pub use sponsorship::UniqueSponsorshipHandler;60pub use eth::sponsoring::UniqueEthSponsorshipHandler;6162pub use eth::UniqueErcSupport;6364pub mod common;65use common::CommonWeights;66pub mod dispatch;67use dispatch::dispatch_call;6869#[cfg(feature = "runtime-benchmarks")]70mod benchmarking;71pub mod weights;72use weights::WeightInfo;7374decl_error! {75 76 pub enum Error for Module<T: Config> {77 78 CollectionDecimalPointLimitExceeded,79 80 ConfirmUnsetSponsorFail,81 82 EmptyArgument,83 }84}8586pub trait Config:87 system::Config88 + pallet_evm_coder_substrate::Config89 + pallet_common::Config90 + pallet_nonfungible::Config91 + pallet_refungible::Config92 + pallet_fungible::Config93 + Sized94 + TypeInfo95{96 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;9798 99 type WeightInfo: WeightInfo;100}101102decl_event! {103 pub enum Event<T>104 where105 <T as frame_system::Config>::AccountId,106 <T as pallet_common::Config>::CrossAccountId,107 {108 109 110 111 112 113 CollectionSponsorRemoved(CollectionId),114115 116 117 118 119 120 121 122 CollectionAdminAdded(CollectionId, CrossAccountId),123124 125 126 127 128 129 130 131 CollectionOwnedChanged(CollectionId, AccountId),132133 134 135 136 137 138 139 140 CollectionSponsorSet(CollectionId, AccountId),141142 143 144 145 146 147 ConstOnChainSchemaSet(CollectionId),148149 150 151 152 153 154 155 156 SponsorshipConfirmed(CollectionId, AccountId),157158 159 160 161 162 163 164 165 CollectionAdminRemoved(CollectionId, CrossAccountId),166167 168 169 170 171 172 173 174 AllowListAddressRemoved(CollectionId, CrossAccountId),175176 177 178 179 180 181 182 183 AllowListAddressAdded(CollectionId, CrossAccountId),184185 186 187 188 189 190 CollectionLimitSet(CollectionId),191192 193 194 195 196 197 MintPermissionSet(CollectionId),198199 200 201 202 203 204 OffchainSchemaSet(CollectionId),205206 207 208 209 210 211 212 213 PublicAccessModeSet(CollectionId, AccessMode),214215 216 217 218 219 220 SchemaVersionSet(CollectionId),221222 223 224 225 226 227 VariableOnChainSchemaSet(CollectionId),228 }229}230231type SelfWeightOf<T> = <T as Config>::WeightInfo;232233234235236237238239240241242243244245246247248249250251252253254255decl_storage! {256 trait Store for Module<T: Config> as Unique {257258 259 260 ChainVersion: u64;261 262263 264 265 266 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;267 268 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;269 270 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;271 272 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>;273 274275 276 277 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;278 279 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;280 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;281 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>;282 }283}284285decl_module! {286 pub struct Module<T: Config> for enum Call287 where288 origin: T::Origin289 {290 type Error = Error<T>;291292 fn deposit_event() = default;293294 fn on_initialize(_now: T::BlockNumber) -> Weight {295 0296 }297298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 #[weight = <SelfWeightOf<T>>::create_collection()]315 #[transactional]316 #[deprecated]317 pub fn create_collection(origin,318 collection_name: Vec<u16>,319 collection_description: Vec<u16>,320 token_prefix: Vec<u8>,321 mode: CollectionMode) -> DispatchResult {322 Self::create_collection_ex(origin, CreateCollectionData {323 name: collection_name,324 description: collection_description,325 token_prefix,326 mode,327 ..Default::default()328 })329 }330331 332 333 334 #[weight = <SelfWeightOf<T>>::create_collection()]335 #[transactional]336 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {337 let owner = ensure_signed(origin)?;338339 let _id = match data.mode {340 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},341 CollectionMode::Fungible(decimal_points) => {342 343 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);344 <PalletFungible<T>>::init_collection(owner, data)?345 }346 CollectionMode::ReFungible => {347 <PalletRefungible<T>>::init_collection(owner, data)?348 }349 };350351 Ok(())352 }353354 355 356 357 358 359 360 361 362 363 #[weight = <SelfWeightOf<T>>::destroy_collection()]364 #[transactional]365 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {366 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);367368 let collection = <CollectionHandle<T>>::try_get(collection_id)?;369 collection.check_is_owner(&sender)?;370371 372373 match collection.mode {374 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,375 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,376 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,377 }378379 <NftTransferBasket<T>>::remove_prefix(collection_id, None);380 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);381 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);382383 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);384 <NftApproveBasket<T>>::remove_prefix(collection_id, None);385 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);386 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);387388 Ok(())389 }390391 392 393 394 395 396 397 398 399 400 401 402 403 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]404 #[transactional]405 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{406407 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);408 let collection = <CollectionHandle<T>>::try_get(collection_id)?;409410 <PalletCommon<T>>::toggle_allowlist(411 &collection,412 &sender,413 &address,414 true,415 )?;416417 Self::deposit_event(Event::<T>::AllowListAddressAdded(418 collection_id,419 address420 ));421422 Ok(())423 }424425 426 427 428 429 430 431 432 433 434 435 436 437 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]438 #[transactional]439 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{440441 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);442 let collection = <CollectionHandle<T>>::try_get(collection_id)?;443444 <PalletCommon<T>>::toggle_allowlist(445 &collection,446 &sender,447 &address,448 false,449 )?;450451 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(452 collection_id,453 address454 ));455456 Ok(())457 }458459 460 461 462 463 464 465 466 467 468 469 470 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]471 #[transactional]472 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult473 {474 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);475476 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;477 target_collection.check_is_owner(&sender)?;478479 target_collection.access = mode.clone();480481 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(482 collection_id,483 mode484 ));485486 target_collection.save()487 }488489 490 491 492 493 494 495 496 497 498 499 500 501 502 #[weight = <SelfWeightOf<T>>::set_mint_permission()]503 #[transactional]504 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult505 {506 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);507508 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;509 target_collection.check_is_owner(&sender)?;510511 target_collection.mint_mode = mint_permission;512513 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(514 collection_id515 ));516517 target_collection.save()518 }519520 521 522 523 524 525 526 527 528 529 530 531 #[weight = <SelfWeightOf<T>>::change_collection_owner()]532 #[transactional]533 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {534535 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);536537 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;538 target_collection.check_is_owner(&sender)?;539540 target_collection.owner = new_owner.clone();541 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(542 collection_id,543 new_owner544 ));545546 target_collection.save()547 }548549 550 551 552 553 554 555 556 557 558 559 560 561 562 #[weight = <SelfWeightOf<T>>::add_collection_admin()]563 #[transactional]564 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {565 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);566 let collection = <CollectionHandle<T>>::try_get(collection_id)?;567568 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(569 collection_id,570 new_admin_id.clone()571 ));572573 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)574 }575576 577 578 579 580 581 582 583 584 585 586 587 588 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]589 #[transactional]590 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {591 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);592 let collection = <CollectionHandle<T>>::try_get(collection_id)?;593594 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(595 collection_id,596 account_id.clone()597 ));598599 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)600 }601602 603 604 605 606 607 608 609 610 611 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]612 #[transactional]613 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {614 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);615616 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;617 target_collection.check_is_owner(&sender)?;618619 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());620621 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(622 collection_id,623 new_sponsor624 ));625626 target_collection.save()627 }628629 630 631 632 633 634 635 636 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]637 #[transactional]638 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {639 let sender = ensure_signed(origin)?;640641 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;642 ensure!(643 target_collection.sponsorship.pending_sponsor() == Some(&sender),644 Error::<T>::ConfirmUnsetSponsorFail645 );646647 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());648649 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(650 collection_id,651 sender652 ));653654 target_collection.save()655 }656657 658 659 660 661 662 663 664 665 666 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]667 #[transactional]668 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {669 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);670671 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;672 target_collection.check_is_owner(&sender)?;673674 target_collection.sponsorship = SponsorshipState::Disabled;675676 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(677 collection_id678 ));679 target_collection.save()680 }681682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 #[weight = <CommonWeights<T>>::create_item()]701 #[transactional]702 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {703 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);704705 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))706 }707708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]727 #[transactional]728 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {729 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);730 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);731732 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))733 }734735 736737 738 739 740 741 742 743 744 745 746 747 748 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]749 #[transactional]750 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {751 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);752 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;753 target_collection.check_is_owner(&sender)?;754755 756757 target_collection.limits.transfers_enabled = Some(value);758 target_collection.save()759 }760761 762 763 764 765 766 767 768 769 770 771 772 773 774 #[weight = <CommonWeights<T>>::burn_item()]775 #[transactional]776 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {777 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);778779 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;780 if value == 1 {781 <NftTransferBasket<T>>::remove(collection_id, item_id);782 <NftApproveBasket<T>>::remove(collection_id, item_id);783 }784 785 786 787 Ok(post_info)788 }789790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 #[weight = <CommonWeights<T>>::burn_from()]807 #[transactional]808 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {809 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);810811 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))812 }813814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 #[weight = <CommonWeights<T>>::transfer()]838 #[transactional]839 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {840 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);841842 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))843 }844845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 #[weight = <CommonWeights<T>>::approve()]861 #[transactional]862 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {863 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);864865 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))866 }867868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 #[weight = <CommonWeights<T>>::transfer_from()]888 #[transactional]889 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {890 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);891892 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))893 }894895 896 897 898 899 900 901 902 903 904 905 906 907 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]908 #[transactional]909 pub fn set_variable_meta_data (910 origin,911 collection_id: CollectionId,912 item_id: TokenId,913 data: Vec<u8>914 ) -> DispatchResultWithPostInfo {915 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);916917 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))918 }919920 921 922 923 924 925 926 927 928 929 930 931 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]932 #[transactional]933 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {934 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);935 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;936937 ensure!(938 target_collection.meta_update_permission != MetaUpdatePermission::None,939 <CommonError<T>>::MetadataFlagFrozen,940 );941 target_collection.check_is_owner(&sender)?;942943 target_collection.meta_update_permission = value;944945 target_collection.save()946 }947948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 #[weight = <SelfWeightOf<T>>::set_schema_version()]963 #[transactional]964 pub fn set_schema_version(965 origin,966 collection_id: CollectionId,967 version: SchemaVersion968 ) -> DispatchResult {969 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);970 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;971 target_collection.check_is_owner_or_admin(&sender)?;972 target_collection.schema_version = version;973974 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(975 collection_id976 ));977978 target_collection.save()979 }980981 982 983 984 985 986 987 988 989 990 991 992 993 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]994 #[transactional]995 pub fn set_offchain_schema(996 origin,997 collection_id: CollectionId,998 schema: Vec<u8>999 ) -> DispatchResult {1000 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1001 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1002 target_collection.check_is_owner_or_admin(&sender)?;10031004 1005 ensure!(schema.len() as u32 <= OFFCHAIN_SCHEMA_LIMIT, "");10061007 target_collection.offchain_schema = schema;10081009 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1010 collection_id1011 ));10121013 target_collection.save()1014 }10151016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1029 #[transactional]1030 pub fn set_const_on_chain_schema (1031 origin,1032 collection_id: CollectionId,1033 schema: Vec<u8>1034 ) -> DispatchResult {1035 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1036 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1037 target_collection.check_is_owner_or_admin(&sender)?;10381039 1040 ensure!(schema.len() as u32 <= CONST_ON_CHAIN_SCHEMA_LIMIT, "");10411042 target_collection.const_on_chain_schema = schema;10431044 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1045 collection_id1046 ));10471048 target_collection.save()1049 }10501051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1064 #[transactional]1065 pub fn set_variable_on_chain_schema (1066 origin,1067 collection_id: CollectionId,1068 schema: Vec<u8>1069 ) -> DispatchResult {1070 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1071 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1072 target_collection.check_is_owner_or_admin(&sender)?;10731074 1075 ensure!(schema.len() as u32 <= VARIABLE_ON_CHAIN_SCHEMA_LIMIT, "");10761077 target_collection.variable_on_chain_schema = schema;10781079 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1080 collection_id1081 ));10821083 target_collection.save()1084 }10851086 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1087 #[transactional]1088 pub fn set_collection_limits(1089 origin,1090 collection_id: CollectionId,1091 new_limit: CollectionLimits,1092 ) -> DispatchResult {1093 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1094 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1095 target_collection.check_is_owner(&sender)?;1096 let old_limit = &target_collection.limits;10971098 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10991100 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1101 collection_id1102 ));11031104 target_collection.save()1105 }1106 }1107}