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 account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,58 CommonWeightInfo,59};60use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};61use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};62use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};6364#[cfg(test)]65mod mock;6667#[cfg(test)]68mod tests;6970mod eth;71mod sponsorship;72pub use sponsorship::UniqueSponsorshipHandler;73pub use eth::sponsoring::UniqueEthSponsorshipHandler;7475pub use eth::UniqueErcSupport;7677pub mod common;78use common::CommonWeights;79pub mod dispatch;80use dispatch::dispatch_call;8182#[cfg(feature = "runtime-benchmarks")]83mod benchmarking;84pub mod weights;85use weights::WeightInfo;8687decl_error! {88 89 pub enum Error for Module<T: Config> {90 91 CollectionDecimalPointLimitExceeded,92 93 ConfirmUnsetSponsorFail,94 95 EmptyArgument,96 }97}9899pub trait Config:100 system::Config101 + pallet_evm_coder_substrate::Config102 + pallet_common::Config103 + pallet_nonfungible::Config104 + pallet_refungible::Config105 + pallet_fungible::Config106 + Sized107 + TypeInfo108{109 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;110111 112 type WeightInfo: WeightInfo;113}114115decl_event! {116 pub enum Event<T>117 where118 <T as frame_system::Config>::AccountId,119 <T as pallet_common::Config>::CrossAccountId,120 {121 122 123 124 125 126 CollectionSponsorRemoved(CollectionId),127128 129 130 131 132 133 134 135 CollectionAdminAdded(CollectionId, CrossAccountId),136137 138 139 140 141 142 143 144 CollectionOwnedChanged(CollectionId, AccountId),145146 147 148 149 150 151 152 153 CollectionSponsorSet(CollectionId, AccountId),154155 156 157 158 159 160 ConstOnChainSchemaSet(CollectionId),161162 163 164 165 166 167 168 169 SponsorshipConfirmed(CollectionId, AccountId),170171 172 173 174 175 176 177 178 CollectionAdminRemoved(CollectionId, CrossAccountId),179180 181 182 183 184 185 186 187 AllowListAddressRemoved(CollectionId, CrossAccountId),188189 190 191 192 193 194 195 196 AllowListAddressAdded(CollectionId, CrossAccountId),197198 199 200 201 202 203 CollectionLimitSet(CollectionId),204205 206 207 208 209 210 MintPermissionSet(CollectionId),211212 213 214 215 216 217 OffchainSchemaSet(CollectionId),218219 220 221 222 223 224 225 226 PublicAccessModeSet(CollectionId, AccessMode),227228 229 230 231 232 233 SchemaVersionSet(CollectionId),234235 236 237 238 239 240 VariableOnChainSchemaSet(CollectionId),241 }242}243244type SelfWeightOf<T> = <T as Config>::WeightInfo;245246247248249250251252253254255256257258259260261262263264265266267268decl_storage! {269 trait Store for Module<T: Config> as Unique {270271 272 273 ChainVersion: u64;274 275276 277 278 279 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;280 281 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;282 283 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;284 285 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>;286 287288 289 290 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;291 292 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;293 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;294 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>;295 }296}297298decl_module! {299 pub struct Module<T: Config> for enum Call300 where301 origin: T::Origin302 {303 type Error = Error<T>;304305 fn deposit_event() = default;306307 fn on_initialize(_now: T::BlockNumber) -> Weight {308 0309 }310311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 #[weight = <SelfWeightOf<T>>::create_collection()]328 #[transactional]329 #[deprecated]330 pub fn create_collection(origin,331 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,332 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,333 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,334 mode: CollectionMode) -> DispatchResult {335 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {336 name: collection_name,337 description: collection_description,338 token_prefix,339 mode,340 ..Default::default()341 };342 Self::create_collection_ex(origin, data)343 }344345 346 347 348 #[weight = <SelfWeightOf<T>>::create_collection()]349 #[transactional]350 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {351 let owner = ensure_signed(origin)?;352353 let _id = match data.mode {354 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},355 CollectionMode::Fungible(decimal_points) => {356 357 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);358 <PalletFungible<T>>::init_collection(owner, data)?359 }360 CollectionMode::ReFungible => {361 <PalletRefungible<T>>::init_collection(owner, data)?362 }363 };364365 Ok(())366 }367368 369 370 371 372 373 374 375 376 377 #[weight = <SelfWeightOf<T>>::destroy_collection()]378 #[transactional]379 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {380 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);381382 let collection = <CollectionHandle<T>>::try_get(collection_id)?;383 collection.check_is_owner(&sender)?;384385 386387 match collection.mode {388 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,389 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,390 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,391 }392393 <NftTransferBasket<T>>::remove_prefix(collection_id, None);394 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);395 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);396397 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);398 <NftApproveBasket<T>>::remove_prefix(collection_id, None);399 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);400 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);401402 Ok(())403 }404405 406 407 408 409 410 411 412 413 414 415 416 417 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]418 #[transactional]419 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{420421 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);422 let collection = <CollectionHandle<T>>::try_get(collection_id)?;423424 <PalletCommon<T>>::toggle_allowlist(425 &collection,426 &sender,427 &address,428 true,429 )?;430431 Self::deposit_event(Event::<T>::AllowListAddressAdded(432 collection_id,433 address434 ));435436 Ok(())437 }438439 440 441 442 443 444 445 446 447 448 449 450 451 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]452 #[transactional]453 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{454455 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);456 let collection = <CollectionHandle<T>>::try_get(collection_id)?;457458 <PalletCommon<T>>::toggle_allowlist(459 &collection,460 &sender,461 &address,462 false,463 )?;464465 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(466 collection_id,467 address468 ));469470 Ok(())471 }472473 474 475 476 477 478 479 480 481 482 483 484 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]485 #[transactional]486 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult487 {488 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);489490 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;491 target_collection.check_is_owner(&sender)?;492493 target_collection.access = mode.clone();494495 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(496 collection_id,497 mode498 ));499500 target_collection.save()501 }502503 504 505 506 507 508 509 510 511 512 513 514 515 516 #[weight = <SelfWeightOf<T>>::set_mint_permission()]517 #[transactional]518 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult519 {520 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);521522 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;523 target_collection.check_is_owner(&sender)?;524525 target_collection.mint_mode = mint_permission;526527 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(528 collection_id529 ));530531 target_collection.save()532 }533534 535 536 537 538 539 540 541 542 543 544 545 #[weight = <SelfWeightOf<T>>::change_collection_owner()]546 #[transactional]547 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {548549 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);550551 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;552 target_collection.check_is_owner(&sender)?;553554 target_collection.owner = new_owner.clone();555 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(556 collection_id,557 new_owner558 ));559560 target_collection.save()561 }562563 564 565 566 567 568 569 570 571 572 573 574 575 576 #[weight = <SelfWeightOf<T>>::add_collection_admin()]577 #[transactional]578 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {579 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);580 let collection = <CollectionHandle<T>>::try_get(collection_id)?;581582 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(583 collection_id,584 new_admin_id.clone()585 ));586587 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)588 }589590 591 592 593 594 595 596 597 598 599 600 601 602 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]603 #[transactional]604 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {605 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);606 let collection = <CollectionHandle<T>>::try_get(collection_id)?;607608 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(609 collection_id,610 account_id.clone()611 ));612613 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)614 }615616 617 618 619 620 621 622 623 624 625 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]626 #[transactional]627 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {628 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);629630 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;631 target_collection.check_is_owner(&sender)?;632633 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());634635 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(636 collection_id,637 new_sponsor638 ));639640 target_collection.save()641 }642643 644 645 646 647 648 649 650 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]651 #[transactional]652 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {653 let sender = ensure_signed(origin)?;654655 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;656 ensure!(657 target_collection.sponsorship.pending_sponsor() == Some(&sender),658 Error::<T>::ConfirmUnsetSponsorFail659 );660661 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());662663 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(664 collection_id,665 sender666 ));667668 target_collection.save()669 }670671 672 673 674 675 676 677 678 679 680 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]681 #[transactional]682 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {683 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);684685 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;686 target_collection.check_is_owner(&sender)?;687688 target_collection.sponsorship = SponsorshipState::Disabled;689690 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(691 collection_id692 ));693 target_collection.save()694 }695696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 #[weight = <CommonWeights<T>>::create_item()]715 #[transactional]716 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {717 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);718719 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))720 }721722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]741 #[transactional]742 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {743 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);744 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);745746 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))747 }748749 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]750 #[transactional]751 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {752 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);753754 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))755 }756757 758759 760 761 762 763 764 765 766 767 768 769 770 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]771 #[transactional]772 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {773 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);774 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;775 target_collection.check_is_owner(&sender)?;776777 778779 target_collection.limits.transfers_enabled = Some(value);780 target_collection.save()781 }782783 784 785 786 787 788 789 790 791 792 793 794 795 796 #[weight = <CommonWeights<T>>::burn_item()]797 #[transactional]798 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {799 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);800801 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;802 if value == 1 {803 <NftTransferBasket<T>>::remove(collection_id, item_id);804 <NftApproveBasket<T>>::remove(collection_id, item_id);805 }806 807 808 809 Ok(post_info)810 }811812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 #[weight = <CommonWeights<T>>::burn_from()]829 #[transactional]830 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {831 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);832833 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))834 }835836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 #[weight = <CommonWeights<T>>::transfer()]860 #[transactional]861 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {862 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);863864 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))865 }866867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 #[weight = <CommonWeights<T>>::approve()]883 #[transactional]884 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {885 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);886887 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))888 }889890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 #[weight = <CommonWeights<T>>::transfer_from()]910 #[transactional]911 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {912 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);913914 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))915 }916917 918 919 920 921 922 923 924 925 926 927 928 929 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]930 #[transactional]931 pub fn set_variable_meta_data (932 origin,933 collection_id: CollectionId,934 item_id: TokenId,935 data: BoundedVec<u8, CustomDataLimit>,936 ) -> DispatchResultWithPostInfo {937 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);938939 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))940 }941942 943 944 945 946 947 948 949 950 951 952 953 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]954 #[transactional]955 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {956 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);957 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;958959 ensure!(960 target_collection.meta_update_permission != MetaUpdatePermission::None,961 <CommonError<T>>::MetadataFlagFrozen,962 );963 target_collection.check_is_owner(&sender)?;964965 target_collection.meta_update_permission = value;966967 target_collection.save()968 }969970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 #[weight = <SelfWeightOf<T>>::set_schema_version()]985 #[transactional]986 pub fn set_schema_version(987 origin,988 collection_id: CollectionId,989 version: SchemaVersion990 ) -> DispatchResult {991 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);992 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;993 target_collection.check_is_owner_or_admin(&sender)?;994 target_collection.schema_version = version;995996 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(997 collection_id998 ));9991000 target_collection.save()1001 }10021003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1016 #[transactional]1017 pub fn set_offchain_schema(1018 origin,1019 collection_id: CollectionId,1020 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1021 ) -> DispatchResult {1022 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1023 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1024 target_collection.check_is_owner_or_admin(&sender)?;10251026 target_collection.offchain_schema = schema;10271028 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1029 collection_id1030 ));10311032 target_collection.save()1033 }10341035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1048 #[transactional]1049 pub fn set_const_on_chain_schema (1050 origin,1051 collection_id: CollectionId,1052 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1053 ) -> DispatchResult {1054 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1055 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1056 target_collection.check_is_owner_or_admin(&sender)?;10571058 target_collection.const_on_chain_schema = schema;10591060 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1061 collection_id1062 ));10631064 target_collection.save()1065 }10661067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1080 #[transactional]1081 pub fn set_variable_on_chain_schema (1082 origin,1083 collection_id: CollectionId,1084 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1085 ) -> DispatchResult {1086 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1087 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1088 target_collection.check_is_owner_or_admin(&sender)?;10891090 target_collection.variable_on_chain_schema = schema;10911092 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1093 collection_id1094 ));10951096 target_collection.save()1097 }10981099 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1100 #[transactional]1101 pub fn set_collection_limits(1102 origin,1103 collection_id: CollectionId,1104 new_limit: CollectionLimits,1105 ) -> DispatchResult {1106 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1107 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1108 target_collection.check_is_owner(&sender)?;1109 let old_limit = &target_collection.limits;11101111 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11121113 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1114 collection_id1115 ));11161117 target_collection.save()1118 }1119 }1120}