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, VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,40 OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,41 MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,42 CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,43 CreateCollectionData, CustomDataLimit, CreateItemExData,44};45use pallet_common::{46 account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,47 CommonWeightInfo,48};49use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};50use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};51use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};5253#[cfg(test)]54mod mock;5556#[cfg(test)]57mod tests;5859mod eth;60mod sponsorship;61pub use sponsorship::UniqueSponsorshipHandler;62pub use eth::sponsoring::UniqueEthSponsorshipHandler;6364pub use eth::UniqueErcSupport;6566pub mod common;67use common::CommonWeights;68pub mod dispatch;69use dispatch::dispatch_call;7071#[cfg(feature = "runtime-benchmarks")]72mod benchmarking;73pub mod weights;74use weights::WeightInfo;7576decl_error! {77 78 pub enum Error for Module<T: Config> {79 80 CollectionDecimalPointLimitExceeded,81 82 ConfirmUnsetSponsorFail,83 84 EmptyArgument,85 }86}8788pub trait Config:89 system::Config90 + pallet_evm_coder_substrate::Config91 + pallet_common::Config92 + pallet_nonfungible::Config93 + pallet_refungible::Config94 + pallet_fungible::Config95 + Sized96 + TypeInfo97{98 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;99100 101 type WeightInfo: WeightInfo;102}103104decl_event! {105 pub enum Event<T>106 where107 <T as frame_system::Config>::AccountId,108 <T as pallet_common::Config>::CrossAccountId,109 {110 111 112 113 114 115 CollectionSponsorRemoved(CollectionId),116117 118 119 120 121 122 123 124 CollectionAdminAdded(CollectionId, CrossAccountId),125126 127 128 129 130 131 132 133 CollectionOwnedChanged(CollectionId, AccountId),134135 136 137 138 139 140 141 142 CollectionSponsorSet(CollectionId, AccountId),143144 145 146 147 148 149 ConstOnChainSchemaSet(CollectionId),150151 152 153 154 155 156 157 158 SponsorshipConfirmed(CollectionId, AccountId),159160 161 162 163 164 165 166 167 CollectionAdminRemoved(CollectionId, CrossAccountId),168169 170 171 172 173 174 175 176 AllowListAddressRemoved(CollectionId, CrossAccountId),177178 179 180 181 182 183 184 185 AllowListAddressAdded(CollectionId, CrossAccountId),186187 188 189 190 191 192 CollectionLimitSet(CollectionId),193194 195 196 197 198 199 MintPermissionSet(CollectionId),200201 202 203 204 205 206 OffchainSchemaSet(CollectionId),207208 209 210 211 212 213 214 215 PublicAccessModeSet(CollectionId, AccessMode),216217 218 219 220 221 222 SchemaVersionSet(CollectionId),223224 225 226 227 228 229 VariableOnChainSchemaSet(CollectionId),230 }231}232233type SelfWeightOf<T> = <T as Config>::WeightInfo;234235236237238239240241242243244245246247248249250251252253254255256257decl_storage! {258 trait Store for Module<T: Config> as Unique {259260 261 262 ChainVersion: u64;263 264265 266 267 268 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;269 270 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;271 272 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;273 274 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>;275 276277 278 279 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;280 281 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;282 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;283 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>;284 }285}286287decl_module! {288 pub struct Module<T: Config> for enum Call289 where290 origin: T::Origin291 {292 type Error = Error<T>;293294 fn deposit_event() = default;295296 fn on_initialize(_now: T::BlockNumber) -> Weight {297 0298 }299300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 #[weight = <SelfWeightOf<T>>::create_collection()]317 #[transactional]318 #[deprecated]319 pub fn create_collection(origin,320 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,321 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,322 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,323 mode: CollectionMode) -> DispatchResult {324 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {325 name: collection_name,326 description: collection_description,327 token_prefix,328 mode,329 ..Default::default()330 };331 Self::create_collection_ex(origin, data)332 }333334 335 336 337 #[weight = <SelfWeightOf<T>>::create_collection()]338 #[transactional]339 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {340 let owner = ensure_signed(origin)?;341342 let _id = match data.mode {343 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},344 CollectionMode::Fungible(decimal_points) => {345 346 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);347 <PalletFungible<T>>::init_collection(owner, data)?348 }349 CollectionMode::ReFungible => {350 <PalletRefungible<T>>::init_collection(owner, data)?351 }352 };353354 Ok(())355 }356357 358 359 360 361 362 363 364 365 366 #[weight = <SelfWeightOf<T>>::destroy_collection()]367 #[transactional]368 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {369 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);370371 let collection = <CollectionHandle<T>>::try_get(collection_id)?;372 collection.check_is_owner(&sender)?;373374 375376 match collection.mode {377 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,378 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,379 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,380 }381382 <NftTransferBasket<T>>::remove_prefix(collection_id, None);383 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);384 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);385386 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);387 <NftApproveBasket<T>>::remove_prefix(collection_id, None);388 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);389 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);390391 Ok(())392 }393394 395 396 397 398 399 400 401 402 403 404 405 406 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]407 #[transactional]408 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{409410 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);411 let collection = <CollectionHandle<T>>::try_get(collection_id)?;412413 <PalletCommon<T>>::toggle_allowlist(414 &collection,415 &sender,416 &address,417 true,418 )?;419420 Self::deposit_event(Event::<T>::AllowListAddressAdded(421 collection_id,422 address423 ));424425 Ok(())426 }427428 429 430 431 432 433 434 435 436 437 438 439 440 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]441 #[transactional]442 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{443444 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);445 let collection = <CollectionHandle<T>>::try_get(collection_id)?;446447 <PalletCommon<T>>::toggle_allowlist(448 &collection,449 &sender,450 &address,451 false,452 )?;453454 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(455 collection_id,456 address457 ));458459 Ok(())460 }461462 463 464 465 466 467 468 469 470 471 472 473 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]474 #[transactional]475 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult476 {477 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);478479 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;480 target_collection.check_is_owner(&sender)?;481482 target_collection.access = mode.clone();483484 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(485 collection_id,486 mode487 ));488489 target_collection.save()490 }491492 493 494 495 496 497 498 499 500 501 502 503 504 505 #[weight = <SelfWeightOf<T>>::set_mint_permission()]506 #[transactional]507 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult508 {509 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);510511 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;512 target_collection.check_is_owner(&sender)?;513514 target_collection.mint_mode = mint_permission;515516 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(517 collection_id518 ));519520 target_collection.save()521 }522523 524 525 526 527 528 529 530 531 532 533 534 #[weight = <SelfWeightOf<T>>::change_collection_owner()]535 #[transactional]536 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {537538 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);539540 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;541 target_collection.check_is_owner(&sender)?;542543 target_collection.owner = new_owner.clone();544 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(545 collection_id,546 new_owner547 ));548549 target_collection.save()550 }551552 553 554 555 556 557 558 559 560 561 562 563 564 565 #[weight = <SelfWeightOf<T>>::add_collection_admin()]566 #[transactional]567 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {568 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);569 let collection = <CollectionHandle<T>>::try_get(collection_id)?;570571 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(572 collection_id,573 new_admin_id.clone()574 ));575576 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)577 }578579 580 581 582 583 584 585 586 587 588 589 590 591 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]592 #[transactional]593 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {594 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);595 let collection = <CollectionHandle<T>>::try_get(collection_id)?;596597 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(598 collection_id,599 account_id.clone()600 ));601602 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)603 }604605 606 607 608 609 610 611 612 613 614 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]615 #[transactional]616 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {617 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);618619 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;620 target_collection.check_is_owner(&sender)?;621622 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());623624 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(625 collection_id,626 new_sponsor627 ));628629 target_collection.save()630 }631632 633 634 635 636 637 638 639 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]640 #[transactional]641 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {642 let sender = ensure_signed(origin)?;643644 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;645 ensure!(646 target_collection.sponsorship.pending_sponsor() == Some(&sender),647 Error::<T>::ConfirmUnsetSponsorFail648 );649650 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());651652 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(653 collection_id,654 sender655 ));656657 target_collection.save()658 }659660 661 662 663 664 665 666 667 668 669 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]670 #[transactional]671 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {672 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);673674 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;675 target_collection.check_is_owner(&sender)?;676677 target_collection.sponsorship = SponsorshipState::Disabled;678679 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(680 collection_id681 ));682 target_collection.save()683 }684685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 #[weight = <CommonWeights<T>>::create_item()]704 #[transactional]705 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {706 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);707708 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))709 }710711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]730 #[transactional]731 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {732 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);733 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);734735 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))736 }737738 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]739 #[transactional]740 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {741 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);742743 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))744 }745746 747748 749 750 751 752 753 754 755 756 757 758 759 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]760 #[transactional]761 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {762 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);763 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;764 target_collection.check_is_owner(&sender)?;765766 767768 target_collection.limits.transfers_enabled = Some(value);769 target_collection.save()770 }771772 773 774 775 776 777 778 779 780 781 782 783 784 785 #[weight = <CommonWeights<T>>::burn_item()]786 #[transactional]787 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {788 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);789790 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;791 if value == 1 {792 <NftTransferBasket<T>>::remove(collection_id, item_id);793 <NftApproveBasket<T>>::remove(collection_id, item_id);794 }795 796 797 798 Ok(post_info)799 }800801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 #[weight = <CommonWeights<T>>::burn_from()]818 #[transactional]819 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {820 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);821822 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))823 }824825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 #[weight = <CommonWeights<T>>::transfer()]849 #[transactional]850 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {851 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);852853 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))854 }855856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 #[weight = <CommonWeights<T>>::approve()]872 #[transactional]873 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {874 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);875876 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))877 }878879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 #[weight = <CommonWeights<T>>::transfer_from()]899 #[transactional]900 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {901 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);902903 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))904 }905906 907 908 909 910 911 912 913 914 915 916 917 918 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]919 #[transactional]920 pub fn set_variable_meta_data (921 origin,922 collection_id: CollectionId,923 item_id: TokenId,924 data: BoundedVec<u8, CustomDataLimit>,925 ) -> DispatchResultWithPostInfo {926 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);927928 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))929 }930931 932 933 934 935 936 937 938 939 940 941 942 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]943 #[transactional]944 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {945 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);946 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;947948 ensure!(949 target_collection.meta_update_permission != MetaUpdatePermission::None,950 <CommonError<T>>::MetadataFlagFrozen,951 );952 target_collection.check_is_owner(&sender)?;953954 target_collection.meta_update_permission = value;955956 target_collection.save()957 }958959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 #[weight = <SelfWeightOf<T>>::set_schema_version()]974 #[transactional]975 pub fn set_schema_version(976 origin,977 collection_id: CollectionId,978 version: SchemaVersion979 ) -> DispatchResult {980 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);981 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;982 target_collection.check_is_owner_or_admin(&sender)?;983 target_collection.schema_version = version;984985 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(986 collection_id987 ));988989 target_collection.save()990 }991992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1005 #[transactional]1006 pub fn set_offchain_schema(1007 origin,1008 collection_id: CollectionId,1009 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1010 ) -> DispatchResult {1011 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1012 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1013 target_collection.check_is_owner_or_admin(&sender)?;10141015 target_collection.offchain_schema = schema;10161017 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1018 collection_id1019 ));10201021 target_collection.save()1022 }10231024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1037 #[transactional]1038 pub fn set_const_on_chain_schema (1039 origin,1040 collection_id: CollectionId,1041 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1042 ) -> DispatchResult {1043 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1044 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1045 target_collection.check_is_owner_or_admin(&sender)?;10461047 target_collection.const_on_chain_schema = schema;10481049 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1050 collection_id1051 ));10521053 target_collection.save()1054 }10551056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1069 #[transactional]1070 pub fn set_variable_on_chain_schema (1071 origin,1072 collection_id: CollectionId,1073 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1074 ) -> DispatchResult {1075 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1076 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1077 target_collection.check_is_owner_or_admin(&sender)?;10781079 target_collection.variable_on_chain_schema = schema;10801081 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1082 collection_id1083 ));10841085 target_collection.save()1086 }10871088 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1089 #[transactional]1090 pub fn set_collection_limits(1091 origin,1092 collection_id: CollectionId,1093 new_limit: CollectionLimits,1094 ) -> DispatchResult {1095 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1096 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1097 target_collection.check_is_owner(&sender)?;1098 let old_limit = &target_collection.limits;10991100 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11011102 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1103 collection_id1104 ));11051106 target_collection.save()1107 }1108 }1109}