1234567891011121314151617#![recursion_limit = "1024"]18#![cfg_attr(not(feature = "std"), no_std)]19#![allow(20 clippy::too_many_arguments,21 clippy::unnecessary_mut_passed,22 clippy::unused_unit23)]2425extern crate alloc;2627pub use serde::{Serialize, Deserialize};2829pub use frame_support::{30 construct_runtime, decl_module, decl_storage, decl_error, decl_event,31 dispatch::DispatchResult,32 ensure, fail, parameter_types,33 traits::{34 ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness,35 IsSubType, WithdrawReasons,36 },37 weights::{38 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},39 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,40 WeightToFeePolynomial, DispatchClass,41 },42 StorageValue, transactional,43 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},44 BoundedVec,45};46use scale_info::TypeInfo;47use frame_system::{self as system, ensure_signed};48use sp_runtime::{sp_std::prelude::Vec};49use up_data_structs::{50 MAX_DECIMAL_POINTS, VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,51 OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,52 MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,53 CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,54 CreateCollectionData, CustomDataLimit, CreateItemExData,55};56use pallet_common::{CollectionHandle, Pallet as PalletCommon, Error as CommonError, CommonWeightInfo};57use pallet_evm::account::CrossAccountId;58use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};59use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};60use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};6162#[cfg(test)]63mod mock;6465#[cfg(test)]66mod tests;6768mod eth;69mod sponsorship;70pub use sponsorship::{UniqueSponsorshipHandler, UniqueSponsorshipPredict};71pub use eth::sponsoring::UniqueEthSponsorshipHandler;7273pub use eth::UniqueErcSupport;7475pub mod common;76use common::CommonWeights;77pub mod dispatch;78use dispatch::dispatch_call;7980#[cfg(feature = "runtime-benchmarks")]81mod benchmarking;82pub mod weights;83use weights::WeightInfo;8485pub trait SponsorshipPredict<T: Config> {86 fn predict(collection: CollectionId, account: T::CrossAccountId, token: TokenId) -> Option<u64>87 where88 u64: From<<T as frame_system::Config>::BlockNumber>;89}9091decl_error! {92 93 pub enum Error for Module<T: Config> {94 95 CollectionDecimalPointLimitExceeded,96 97 ConfirmUnsetSponsorFail,98 99 EmptyArgument,100 }101}102103pub trait Config:104 system::Config105 + pallet_evm_coder_substrate::Config106 + pallet_common::Config107 + pallet_nonfungible::Config108 + pallet_refungible::Config109 + pallet_fungible::Config110 + Sized111 + TypeInfo112{113 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;114115 116 type WeightInfo: WeightInfo;117}118119decl_event! {120 pub enum Event<T>121 where122 <T as frame_system::Config>::AccountId,123 <T as pallet_evm::account::Config>::CrossAccountId,124 {125 126 127 128 129 130 CollectionSponsorRemoved(CollectionId),131132 133 134 135 136 137 138 139 CollectionAdminAdded(CollectionId, CrossAccountId),140141 142 143 144 145 146 147 148 CollectionOwnedChanged(CollectionId, AccountId),149150 151 152 153 154 155 156 157 CollectionSponsorSet(CollectionId, AccountId),158159 160 161 162 163 164 ConstOnChainSchemaSet(CollectionId),165166 167 168 169 170 171 172 173 SponsorshipConfirmed(CollectionId, AccountId),174175 176 177 178 179 180 181 182 CollectionAdminRemoved(CollectionId, CrossAccountId),183184 185 186 187 188 189 190 191 AllowListAddressRemoved(CollectionId, CrossAccountId),192193 194 195 196 197 198 199 200 AllowListAddressAdded(CollectionId, CrossAccountId),201202 203 204 205 206 207 CollectionLimitSet(CollectionId),208209 210 211 212 213 214 MintPermissionSet(CollectionId),215216 217 218 219 220 221 OffchainSchemaSet(CollectionId),222223 224 225 226 227 228 229 230 PublicAccessModeSet(CollectionId, AccessMode),231232 233 234 235 236 237 SchemaVersionSet(CollectionId),238239 240 241 242 243 244 VariableOnChainSchemaSet(CollectionId),245 }246}247248type SelfWeightOf<T> = <T as Config>::WeightInfo;249250251252253254255256257258259260261262263264265266267268269270271272decl_storage! {273 trait Store for Module<T: Config> as Unique {274275 276 277 ChainVersion: u64;278 279280 281 282 283 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;284 285 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;286 287 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;288 289 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>;290 291292 293 294 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;295 296 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;297 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;298 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>;299 }300}301302decl_module! {303 pub struct Module<T: Config> for enum Call304 where305 origin: T::Origin306 {307 type Error = Error<T>;308309 fn deposit_event() = default;310311 fn on_initialize(_now: T::BlockNumber) -> Weight {312 0313 }314315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 #[weight = <SelfWeightOf<T>>::create_collection()]332 #[transactional]333 #[deprecated]334 pub fn create_collection(origin,335 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,336 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,337 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,338 mode: CollectionMode) -> DispatchResult {339 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {340 name: collection_name,341 description: collection_description,342 token_prefix,343 mode,344 ..Default::default()345 };346 Self::create_collection_ex(origin, data)347 }348349 350 351 352 #[weight = <SelfWeightOf<T>>::create_collection()]353 #[transactional]354 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {355 let owner = ensure_signed(origin)?;356357 let _id = match data.mode {358 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},359 CollectionMode::Fungible(decimal_points) => {360 361 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);362 <PalletFungible<T>>::init_collection(owner, data)?363 }364 CollectionMode::ReFungible => {365 <PalletRefungible<T>>::init_collection(owner, data)?366 }367 };368369 Ok(())370 }371372 373 374 375 376 377 378 379 380 381 #[weight = <SelfWeightOf<T>>::destroy_collection()]382 #[transactional]383 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {384 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);385386 let collection = <CollectionHandle<T>>::try_get(collection_id)?;387 collection.check_is_owner(&sender)?;388389 390391 match collection.mode {392 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,393 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,394 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,395 }396397 <NftTransferBasket<T>>::remove_prefix(collection_id, None);398 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);399 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);400401 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);402 <NftApproveBasket<T>>::remove_prefix(collection_id, None);403 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);404 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);405406 Ok(())407 }408409 410 411 412 413 414 415 416 417 418 419 420 421 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]422 #[transactional]423 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{424425 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);426 let collection = <CollectionHandle<T>>::try_get(collection_id)?;427428 <PalletCommon<T>>::toggle_allowlist(429 &collection,430 &sender,431 &address,432 true,433 )?;434435 Self::deposit_event(Event::<T>::AllowListAddressAdded(436 collection_id,437 address438 ));439440 Ok(())441 }442443 444 445 446 447 448 449 450 451 452 453 454 455 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]456 #[transactional]457 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{458459 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);460 let collection = <CollectionHandle<T>>::try_get(collection_id)?;461462 <PalletCommon<T>>::toggle_allowlist(463 &collection,464 &sender,465 &address,466 false,467 )?;468469 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(470 collection_id,471 address472 ));473474 Ok(())475 }476477 478 479 480 481 482 483 484 485 486 487 488 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]489 #[transactional]490 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult491 {492 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);493494 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;495 target_collection.check_is_owner(&sender)?;496497 target_collection.access = mode.clone();498499 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(500 collection_id,501 mode502 ));503504 target_collection.save()505 }506507 508 509 510 511 512 513 514 515 516 517 518 519 520 #[weight = <SelfWeightOf<T>>::set_mint_permission()]521 #[transactional]522 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult523 {524 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);525526 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;527 target_collection.check_is_owner(&sender)?;528529 target_collection.mint_mode = mint_permission;530531 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(532 collection_id533 ));534535 target_collection.save()536 }537538 539 540 541 542 543 544 545 546 547 548 549 #[weight = <SelfWeightOf<T>>::change_collection_owner()]550 #[transactional]551 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {552553 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);554555 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;556 target_collection.check_is_owner(&sender)?;557558 target_collection.owner = new_owner.clone();559 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(560 collection_id,561 new_owner562 ));563564 target_collection.save()565 }566567 568 569 570 571 572 573 574 575 576 577 578 579 580 #[weight = <SelfWeightOf<T>>::add_collection_admin()]581 #[transactional]582 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {583 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);584 let collection = <CollectionHandle<T>>::try_get(collection_id)?;585586 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(587 collection_id,588 new_admin_id.clone()589 ));590591 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)592 }593594 595 596 597 598 599 600 601 602 603 604 605 606 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]607 #[transactional]608 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {609 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);610 let collection = <CollectionHandle<T>>::try_get(collection_id)?;611612 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(613 collection_id,614 account_id.clone()615 ));616617 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)618 }619620 621 622 623 624 625 626 627 628 629 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]630 #[transactional]631 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {632 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);633634 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;635 target_collection.check_is_owner(&sender)?;636637 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());638639 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(640 collection_id,641 new_sponsor642 ));643644 target_collection.save()645 }646647 648 649 650 651 652 653 654 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]655 #[transactional]656 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {657 let sender = ensure_signed(origin)?;658659 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;660 ensure!(661 target_collection.sponsorship.pending_sponsor() == Some(&sender),662 Error::<T>::ConfirmUnsetSponsorFail663 );664665 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());666667 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(668 collection_id,669 sender670 ));671672 target_collection.save()673 }674675 676 677 678 679 680 681 682 683 684 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]685 #[transactional]686 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {687 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);688689 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;690 target_collection.check_is_owner(&sender)?;691692 target_collection.sponsorship = SponsorshipState::Disabled;693694 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(695 collection_id696 ));697 target_collection.save()698 }699700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 #[weight = <CommonWeights<T>>::create_item()]719 #[transactional]720 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {721 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);722723 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))724 }725726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]745 #[transactional]746 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {747 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);748 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);749750 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))751 }752753 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]754 #[transactional]755 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {756 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);757758 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))759 }760761 762763 764 765 766 767 768 769 770 771 772 773 774 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]775 #[transactional]776 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {777 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);778 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;779 target_collection.check_is_owner(&sender)?;780781 782783 target_collection.limits.transfers_enabled = Some(value);784 target_collection.save()785 }786787 788 789 790 791 792 793 794 795 796 797 798 799 800 #[weight = <CommonWeights<T>>::burn_item()]801 #[transactional]802 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {803 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);804805 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;806 if value == 1 {807 <NftTransferBasket<T>>::remove(collection_id, item_id);808 <NftApproveBasket<T>>::remove(collection_id, item_id);809 }810 811 812 813 Ok(post_info)814 }815816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 #[weight = <CommonWeights<T>>::burn_from()]833 #[transactional]834 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {835 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);836837 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))838 }839840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 #[weight = <CommonWeights<T>>::transfer()]864 #[transactional]865 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {866 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);867868 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))869 }870871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 #[weight = <CommonWeights<T>>::approve()]887 #[transactional]888 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {889 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);890891 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))892 }893894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 #[weight = <CommonWeights<T>>::transfer_from()]914 #[transactional]915 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {916 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);917918 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))919 }920921 922 923 924 925 926 927 928 929 930 931 932 933 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]934 #[transactional]935 pub fn set_variable_meta_data (936 origin,937 collection_id: CollectionId,938 item_id: TokenId,939 data: BoundedVec<u8, CustomDataLimit>,940 ) -> DispatchResultWithPostInfo {941 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);942943 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))944 }945946 947 948 949 950 951 952 953 954 955 956 957 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]958 #[transactional]959 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {960 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);961 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;962963 ensure!(964 target_collection.meta_update_permission != MetaUpdatePermission::None,965 <CommonError<T>>::MetadataFlagFrozen,966 );967 target_collection.check_is_owner(&sender)?;968969 target_collection.meta_update_permission = value;970971 target_collection.save()972 }973974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 #[weight = <SelfWeightOf<T>>::set_schema_version()]989 #[transactional]990 pub fn set_schema_version(991 origin,992 collection_id: CollectionId,993 version: SchemaVersion994 ) -> DispatchResult {995 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);996 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;997 target_collection.check_is_owner_or_admin(&sender)?;998 target_collection.schema_version = version;9991000 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(1001 collection_id1002 ));10031004 target_collection.save()1005 }10061007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1020 #[transactional]1021 pub fn set_offchain_schema(1022 origin,1023 collection_id: CollectionId,1024 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1025 ) -> DispatchResult {1026 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1027 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1028 target_collection.check_is_owner_or_admin(&sender)?;10291030 target_collection.offchain_schema = schema;10311032 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1033 collection_id1034 ));10351036 target_collection.save()1037 }10381039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1052 #[transactional]1053 pub fn set_const_on_chain_schema (1054 origin,1055 collection_id: CollectionId,1056 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1057 ) -> DispatchResult {1058 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1059 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1060 target_collection.check_is_owner_or_admin(&sender)?;10611062 target_collection.const_on_chain_schema = schema;10631064 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1065 collection_id1066 ));10671068 target_collection.save()1069 }10701071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1084 #[transactional]1085 pub fn set_variable_on_chain_schema (1086 origin,1087 collection_id: CollectionId,1088 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1089 ) -> DispatchResult {1090 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1091 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1092 target_collection.check_is_owner_or_admin(&sender)?;10931094 target_collection.variable_on_chain_schema = schema;10951096 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1097 collection_id1098 ));10991100 target_collection.save()1101 }11021103 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1104 #[transactional]1105 pub fn set_collection_limits(1106 origin,1107 collection_id: CollectionId,1108 new_limit: CollectionLimits,1109 ) -> DispatchResult {1110 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1111 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1112 target_collection.check_is_owner(&sender)?;1113 let old_limit = &target_collection.limits;11141115 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11161117 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1118 collection_id1119 ));11201121 target_collection.save()1122 }1123 }1124}