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, CustomDataLimit,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 243 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;244 245 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;246 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;247 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>;248 }249}250251decl_module! {252 pub struct Module<T: Config> for enum Call253 where254 origin: T::Origin255 {256 type Error = Error<T>;257258 fn deposit_event() = default;259260 fn on_initialize(_now: T::BlockNumber) -> Weight {261 0262 }263264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 #[weight = <SelfWeightOf<T>>::create_collection()]281 #[transactional]282 #[deprecated]283 pub fn create_collection(origin,284 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,285 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,286 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,287 mode: CollectionMode) -> DispatchResult {288 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {289 name: collection_name,290 description: collection_description,291 token_prefix,292 mode,293 ..Default::default()294 };295 Self::create_collection_ex(origin, data)296 }297298 299 300 301 #[weight = <SelfWeightOf<T>>::create_collection()]302 #[transactional]303 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {304 let sender = ensure_signed(origin)?;305306 307308 T::CollectionDispatch::create(sender, data)?;309310 Ok(())311 }312313 314 315 316 317 318 319 320 321 322 #[weight = <SelfWeightOf<T>>::destroy_collection()]323 #[transactional]324 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {325 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);326 let collection = <CollectionHandle<T>>::try_get(collection_id)?;327328 329330 T::CollectionDispatch::destroy(sender, collection)?;331332 <NftTransferBasket<T>>::remove_prefix(collection_id, None);333 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);334 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);335336 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);337 <NftApproveBasket<T>>::remove_prefix(collection_id, None);338 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);339 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);340341 Ok(())342 }343344 345 346 347 348 349 350 351 352 353 354 355 356 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]357 #[transactional]358 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{359360 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);361 let collection = <CollectionHandle<T>>::try_get(collection_id)?;362363 <PalletCommon<T>>::toggle_allowlist(364 &collection,365 &sender,366 &address,367 true,368 )?;369370 Self::deposit_event(Event::<T>::AllowListAddressAdded(371 collection_id,372 address373 ));374375 Ok(())376 }377378 379 380 381 382 383 384 385 386 387 388 389 390 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]391 #[transactional]392 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{393394 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);395 let collection = <CollectionHandle<T>>::try_get(collection_id)?;396397 <PalletCommon<T>>::toggle_allowlist(398 &collection,399 &sender,400 &address,401 false,402 )?;403404 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(405 collection_id,406 address407 ));408409 Ok(())410 }411412 413 414 415 416 417 418 419 420 421 422 423 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]424 #[transactional]425 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult426 {427 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);428429 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;430 target_collection.check_is_owner(&sender)?;431432 target_collection.access = mode.clone();433434 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(435 collection_id,436 mode437 ));438439 target_collection.save()440 }441442 443 444 445 446 447 448 449 450 451 452 453 454 455 #[weight = <SelfWeightOf<T>>::set_mint_permission()]456 #[transactional]457 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult458 {459 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);460461 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;462 target_collection.check_is_owner(&sender)?;463464 target_collection.mint_mode = mint_permission;465466 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(467 collection_id468 ));469470 target_collection.save()471 }472473 474 475 476 477 478 479 480 481 482 483 484 #[weight = <SelfWeightOf<T>>::change_collection_owner()]485 #[transactional]486 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {487488 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);489490 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;491 target_collection.check_is_owner(&sender)?;492493 target_collection.owner = new_owner.clone();494 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(495 collection_id,496 new_owner497 ));498499 target_collection.save()500 }501502 503 504 505 506 507 508 509 510 511 512 513 514 515 #[weight = <SelfWeightOf<T>>::add_collection_admin()]516 #[transactional]517 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {518 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);519 let collection = <CollectionHandle<T>>::try_get(collection_id)?;520521 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(522 collection_id,523 new_admin_id.clone()524 ));525526 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)527 }528529 530 531 532 533 534 535 536 537 538 539 540 541 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]542 #[transactional]543 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {544 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);545 let collection = <CollectionHandle<T>>::try_get(collection_id)?;546547 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(548 collection_id,549 account_id.clone()550 ));551552 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)553 }554555 556 557 558 559 560 561 562 563 564 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]565 #[transactional]566 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {567 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);568569 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;570 target_collection.check_is_owner(&sender)?;571572 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());573574 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(575 collection_id,576 new_sponsor577 ));578579 target_collection.save()580 }581582 583 584 585 586 587 588 589 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]590 #[transactional]591 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {592 let sender = ensure_signed(origin)?;593594 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;595 ensure!(596 target_collection.sponsorship.pending_sponsor() == Some(&sender),597 Error::<T>::ConfirmUnsetSponsorFail598 );599600 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());601602 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(603 collection_id,604 sender605 ));606607 target_collection.save()608 }609610 611 612 613 614 615 616 617 618 619 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]620 #[transactional]621 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {622 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);623624 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;625 target_collection.check_is_owner(&sender)?;626627 target_collection.sponsorship = SponsorshipState::Disabled;628629 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(630 collection_id631 ));632 target_collection.save()633 }634635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 #[weight = T::CommonWeightInfo::create_item()]654 #[transactional]655 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {656 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);657 let budget = budget::Value::new(2);658659 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))660 }661662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 #[weight = T::CommonWeightInfo::create_multiple_items(items_data.len() as u32)]681 #[transactional]682 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {683 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);684 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);685 let budget = budget::Value::new(2);686687 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))688 }689690 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]691 #[transactional]692 pub fn set_collection_properties(693 origin,694 collection_id: CollectionId,695 properties: Vec<Property>696 ) -> DispatchResultWithPostInfo {697 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);698699 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);700701 dispatch_call::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))702 }703704 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]705 #[transactional]706 pub fn delete_collection_properties(707 origin,708 collection_id: CollectionId,709 property_keys: Vec<PropertyKey>,710 ) -> DispatchResultWithPostInfo {711 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);712713 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);714715 dispatch_call::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))716 }717718 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]719 #[transactional]720 pub fn set_token_properties(721 origin,722 collection_id: CollectionId,723 token_id: TokenId,724 properties: Vec<Property>725 ) -> DispatchResultWithPostInfo {726 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);727728 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);729730 dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))731 }732733 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]734 #[transactional]735 pub fn delete_token_properties(736 origin,737 collection_id: CollectionId,738 token_id: TokenId,739 property_keys: Vec<PropertyKey>740 ) -> DispatchResultWithPostInfo {741 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);742743 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);744745 dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))746 }747748 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]749 #[transactional]750 pub fn set_property_permissions(751 origin,752 collection_id: CollectionId,753 property_permissions: Vec<PropertyKeyPermission>,754 ) -> DispatchResultWithPostInfo {755 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);756757 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);758759 dispatch_call::<T, _>(collection_id, |d| d.set_property_permissions(&sender, property_permissions))760 }761762 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]763 #[transactional]764 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {765 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);766 let budget = budget::Value::new(2);767768 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))769 }770771 772773 774 775 776 777 778 779 780 781 782 783 784 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]785 #[transactional]786 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {787 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);788 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;789 target_collection.check_is_owner(&sender)?;790791 792793 target_collection.limits.transfers_enabled = Some(value);794 target_collection.save()795 }796797 798 799 800 801 802 803 804 805 806 807 808 809 810 #[weight = T::CommonWeightInfo::burn_item()]811 #[transactional]812 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {813 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);814815 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;816 if value == 1 {817 <NftTransferBasket<T>>::remove(collection_id, item_id);818 <NftApproveBasket<T>>::remove(collection_id, item_id);819 }820 821 822 823 Ok(post_info)824 }825826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 #[weight = T::CommonWeightInfo::burn_from()]843 #[transactional]844 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {845 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);846 let budget = budget::Value::new(2);847848 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))849 }850851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 #[weight = T::CommonWeightInfo::transfer()]875 #[transactional]876 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {877 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);878 let budget = budget::Value::new(2);879880 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))881 }882883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 #[weight = T::CommonWeightInfo::approve()]899 #[transactional]900 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {901 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);902903 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))904 }905906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 #[weight = T::CommonWeightInfo::transfer_from()]926 #[transactional]927 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {928 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);929 let budget = budget::Value::new(2);930931 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))932 }933934 935 936 937 938 939 940 941 942 943 944 945 946 #[weight = T::CommonWeightInfo::set_variable_metadata(data.len() as u32)]947 #[transactional]948 pub fn set_variable_meta_data (949 origin,950 collection_id: CollectionId,951 item_id: TokenId,952 data: BoundedVec<u8, CustomDataLimit>,953 ) -> DispatchResultWithPostInfo {954 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);955956 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))957 }958959 960 961 962 963 964 965 966 967 968 969 970 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]971 #[transactional]972 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {973 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);974 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;975976 ensure!(977 target_collection.meta_update_permission != MetaUpdatePermission::None,978 <CommonError<T>>::MetadataFlagFrozen,979 );980 target_collection.check_is_owner(&sender)?;981982 target_collection.meta_update_permission = value;983984 target_collection.save()985 }986987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 #[weight = <SelfWeightOf<T>>::set_schema_version()]1002 #[transactional]1003 pub fn set_schema_version(1004 origin,1005 collection_id: CollectionId,1006 version: SchemaVersion1007 ) -> DispatchResult {1008 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1009 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1010 target_collection.check_is_owner_or_admin(&sender)?;1011 target_collection.schema_version = version;10121013 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(1014 collection_id1015 ));10161017 target_collection.save()1018 }10191020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1033 #[transactional]1034 pub fn set_offchain_schema(1035 origin,1036 collection_id: CollectionId,1037 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1038 ) -> DispatchResult {1039 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1040 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10411042 10431044 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::OffchainSchema, schema.into_inner())?;10451046 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1047 collection_id1048 ));1049 Ok(())1050 }10511052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1065 #[transactional]1066 pub fn set_const_on_chain_schema (1067 origin,1068 collection_id: CollectionId,1069 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1070 ) -> DispatchResult {1071 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1072 let collection = <CollectionHandle<T>>::try_get(collection_id)?;10731074 10751076 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::ConstOnChainSchema, schema.into_inner())?;10771078 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1079 collection_id1080 ));1081 Ok(())1082 }10831084 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1085 #[transactional]1086 pub fn set_collection_limits(1087 origin,1088 collection_id: CollectionId,1089 new_limit: CollectionLimits,1090 ) -> DispatchResult {1091 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1092 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1093 target_collection.check_is_owner(&sender)?;1094 let old_limit = &target_collection.limits;10951096 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;10971098 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1099 collection_id1100 ));11011102 target_collection.save()1103 }1104 }1105}