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)]2425use frame_support::{26 decl_module, decl_storage, decl_error, decl_event,27 dispatch::DispatchResult,28 ensure,29 weights::{Weight},30 transactional,31 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},32 BoundedVec,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 CONST_ON_CHAIN_SCHEMA_LIMIT, OFFCHAIN_SCHEMA_LIMIT,39 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,40 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,41 SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData,42 CreateItemExData, budget, CollectionField, Property, PropertyKey, PropertyKeyPermission,43};44use pallet_evm::account::CrossAccountId;45use pallet_common::{46 CollectionHandle, Pallet as PalletCommon, Error as CommonError, CommonWeightInfo,47 dispatch::dispatch_call, dispatch::CollectionDispatch,48};4950#[cfg(feature = "runtime-benchmarks")]51mod benchmarking;52pub mod weights;53use weights::WeightInfo;5455decl_error! {56 57 pub enum Error for Module<T: Config> {58 59 CollectionDecimalPointLimitExceeded,60 61 ConfirmUnsetSponsorFail,62 63 EmptyArgument,64 }65}6667pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {68 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;6970 71 type WeightInfo: WeightInfo;72 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;73}7475decl_event! {76 pub enum Event<T>77 where78 <T as frame_system::Config>::AccountId,79 <T as pallet_evm::account::Config>::CrossAccountId,80 {81 82 83 84 85 86 CollectionSponsorRemoved(CollectionId),8788 89 90 91 92 93 94 95 CollectionAdminAdded(CollectionId, CrossAccountId),9697 98 99 100 101 102 103 104 CollectionOwnedChanged(CollectionId, AccountId),105106 107 108 109 110 111 112 113 CollectionSponsorSet(CollectionId, AccountId),114115 116 117 118 119 120 ConstOnChainSchemaSet(CollectionId),121122 123 124 125 126 127 128 129 SponsorshipConfirmed(CollectionId, AccountId),130131 132 133 134 135 136 137 138 CollectionAdminRemoved(CollectionId, CrossAccountId),139140 141 142 143 144 145 146 147 AllowListAddressRemoved(CollectionId, CrossAccountId),148149 150 151 152 153 154 155 156 AllowListAddressAdded(CollectionId, CrossAccountId),157158 159 160 161 162 163 CollectionLimitSet(CollectionId),164165 166 167 168 169 170 MintPermissionSet(CollectionId),171172 173 174 175 176 177 OffchainSchemaSet(CollectionId),178179 180 181 182 183 184 185 186 PublicAccessModeSet(CollectionId, AccessMode),187188 189 190 191 192 193 SchemaVersionSet(CollectionId),194 }195}196197type SelfWeightOf<T> = <T as Config>::WeightInfo;198199200201202203204205206207208209210211212213214215216217218219220221decl_storage! {222 trait Store for Module<T: Config> as Unique {223224 225 226 ChainVersion: u64;227 228229 230 231 232 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;233 234 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;235 236 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;237 238 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>;239 240241 242 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;243 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;244 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>;245 }246}247248decl_module! {249 pub struct Module<T: Config> for enum Call250 where251 origin: T::Origin252 {253 type Error = Error<T>;254255 fn deposit_event() = default;256257 fn on_initialize(_now: T::BlockNumber) -> Weight {258 0259 }260261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 #[weight = <SelfWeightOf<T>>::create_collection()]278 #[transactional]279 #[deprecated]280 pub fn create_collection(origin,281 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,282 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,283 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,284 mode: CollectionMode) -> DispatchResult {285 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {286 name: collection_name,287 description: collection_description,288 token_prefix,289 mode,290 ..Default::default()291 };292 Self::create_collection_ex(origin, data)293 }294295 296 297 298 #[weight = <SelfWeightOf<T>>::create_collection()]299 #[transactional]300 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {301 let sender = ensure_signed(origin)?;302303 304305 T::CollectionDispatch::create(sender, data)?;306307 Ok(())308 }309310 311 312 313 314 315 316 317 318 319 #[weight = <SelfWeightOf<T>>::destroy_collection()]320 #[transactional]321 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {322 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);323 let collection = <CollectionHandle<T>>::try_get(collection_id)?;324325 326327 T::CollectionDispatch::destroy(sender, collection)?;328329 <NftTransferBasket<T>>::remove_prefix(collection_id, None);330 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);331 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);332333 <NftApproveBasket<T>>::remove_prefix(collection_id, None);334 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);335 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);336337 Ok(())338 }339340 341 342 343 344 345 346 347 348 349 350 351 352 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]353 #[transactional]354 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{355356 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);357 let collection = <CollectionHandle<T>>::try_get(collection_id)?;358359 <PalletCommon<T>>::toggle_allowlist(360 &collection,361 &sender,362 &address,363 true,364 )?;365366 Self::deposit_event(Event::<T>::AllowListAddressAdded(367 collection_id,368 address369 ));370371 Ok(())372 }373374 375 376 377 378 379 380 381 382 383 384 385 386 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]387 #[transactional]388 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{389390 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);391 let collection = <CollectionHandle<T>>::try_get(collection_id)?;392393 <PalletCommon<T>>::toggle_allowlist(394 &collection,395 &sender,396 &address,397 false,398 )?;399400 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(401 collection_id,402 address403 ));404405 Ok(())406 }407408 409 410 411 412 413 414 415 416 417 418 419 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]420 #[transactional]421 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult422 {423 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);424425 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;426 target_collection.check_is_owner(&sender)?;427428 target_collection.access = mode.clone();429430 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(431 collection_id,432 mode433 ));434435 target_collection.save()436 }437438 439 440 441 442 443 444 445 446 447 448 449 450 451 #[weight = <SelfWeightOf<T>>::set_mint_permission()]452 #[transactional]453 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult454 {455 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);456457 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;458 target_collection.check_is_owner(&sender)?;459460 target_collection.mint_mode = mint_permission;461462 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(463 collection_id464 ));465466 target_collection.save()467 }468469 470 471 472 473 474 475 476 477 478 479 480 #[weight = <SelfWeightOf<T>>::change_collection_owner()]481 #[transactional]482 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {483484 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);485486 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;487 target_collection.check_is_owner(&sender)?;488489 target_collection.owner = new_owner.clone();490 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(491 collection_id,492 new_owner493 ));494495 target_collection.save()496 }497498 499 500 501 502 503 504 505 506 507 508 509 510 511 #[weight = <SelfWeightOf<T>>::add_collection_admin()]512 #[transactional]513 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {514 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);515 let collection = <CollectionHandle<T>>::try_get(collection_id)?;516517 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(518 collection_id,519 new_admin_id.clone()520 ));521522 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)523 }524525 526 527 528 529 530 531 532 533 534 535 536 537 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]538 #[transactional]539 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {540 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);541 let collection = <CollectionHandle<T>>::try_get(collection_id)?;542543 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(544 collection_id,545 account_id.clone()546 ));547548 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)549 }550551 552 553 554 555 556 557 558 559 560 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]561 #[transactional]562 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {563 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);564565 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;566 target_collection.check_is_owner(&sender)?;567568 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());569570 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(571 collection_id,572 new_sponsor573 ));574575 target_collection.save()576 }577578 579 580 581 582 583 584 585 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]586 #[transactional]587 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {588 let sender = ensure_signed(origin)?;589590 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;591 ensure!(592 target_collection.sponsorship.pending_sponsor() == Some(&sender),593 Error::<T>::ConfirmUnsetSponsorFail594 );595596 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());597598 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(599 collection_id,600 sender601 ));602603 target_collection.save()604 }605606 607 608 609 610 611 612 613 614 615 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]616 #[transactional]617 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {618 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);619620 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;621 target_collection.check_is_owner(&sender)?;622623 target_collection.sponsorship = SponsorshipState::Disabled;624625 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(626 collection_id627 ));628 target_collection.save()629 }630631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 #[weight = T::CommonWeightInfo::create_item()]650 #[transactional]651 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {652 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);653 let budget = budget::Value::new(2);654655 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))656 }657658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 #[weight = T::CommonWeightInfo::create_multiple_items(items_data.len() as u32)]677 #[transactional]678 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {679 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);680 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);681 let budget = budget::Value::new(2);682683 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))684 }685686 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]687 #[transactional]688 pub fn set_collection_properties(689 origin,690 collection_id: CollectionId,691 properties: Vec<Property>692 ) -> DispatchResultWithPostInfo {693 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);694695 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);696697 dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))698 }699700 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]701 #[transactional]702 pub fn delete_collection_properties(703 origin,704 collection_id: CollectionId,705 property_keys: Vec<PropertyKey>,706 ) -> DispatchResultWithPostInfo {707 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);708709 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);710711 dispatch_call::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))712 }713714 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]715 #[transactional]716 pub fn set_token_properties(717 origin,718 collection_id: CollectionId,719 token_id: TokenId,720 properties: Vec<Property>721 ) -> DispatchResultWithPostInfo {722 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);723724 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);725726 dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))727 }728729 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]730 #[transactional]731 pub fn delete_token_properties(732 origin,733 collection_id: CollectionId,734 token_id: TokenId,735 property_keys: Vec<PropertyKey>736 ) -> DispatchResultWithPostInfo {737 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);738739 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);740741 dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))742 }743744 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]745 #[transactional]746 pub fn set_property_permissions(747 origin,748 collection_id: CollectionId,749 property_permissions: Vec<PropertyKeyPermission>,750 ) -> DispatchResultWithPostInfo {751 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);752753 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);754755 dispatch_call::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))756 }757758 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]759 #[transactional]760 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {761 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);762 let budget = budget::Value::new(2);763764 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))765 }766767 768769 770 771 772 773 774 775 776 777 778 779 780 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]781 #[transactional]782 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {783 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);784 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;785 target_collection.check_is_owner(&sender)?;786787 788789 target_collection.limits.transfers_enabled = Some(value);790 target_collection.save()791 }792793 794 795 796 797 798 799 800 801 802 803 804 805 806 #[weight = T::CommonWeightInfo::burn_item()]807 #[transactional]808 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {809 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);810811 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;812 if value == 1 {813 <NftTransferBasket<T>>::remove(collection_id, item_id);814 <NftApproveBasket<T>>::remove(collection_id, item_id);815 }816 817 818 819 Ok(post_info)820 }821822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 #[weight = T::CommonWeightInfo::burn_from()]839 #[transactional]840 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {841 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);842 let budget = budget::Value::new(2);843844 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))845 }846847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 #[weight = T::CommonWeightInfo::transfer()]871 #[transactional]872 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {873 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);874 let budget = budget::Value::new(2);875876 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))877 }878879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 #[weight = T::CommonWeightInfo::approve()]895 #[transactional]896 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {897 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);898899 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))900 }901902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 #[weight = T::CommonWeightInfo::transfer_from()]922 #[transactional]923 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {924 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);925 let budget = budget::Value::new(2);926927 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))928 }929930 931 932 933 934 935 936 937 938 939 940 941 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]942 #[transactional]943 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {944 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);945 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;946947 ensure!(948 target_collection.meta_update_permission != MetaUpdatePermission::None,949 <CommonError<T>>::MetadataFlagFrozen,950 );951 target_collection.check_is_owner(&sender)?;952953 target_collection.meta_update_permission = value;954955 target_collection.save()956 }957958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 #[weight = <SelfWeightOf<T>>::set_schema_version()]973 #[transactional]974 pub fn set_schema_version(975 origin,976 collection_id: CollectionId,977 version: SchemaVersion978 ) -> DispatchResult {979 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);980 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;981 target_collection.check_is_owner_or_admin(&sender)?;982 target_collection.schema_version = version;983984 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(985 collection_id986 ));987988 target_collection.save()989 }990991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1004 #[transactional]1005 pub fn set_offchain_schema(1006 origin,1007 collection_id: CollectionId,1008 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1009 ) -> DispatchResult {1010 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1011 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10121013 10141015 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;10161017 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1018 collection_id1019 ));1020 Ok(())1021 }10221023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1036 #[transactional]1037 pub fn set_const_on_chain_schema (1038 origin,1039 collection_id: CollectionId,1040 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1041 ) -> DispatchResult {1042 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1043 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10441045 10461047 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;10481049 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1050 collection_id1051 ));1052 Ok(())1053 }10541055 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1056 #[transactional]1057 pub fn set_collection_limits(1058 origin,1059 collection_id: CollectionId,1060 new_limit: CollectionLimits,1061 ) -> DispatchResult {1062 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1063 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1064 target_collection.check_is_owner(&sender)?;1065 let old_limit = &target_collection.limits;10661067 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10681069 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1070 collection_id1071 ));10721073 target_collection.save()1074 }1075 }1076}