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;2627use frame_support::{28 decl_module, decl_storage, decl_error, decl_event,29 dispatch::DispatchResult,30 ensure, fail,31 weights::{Weight},32 transactional,33 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},34 BoundedVec,35};36use scale_info::TypeInfo;37use frame_system::{self as system, ensure_signed};38use sp_runtime::{sp_std::prelude::Vec};39use up_data_structs::{40 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,41 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,42 SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,43 PropertyKeyPermission,44};45use pallet_evm::account::CrossAccountId;46use pallet_common::{47 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,48 dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,49};50pub mod eth;5152#[cfg(feature = "runtime-benchmarks")]53mod benchmarking;54pub mod weights;55use weights::WeightInfo;5657const NESTING_BUDGET: u32 = 5;5859decl_error! {60 61 pub enum Error for Module<T: Config> {62 63 CollectionDecimalPointLimitExceeded,64 65 ConfirmUnsetSponsorFail,66 67 EmptyArgument,68 69 RepartitionCalledOnNonRefungibleCollection,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 type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;80}8182decl_event! {83 pub enum Event<T>84 where85 <T as frame_system::Config>::AccountId,86 <T as pallet_evm::account::Config>::CrossAccountId,87 {88 89 90 91 92 93 CollectionSponsorRemoved(CollectionId),9495 96 97 98 99 100 101 102 CollectionAdminAdded(CollectionId, CrossAccountId),103104 105 106 107 108 109 110 111 CollectionOwnedChanged(CollectionId, AccountId),112113 114 115 116 117 118 119 120 CollectionSponsorSet(CollectionId, AccountId),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 CollectionPermissionSet(CollectionId),171 }172}173174type SelfWeightOf<T> = <T as Config>::WeightInfo;175176177178179180181182183184185186187188189190191192193194195196197198decl_storage! {199 trait Store for Module<T: Config> as Unique {200201 202 203 ChainVersion: u64;204 205206 207 208 209 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;210 211 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;212 213 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;214 215 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>;216 217218 219 220 #[deprecated]221 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;222 223 pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;224225 226 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;227 228 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;229 230 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>;231 }232}233234decl_module! {235 pub struct Module<T: Config> for enum Call236 where237 origin: T::Origin238 {239 type Error = Error<T>;240241 fn deposit_event() = default;242243 fn on_initialize(_now: T::BlockNumber) -> Weight {244 0245 }246247 fn on_runtime_upgrade() -> Weight {248 let limit = None;249250 <VariableMetaDataBasket<T>>::remove_all(limit);251252 0253 }254255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 #[weight = <SelfWeightOf<T>>::create_collection()]272 #[transactional]273 #[deprecated]274 pub fn create_collection(origin,275 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,276 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,277 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,278 mode: CollectionMode) -> DispatchResult {279 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {280 name: collection_name,281 description: collection_description,282 token_prefix,283 mode,284 ..Default::default()285 };286 Self::create_collection_ex(origin, data)287 }288289 290 291 292 293 294 295 296 297 298 299 #[weight = <SelfWeightOf<T>>::create_collection()]300 #[transactional]301 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {302 let sender = ensure_signed(origin)?;303304 305306 T::CollectionDispatch::create(T::CrossAccountId::from_sub(sender), data)?;307308 Ok(())309 }310311 312 313 314 315 316 317 318 319 320 #[weight = <SelfWeightOf<T>>::destroy_collection()]321 #[transactional]322 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {323 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);324 let collection = <CollectionHandle<T>>::try_get(collection_id)?;325 collection.check_is_internal()?;326327 328329 T::CollectionDispatch::destroy(sender, collection)?;330331 <NftTransferBasket<T>>::remove_prefix(collection_id, None);332 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);333 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);334335 <NftApproveBasket<T>>::remove_prefix(collection_id, None);336 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);337 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);338339 Ok(())340 }341342 343 344 345 346 347 348 349 350 351 352 353 354 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]355 #[transactional]356 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{357358 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);359 let collection = <CollectionHandle<T>>::try_get(collection_id)?;360 collection.check_is_internal()?;361362 <PalletCommon<T>>::toggle_allowlist(363 &collection,364 &sender,365 &address,366 true,367 )?;368369 Self::deposit_event(Event::<T>::AllowListAddressAdded(370 collection_id,371 address372 ));373374 Ok(())375 }376377 378 379 380 381 382 383 384 385 386 387 388 389 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]390 #[transactional]391 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{392393 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);394 let collection = <CollectionHandle<T>>::try_get(collection_id)?;395 collection.check_is_internal()?;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>>::change_collection_owner()]424 #[transactional]425 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {426427 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_internal()?;431 target_collection.check_is_owner(&sender)?;432433 target_collection.owner = new_owner.clone();434 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(435 collection_id,436 new_owner437 ));438439 target_collection.save()440 }441442 443 444 445 446 447 448 449 450 451 452 453 454 455 #[weight = <SelfWeightOf<T>>::add_collection_admin()]456 #[transactional]457 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin: T::CrossAccountId) -> DispatchResult {458 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);459 let collection = <CollectionHandle<T>>::try_get(collection_id)?;460 collection.check_is_internal()?;461462 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(463 collection_id,464 new_admin.clone()465 ));466467 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin, true)468 }469470 471 472 473 474 475 476 477 478 479 480 481 482 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]483 #[transactional]484 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {485 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);486 let collection = <CollectionHandle<T>>::try_get(collection_id)?;487 collection.check_is_internal()?;488489 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(490 collection_id,491 account_id.clone()492 ));493494 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)495 }496497 498 499 500 501 502 503 504 505 506 507 508 509 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]510 #[transactional]511 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {512 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);513514 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;515 target_collection.check_is_owner_or_admin(&sender)?;516 target_collection.check_is_internal()?;517518 target_collection.set_sponsor(new_sponsor.clone())?;519520 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(521 collection_id,522 new_sponsor523 ));524525 target_collection.save()526 }527528 529 530 531 532 533 534 535 536 537 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]538 #[transactional]539 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {540 let sender = ensure_signed(origin)?;541542 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;543 target_collection.check_is_internal()?;544 ensure!(545 target_collection.confirm_sponsorship(&sender)?,546 Error::<T>::ConfirmUnsetSponsorFail547 );548549 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(550 collection_id,551 sender552 ));553554 target_collection.save()555 }556557 558 559 560 561 562 563 564 565 566 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]567 #[transactional]568 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {569 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);570571 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;572 target_collection.check_is_internal()?;573 target_collection.check_is_owner(&sender)?;574575 target_collection.sponsorship = SponsorshipState::Disabled;576577 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(578 collection_id579 ));580 target_collection.save()581 }582583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 #[weight = T::CommonWeightInfo::create_item()]602 #[transactional]603 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {604 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);605 let budget = budget::Value::new(NESTING_BUDGET);606607 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))608 }609610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]629 #[transactional]630 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {631 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);632 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);633 let budget = budget::Value::new(NESTING_BUDGET);634635 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))636 }637638 639 640 641 642 643 644 645 646 647 648 649 650 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]651 #[transactional]652 pub fn set_collection_properties(653 origin,654 collection_id: CollectionId,655 properties: Vec<Property>656 ) -> DispatchResultWithPostInfo {657 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);658659 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);660661 dispatch_tx::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))662 }663664 665 666 667 668 669 670 671 672 673 674 675 676 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]677 #[transactional]678 pub fn delete_collection_properties(679 origin,680 collection_id: CollectionId,681 property_keys: Vec<PropertyKey>,682 ) -> DispatchResultWithPostInfo {683 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);684685 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);686687 dispatch_tx::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))688 }689690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]707 #[transactional]708 pub fn set_token_properties(709 origin,710 collection_id: CollectionId,711 token_id: TokenId,712 properties: Vec<Property>713 ) -> DispatchResultWithPostInfo {714 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);715716 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);717 let budget = budget::Value::new(NESTING_BUDGET);718719 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties, &budget))720 }721722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]739 #[transactional]740 pub fn delete_token_properties(741 origin,742 collection_id: CollectionId,743 token_id: TokenId,744 property_keys: Vec<PropertyKey>745 ) -> DispatchResultWithPostInfo {746 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);747748 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);749 let budget = budget::Value::new(NESTING_BUDGET);750751 dispatch_tx::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys, &budget))752 }753754 755 756 757 758 759 760 761 762 763 764 765 766 #[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)]767 #[transactional]768 pub fn set_token_property_permissions(769 origin,770 collection_id: CollectionId,771 property_permissions: Vec<PropertyKeyPermission>,772 ) -> DispatchResultWithPostInfo {773 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);774775 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);776777 dispatch_tx::<T, _>(collection_id, |d| d.set_token_property_permissions(&sender, property_permissions))778 }779780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]797 #[transactional]798 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {799 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);800 let budget = budget::Value::new(NESTING_BUDGET);801802 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))803 }804805 806 807 808 809 810 811 812 813 814 815 816 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]817 #[transactional]818 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {819 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);820 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;821 target_collection.check_is_internal()?;822 target_collection.check_is_owner(&sender)?;823824 825826 target_collection.limits.transfers_enabled = Some(value);827 target_collection.save()828 }829830 831 832 833 834 835 836 837 838 839 840 841 842 843 #[weight = T::CommonWeightInfo::burn_item()]844 #[transactional]845 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {846 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);847848 let post_info = dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;849 if value == 1 {850 <NftTransferBasket<T>>::remove(collection_id, item_id);851 <NftApproveBasket<T>>::remove(collection_id, item_id);852 }853 854 855 856 Ok(post_info)857 }858859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 #[weight = T::CommonWeightInfo::burn_from()]876 #[transactional]877 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {878 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);879 let budget = budget::Value::new(NESTING_BUDGET);880881 dispatch_tx::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))882 }883884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 #[weight = T::CommonWeightInfo::transfer()]908 #[transactional]909 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {910 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);911 let budget = budget::Value::new(NESTING_BUDGET);912913 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))914 }915916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 #[weight = T::CommonWeightInfo::approve()]932 #[transactional]933 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {934 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);935936 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))937 }938939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 #[weight = T::CommonWeightInfo::transfer_from()]960 #[transactional]961 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {962 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);963 let budget = budget::Value::new(NESTING_BUDGET);964965 dispatch_tx::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))966 }967968 969 970 971 972 973 974 975 976 977 978 979 980 #[weight = <SelfWeightOf<T>>::set_collection_limits()]981 #[transactional]982 pub fn set_collection_limits(983 origin,984 collection_id: CollectionId,985 new_limit: CollectionLimits,986 ) -> DispatchResult {987 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);988 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;989 target_collection.check_is_internal()?;990 target_collection.check_is_owner_or_admin(&sender)?;991 let old_limit = &target_collection.limits;992993 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;994995 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(996 collection_id997 ));998999 target_collection.save()1000 }10011002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1015 #[transactional]1016 pub fn set_collection_permissions(1017 origin,1018 collection_id: CollectionId,1019 new_permission: CollectionPermissions,1020 ) -> DispatchResult {1021 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1022 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1023 target_collection.check_is_internal()?;1024 target_collection.check_is_owner_or_admin(&sender)?;1025 let old_limit = &target_collection.permissions;10261027 target_collection.permissions = <PalletCommon<T>>::clamp_permissions(target_collection.mode.clone(), &old_limit, new_permission)?;10281029 <Pallet<T>>::deposit_event(Event::<T>::CollectionPermissionSet(1030 collection_id1031 ));10321033 target_collection.save()1034 }10351036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 #[weight = T::RefungibleExtensionsWeightInfo::repartition()]1050 #[transactional]1051 pub fn repartition(1052 origin,1053 collection_id: CollectionId,1054 token: TokenId,1055 amount: u128,1056 ) -> DispatchResultWithPostInfo {1057 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1058 dispatch_tx::<T, _>(collection_id, |d| {1059 if let Some(refungible_extensions) = d.refungible_extensions() {1060 refungible_extensions.repartition(&sender, token, amount)1061 } else {1062 fail!(<Error<T>>::RepartitionCalledOnNonRefungibleCollection)1063 }1064 })1065 }1066 }1067}