1234567891011121314151617use core::marker::PhantomData;18use frame_support::{weights::Weight};19use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};2021use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};22use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};2324#[cfg(feature = "refungible")]25use pallet_refungible::{26 Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,27};28use up_data_structs::{CreateItemExData, CreateItemData};2930pub mod xcm;3132macro_rules! max_weight_of {33 ($method:ident ( $($args:tt)* )) => {{34 let max_weight = <FungibleWeights<T>>::$method($($args)*)35 .max(<NonfungibleWeights<T>>::$method($($args)*));3637 #[cfg(feature = "refungible")]38 let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));3940 max_weight41 }};42}4344#[cfg(not(feature = "refungible"))]45pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}4647#[cfg(not(feature = "refungible"))]48impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}4950#[cfg(feature = "refungible")]51pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}5253#[cfg(feature = "refungible")]54impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}5556pub struct CommonWeights<T>(PhantomData<T>);5758impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>59where60 T: CommonWeightConfigs,61{62 fn create_item(data: &CreateItemData) -> Weight {63 dispatch_weight::<T>() + max_weight_of!(create_item(data))64 }6566 fn create_multiple_items(data: &[CreateItemData]) -> Weight {67 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))68 }6970 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {71 dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))72 }7374 fn burn_item() -> Weight {75 dispatch_weight::<T>() + max_weight_of!(burn_item())76 }7778 fn set_collection_properties(amount: u32) -> Weight {79 dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))80 }8182 fn delete_collection_properties(amount: u32) -> Weight {83 dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))84 }8586 fn set_token_properties(amount: u32) -> Weight {87 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))88 }8990 fn delete_token_properties(amount: u32) -> Weight {91 dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))92 }9394 fn set_token_property_permissions(amount: u32) -> Weight {95 dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))96 }9798 fn transfer() -> Weight {99 dispatch_weight::<T>() + max_weight_of!(transfer())100 }101102 fn approve() -> Weight {103 dispatch_weight::<T>() + max_weight_of!(approve())104 }105106 fn approve_from() -> Weight {107 dispatch_weight::<T>() + max_weight_of!(approve_from())108 }109110 fn transfer_from() -> Weight {111 dispatch_weight::<T>() + max_weight_of!(transfer_from())112 }113114 fn burn_from() -> Weight {115 dispatch_weight::<T>() + max_weight_of!(burn_from())116 }117118 fn burn_recursively_self_raw() -> Weight {119 max_weight_of!(burn_recursively_self_raw())120 }121122 fn burn_recursively_breadth_raw(amount: u32) -> Weight {123 max_weight_of!(burn_recursively_breadth_raw(amount))124 }125126 fn token_owner() -> Weight {127 max_weight_of!(token_owner())128 }129130 fn set_allowance_for_all() -> Weight {131 max_weight_of!(set_allowance_for_all())132 }133134 fn force_repair_item() -> Weight {135 max_weight_of!(force_repair_item())136 }137}138139#[cfg(feature = "refungible")]140impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>141where142 T: FungibleConfig + NonfungibleConfig + RefungibleConfig,143{144 fn repartition() -> Weight {145 dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()146 }147}148149#[cfg(not(feature = "refungible"))]150impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>151where152 T: FungibleConfig + NonfungibleConfig,153{154 fn repartition() -> Weight {155 dispatch_weight::<T>()156 }157}