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, UniqueSponsorshipPredict};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;8687pub trait SponsorshipPredict<T: Config> {88 fn predict(collection: CollectionId, account: T::CrossAccountId, token: TokenId) -> Option<u64>89 where90 u64: From<<T as frame_system::Config>::BlockNumber>;91}9293decl_error! {94 95 pub enum Error for Module<T: Config> {96 97 CollectionDecimalPointLimitExceeded,98 99 ConfirmUnsetSponsorFail,100 101 EmptyArgument,102 }103}104105pub trait Config:106 system::Config107 + pallet_evm_coder_substrate::Config108 + pallet_common::Config109 + pallet_nonfungible::Config110 + pallet_refungible::Config111 + pallet_fungible::Config112 + Sized113 + TypeInfo114{115 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;116117 118 type WeightInfo: WeightInfo;119}120121decl_event! {122 pub enum Event<T>123 where124 <T as frame_system::Config>::AccountId,125 <T as pallet_common::Config>::CrossAccountId,126 {127 128 129 130 131 132 CollectionSponsorRemoved(CollectionId),133134 135 136 137 138 139 140 141 CollectionAdminAdded(CollectionId, CrossAccountId),142143 144 145 146 147 148 149 150 CollectionOwnedChanged(CollectionId, AccountId),151152 153 154 155 156 157 158 159 CollectionSponsorSet(CollectionId, AccountId),160161 162 163 164 165 166 ConstOnChainSchemaSet(CollectionId),167168 169 170 171 172 173 174 175 SponsorshipConfirmed(CollectionId, AccountId),176177 178 179 180 181 182 183 184 CollectionAdminRemoved(CollectionId, CrossAccountId),185186 187 188 189 190 191 192 193 AllowListAddressRemoved(CollectionId, CrossAccountId),194195 196 197 198 199 200 201 202 AllowListAddressAdded(CollectionId, CrossAccountId),203204 205 206 207 208 209 CollectionLimitSet(CollectionId),210211 212 213 214 215 216 MintPermissionSet(CollectionId),217218 219 220 221 222 223 OffchainSchemaSet(CollectionId),224225 226 227 228 229 230 231 232 PublicAccessModeSet(CollectionId, AccessMode),233234 235 236 237 238 239 SchemaVersionSet(CollectionId),240241 242 243 244 245 246 VariableOnChainSchemaSet(CollectionId),247 }248}249250type SelfWeightOf<T> = <T as Config>::WeightInfo;251252253254255256257258259260261262263264265266267268269270271272273274decl_storage! {275 trait Store for Module<T: Config> as Unique {276277 278 279 ChainVersion: u64;280 281282 283 284 285 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;286 287 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;288 289 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;290 291 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>;292 293294 295 296 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;297 298 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;299 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;300 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>;301 }302}303304decl_module! {305 pub struct Module<T: Config> for enum Call306 where307 origin: T::Origin308 {309 type Error = Error<T>;310311 fn deposit_event() = default;312313 fn on_initialize(_now: T::BlockNumber) -> Weight {314 0315 }316317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 #[weight = <SelfWeightOf<T>>::create_collection()]334 #[transactional]335 #[deprecated]336 pub fn create_collection(origin,337 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,338 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,339 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,340 mode: CollectionMode) -> DispatchResult {341 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {342 name: collection_name,343 description: collection_description,344 token_prefix,345 mode,346 ..Default::default()347 };348 Self::create_collection_ex(origin, data)349 }350351 352 353 354 #[weight = <SelfWeightOf<T>>::create_collection()]355 #[transactional]356 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {357 let owner = ensure_signed(origin)?;358359 let _id = match data.mode {360 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},361 CollectionMode::Fungible(decimal_points) => {362 363 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);364 <PalletFungible<T>>::init_collection(owner, data)?365 }366 CollectionMode::ReFungible => {367 <PalletRefungible<T>>::init_collection(owner, data)?368 }369 };370371 Ok(())372 }373374 375 376 377 378 379 380 381 382 383 #[weight = <SelfWeightOf<T>>::destroy_collection()]384 #[transactional]385 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {386 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);387388 let collection = <CollectionHandle<T>>::try_get(collection_id)?;389 collection.check_is_owner(&sender)?;390391 392393 match collection.mode {394 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,395 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,396 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,397 }398399 <NftTransferBasket<T>>::remove_prefix(collection_id, None);400 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);401 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);402403 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);404 <NftApproveBasket<T>>::remove_prefix(collection_id, None);405 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);406 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);407408 Ok(())409 }410411 412 413 414 415 416 417 418 419 420 421 422 423 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]424 #[transactional]425 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{426427 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);428 let collection = <CollectionHandle<T>>::try_get(collection_id)?;429430 <PalletCommon<T>>::toggle_allowlist(431 &collection,432 &sender,433 &address,434 true,435 )?;436437 Self::deposit_event(Event::<T>::AllowListAddressAdded(438 collection_id,439 address440 ));441442 Ok(())443 }444445 446 447 448 449 450 451 452 453 454 455 456 457 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]458 #[transactional]459 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{460461 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);462 let collection = <CollectionHandle<T>>::try_get(collection_id)?;463464 <PalletCommon<T>>::toggle_allowlist(465 &collection,466 &sender,467 &address,468 false,469 )?;470471 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(472 collection_id,473 address474 ));475476 Ok(())477 }478479 480 481 482 483 484 485 486 487 488 489 490 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]491 #[transactional]492 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult493 {494 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);495496 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;497 target_collection.check_is_owner(&sender)?;498499 target_collection.access = mode.clone();500501 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(502 collection_id,503 mode504 ));505506 target_collection.save()507 }508509 510 511 512 513 514 515 516 517 518 519 520 521 522 #[weight = <SelfWeightOf<T>>::set_mint_permission()]523 #[transactional]524 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult525 {526 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);527528 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;529 target_collection.check_is_owner(&sender)?;530531 target_collection.mint_mode = mint_permission;532533 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(534 collection_id535 ));536537 target_collection.save()538 }539540 541 542 543 544 545 546 547 548 549 550 551 #[weight = <SelfWeightOf<T>>::change_collection_owner()]552 #[transactional]553 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {554555 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);556557 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;558 target_collection.check_is_owner(&sender)?;559560 target_collection.owner = new_owner.clone();561 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(562 collection_id,563 new_owner564 ));565566 target_collection.save()567 }568569 570 571 572 573 574 575 576 577 578 579 580 581 582 #[weight = <SelfWeightOf<T>>::add_collection_admin()]583 #[transactional]584 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {585 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);586 let collection = <CollectionHandle<T>>::try_get(collection_id)?;587588 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(589 collection_id,590 new_admin_id.clone()591 ));592593 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)594 }595596 597 598 599 600 601 602 603 604 605 606 607 608 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]609 #[transactional]610 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {611 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);612 let collection = <CollectionHandle<T>>::try_get(collection_id)?;613614 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(615 collection_id,616 account_id.clone()617 ));618619 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)620 }621622 623 624 625 626 627 628 629 630 631 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]632 #[transactional]633 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {634 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);635636 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;637 target_collection.check_is_owner(&sender)?;638639 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());640641 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(642 collection_id,643 new_sponsor644 ));645646 target_collection.save()647 }648649 650 651 652 653 654 655 656 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]657 #[transactional]658 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {659 let sender = ensure_signed(origin)?;660661 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;662 ensure!(663 target_collection.sponsorship.pending_sponsor() == Some(&sender),664 Error::<T>::ConfirmUnsetSponsorFail665 );666667 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());668669 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(670 collection_id,671 sender672 ));673674 target_collection.save()675 }676677 678 679 680 681 682 683 684 685 686 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]687 #[transactional]688 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {689 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);690691 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;692 target_collection.check_is_owner(&sender)?;693694 target_collection.sponsorship = SponsorshipState::Disabled;695696 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(697 collection_id698 ));699 target_collection.save()700 }701702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 #[weight = <CommonWeights<T>>::create_item()]721 #[transactional]722 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {723 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);724725 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))726 }727728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]747 #[transactional]748 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {749 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);750 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);751752 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))753 }754755 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]756 #[transactional]757 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {758 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);759760 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))761 }762763 764765 766 767 768 769 770 771 772 773 774 775 776 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]777 #[transactional]778 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {779 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);780 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;781 target_collection.check_is_owner(&sender)?;782783 784785 target_collection.limits.transfers_enabled = Some(value);786 target_collection.save()787 }788789 790 791 792 793 794 795 796 797 798 799 800 801 802 #[weight = <CommonWeights<T>>::burn_item()]803 #[transactional]804 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {805 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);806807 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;808 if value == 1 {809 <NftTransferBasket<T>>::remove(collection_id, item_id);810 <NftApproveBasket<T>>::remove(collection_id, item_id);811 }812 813 814 815 Ok(post_info)816 }817818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 #[weight = <CommonWeights<T>>::burn_from()]835 #[transactional]836 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {837 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);838839 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))840 }841842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 #[weight = <CommonWeights<T>>::transfer()]866 #[transactional]867 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {868 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);869870 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))871 }872873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 #[weight = <CommonWeights<T>>::approve()]889 #[transactional]890 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {891 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);892893 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))894 }895896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 #[weight = <CommonWeights<T>>::transfer_from()]916 #[transactional]917 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {918 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);919920 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))921 }922923 924 925 926 927 928 929 930 931 932 933 934 935 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]936 #[transactional]937 pub fn set_variable_meta_data (938 origin,939 collection_id: CollectionId,940 item_id: TokenId,941 data: BoundedVec<u8, CustomDataLimit>,942 ) -> DispatchResultWithPostInfo {943 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);944945 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))946 }947948 949 950 951 952 953 954 955 956 957 958 959 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]960 #[transactional]961 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {962 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);963 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;964965 ensure!(966 target_collection.meta_update_permission != MetaUpdatePermission::None,967 <CommonError<T>>::MetadataFlagFrozen,968 );969 target_collection.check_is_owner(&sender)?;970971 target_collection.meta_update_permission = value;972973 target_collection.save()974 }975976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 #[weight = <SelfWeightOf<T>>::set_schema_version()]991 #[transactional]992 pub fn set_schema_version(993 origin,994 collection_id: CollectionId,995 version: SchemaVersion996 ) -> DispatchResult {997 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);998 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;999 target_collection.check_is_owner_or_admin(&sender)?;1000 target_collection.schema_version = version;10011002 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(1003 collection_id1004 ));10051006 target_collection.save()1007 }10081009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1022 #[transactional]1023 pub fn set_offchain_schema(1024 origin,1025 collection_id: CollectionId,1026 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1027 ) -> DispatchResult {1028 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1029 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1030 target_collection.check_is_owner_or_admin(&sender)?;10311032 target_collection.offchain_schema = schema;10331034 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1035 collection_id1036 ));10371038 target_collection.save()1039 }10401041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1054 #[transactional]1055 pub fn set_const_on_chain_schema (1056 origin,1057 collection_id: CollectionId,1058 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1059 ) -> DispatchResult {1060 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1061 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1062 target_collection.check_is_owner_or_admin(&sender)?;10631064 target_collection.const_on_chain_schema = schema;10651066 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1067 collection_id1068 ));10691070 target_collection.save()1071 }10721073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1086 #[transactional]1087 pub fn set_variable_on_chain_schema (1088 origin,1089 collection_id: CollectionId,1090 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1091 ) -> DispatchResult {1092 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1093 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1094 target_collection.check_is_owner_or_admin(&sender)?;10951096 target_collection.variable_on_chain_schema = schema;10971098 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1099 collection_id1100 ));11011102 target_collection.save()1103 }11041105 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1106 #[transactional]1107 pub fn set_collection_limits(1108 origin,1109 collection_id: CollectionId,1110 new_limit: CollectionLimits,1111 ) -> DispatchResult {1112 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1113 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1114 target_collection.check_is_owner(&sender)?;1115 let old_limit = &target_collection.limits;11161117 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11181119 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1120 collection_id1121 ));11221123 target_collection.save()1124 }1125 }1126}