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 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, 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, CustomDataLimit,42 CreateItemExData, budget, CollectionField,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;5455pub trait SponsorshipPredict<T: Config> {56 fn predict(collection: CollectionId, account: T::CrossAccountId, token: TokenId) -> Option<u64>57 where58 u64: From<<T as frame_system::Config>::BlockNumber>;59}6061decl_error! {62 63 pub enum Error for Module<T: Config> {64 65 CollectionDecimalPointLimitExceeded,66 67 ConfirmUnsetSponsorFail,68 69 EmptyArgument,70 }71}7273pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {74 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;7576 77 type WeightInfo: WeightInfo;78 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;79}8081decl_event! {82 pub enum Event<T>83 where84 <T as frame_system::Config>::AccountId,85 <T as pallet_evm::account::Config>::CrossAccountId,86 {87 88 89 90 91 92 CollectionSponsorRemoved(CollectionId),9394 95 96 97 98 99 100 101 CollectionAdminAdded(CollectionId, CrossAccountId),102103 104 105 106 107 108 109 110 CollectionOwnedChanged(CollectionId, AccountId),111112 113 114 115 116 117 118 119 CollectionSponsorSet(CollectionId, AccountId),120121 122 123 124 125 126 ConstOnChainSchemaSet(CollectionId),127128 129 130 131 132 133 134 135 SponsorshipConfirmed(CollectionId, AccountId),136137 138 139 140 141 142 143 144 CollectionAdminRemoved(CollectionId, CrossAccountId),145146 147 148 149 150 151 152 153 AllowListAddressRemoved(CollectionId, CrossAccountId),154155 156 157 158 159 160 161 162 AllowListAddressAdded(CollectionId, CrossAccountId),163164 165 166 167 168 169 CollectionLimitSet(CollectionId),170171 172 173 174 175 176 MintPermissionSet(CollectionId),177178 179 180 181 182 183 OffchainSchemaSet(CollectionId),184185 186 187 188 189 190 191 192 PublicAccessModeSet(CollectionId, AccessMode),193194 195 196 197 198 199 SchemaVersionSet(CollectionId),200201 202 203 204 205 206 VariableOnChainSchemaSet(CollectionId),207 }208}209210type SelfWeightOf<T> = <T as Config>::WeightInfo;211212213214215216217218219220221222223224225226227228229230231232233234decl_storage! {235 trait Store for Module<T: Config> as Unique {236237 238 239 ChainVersion: u64;240 241242 243 244 245 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;246 247 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;248 249 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;250 251 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>;252 253254 255 256 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;257 258 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;259 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;260 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>;261 }262}263264decl_module! {265 pub struct Module<T: Config> for enum Call266 where267 origin: T::Origin268 {269 type Error = Error<T>;270271 fn deposit_event() = default;272273 fn on_initialize(_now: T::BlockNumber) -> Weight {274 0275 }276277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 #[weight = <SelfWeightOf<T>>::create_collection()]294 #[transactional]295 #[deprecated]296 pub fn create_collection(origin,297 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,298 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,299 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,300 mode: CollectionMode) -> DispatchResult {301 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {302 name: collection_name,303 description: collection_description,304 token_prefix,305 mode,306 ..Default::default()307 };308 Self::create_collection_ex(origin, data)309 }310311 312 313 314 #[weight = <SelfWeightOf<T>>::create_collection()]315 #[transactional]316 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {317 let sender = ensure_signed(origin)?;318319 320321 T::CollectionDispatch::create(sender, data)?;322323 Ok(())324 }325326 327 328 329 330 331 332 333 334 335 #[weight = <SelfWeightOf<T>>::destroy_collection()]336 #[transactional]337 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {338 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);339 let collection = <CollectionHandle<T>>::try_get(collection_id)?;340341 342343 T::CollectionDispatch::destroy(sender, collection)?;344345 <NftTransferBasket<T>>::remove_prefix(collection_id, None);346 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);347 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);348349 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);350 <NftApproveBasket<T>>::remove_prefix(collection_id, None);351 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);352 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);353354 Ok(())355 }356357 358 359 360 361 362 363 364 365 366 367 368 369 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]370 #[transactional]371 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{372373 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);374 let collection = <CollectionHandle<T>>::try_get(collection_id)?;375376 <PalletCommon<T>>::toggle_allowlist(377 &collection,378 &sender,379 &address,380 true,381 )?;382383 Self::deposit_event(Event::<T>::AllowListAddressAdded(384 collection_id,385 address386 ));387388 Ok(())389 }390391 392 393 394 395 396 397 398 399 400 401 402 403 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]404 #[transactional]405 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{406407 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);408 let collection = <CollectionHandle<T>>::try_get(collection_id)?;409410 <PalletCommon<T>>::toggle_allowlist(411 &collection,412 &sender,413 &address,414 false,415 )?;416417 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(418 collection_id,419 address420 ));421422 Ok(())423 }424425 426 427 428 429 430 431 432 433 434 435 436 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]437 #[transactional]438 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult439 {440 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);441442 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;443 target_collection.check_is_owner(&sender)?;444445 target_collection.access = mode.clone();446447 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(448 collection_id,449 mode450 ));451452 target_collection.save()453 }454455 456 457 458 459 460 461 462 463 464 465 466 467 468 #[weight = <SelfWeightOf<T>>::set_mint_permission()]469 #[transactional]470 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult471 {472 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);473474 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;475 target_collection.check_is_owner(&sender)?;476477 target_collection.mint_mode = mint_permission;478479 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(480 collection_id481 ));482483 target_collection.save()484 }485486 487 488 489 490 491 492 493 494 495 496 497 #[weight = <SelfWeightOf<T>>::change_collection_owner()]498 #[transactional]499 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {500501 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);502503 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;504 target_collection.check_is_owner(&sender)?;505506 target_collection.owner = new_owner.clone();507 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(508 collection_id,509 new_owner510 ));511512 target_collection.save()513 }514515 516 517 518 519 520 521 522 523 524 525 526 527 528 #[weight = <SelfWeightOf<T>>::add_collection_admin()]529 #[transactional]530 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {531 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);532 let collection = <CollectionHandle<T>>::try_get(collection_id)?;533534 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(535 collection_id,536 new_admin_id.clone()537 ));538539 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)540 }541542 543 544 545 546 547 548 549 550 551 552 553 554 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]555 #[transactional]556 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {557 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);558 let collection = <CollectionHandle<T>>::try_get(collection_id)?;559560 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(561 collection_id,562 account_id.clone()563 ));564565 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)566 }567568 569 570 571 572 573 574 575 576 577 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]578 #[transactional]579 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {580 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);581582 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;583 target_collection.check_is_owner(&sender)?;584585 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());586587 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(588 collection_id,589 new_sponsor590 ));591592 target_collection.save()593 }594595 596 597 598 599 600 601 602 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]603 #[transactional]604 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {605 let sender = ensure_signed(origin)?;606607 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;608 ensure!(609 target_collection.sponsorship.pending_sponsor() == Some(&sender),610 Error::<T>::ConfirmUnsetSponsorFail611 );612613 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());614615 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(616 collection_id,617 sender618 ));619620 target_collection.save()621 }622623 624 625 626 627 628 629 630 631 632 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]633 #[transactional]634 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {635 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);636637 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;638 target_collection.check_is_owner(&sender)?;639640 target_collection.sponsorship = SponsorshipState::Disabled;641642 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(643 collection_id644 ));645 target_collection.save()646 }647648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 #[weight = T::CommonWeightInfo::create_item()]667 #[transactional]668 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {669 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);670 let budget = budget::Value::new(2);671672 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))673 }674675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 #[weight = T::CommonWeightInfo::create_multiple_items(items_data.len() as u32)]694 #[transactional]695 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {696 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);697 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);698 let budget = budget::Value::new(2);699700 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))701 }702703 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]704 #[transactional]705 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {706 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);707 let budget = budget::Value::new(2);708709 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))710 }711712 713714 715 716 717 718 719 720 721 722 723 724 725 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]726 #[transactional]727 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {728 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);729 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;730 target_collection.check_is_owner(&sender)?;731732 733734 target_collection.limits.transfers_enabled = Some(value);735 target_collection.save()736 }737738 739 740 741 742 743 744 745 746 747 748 749 750 751 #[weight = T::CommonWeightInfo::burn_item()]752 #[transactional]753 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {754 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);755756 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;757 if value == 1 {758 <NftTransferBasket<T>>::remove(collection_id, item_id);759 <NftApproveBasket<T>>::remove(collection_id, item_id);760 }761 762 763 764 Ok(post_info)765 }766767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 #[weight = T::CommonWeightInfo::burn_from()]784 #[transactional]785 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {786 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);787 let budget = budget::Value::new(2);788789 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))790 }791792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 #[weight = T::CommonWeightInfo::transfer()]816 #[transactional]817 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {818 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);819 let budget = budget::Value::new(2);820821 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))822 }823824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 #[weight = T::CommonWeightInfo::approve()]840 #[transactional]841 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {842 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);843844 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))845 }846847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 #[weight = T::CommonWeightInfo::transfer_from()]867 #[transactional]868 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {869 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);870 let budget = budget::Value::new(2);871872 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))873 }874875 876 877 878 879 880 881 882 883 884 885 886 887 #[weight = T::CommonWeightInfo::set_variable_metadata(data.len() as u32)]888 #[transactional]889 pub fn set_variable_meta_data (890 origin,891 collection_id: CollectionId,892 item_id: TokenId,893 data: BoundedVec<u8, CustomDataLimit>,894 ) -> DispatchResultWithPostInfo {895 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);896897 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))898 }899900 901 902 903 904 905 906 907 908 909 910 911 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]912 #[transactional]913 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {914 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);915 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;916917 ensure!(918 target_collection.meta_update_permission != MetaUpdatePermission::None,919 <CommonError<T>>::MetadataFlagFrozen,920 );921 target_collection.check_is_owner(&sender)?;922923 target_collection.meta_update_permission = value;924925 target_collection.save()926 }927928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 #[weight = <SelfWeightOf<T>>::set_schema_version()]943 #[transactional]944 pub fn set_schema_version(945 origin,946 collection_id: CollectionId,947 version: SchemaVersion948 ) -> DispatchResult {949 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);950 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;951 target_collection.check_is_owner_or_admin(&sender)?;952 target_collection.schema_version = version;953954 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(955 collection_id956 ));957958 target_collection.save()959 }960961 962 963 964 965 966 967 968 969 970 971 972 973 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]974 #[transactional]975 pub fn set_offchain_schema(976 origin,977 collection_id: CollectionId,978 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,979 ) -> DispatchResult {980 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);981 let collection = <CollectionHandle<T>>::try_get(collection_id)?;982983 984985 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;986987 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(988 collection_id989 ));990 Ok(())991 }992993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1006 #[transactional]1007 pub fn set_const_on_chain_schema (1008 origin,1009 collection_id: CollectionId,1010 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1011 ) -> DispatchResult {1012 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1013 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10141015 10161017 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;10181019 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1020 collection_id1021 ));1022 Ok(())1023 }10241025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1038 #[transactional]1039 pub fn set_variable_on_chain_schema (1040 origin,1041 collection_id: CollectionId,1042 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1043 ) -> DispatchResult {1044 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1045 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10461047 10481049 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::VariableOnChainSchema, schema.into_inner())?;10501051 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1052 collection_id1053 ));1054 Ok(())1055 }10561057 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1058 #[transactional]1059 pub fn set_collection_limits(1060 origin,1061 collection_id: CollectionId,1062 new_limit: CollectionLimits,1063 ) -> DispatchResult {1064 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1065 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1066 target_collection.check_is_owner(&sender)?;1067 let old_limit = &target_collection.limits;10681069 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10701071 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1072 collection_id1073 ));10741075 target_collection.save()1076 }1077 }1078}