1234567891011121314151617use core::marker::PhantomData;1819use frame_support::weights::Weight;20use pallet_balances_adapter::{21 common::CommonWeights as NativeFungibleWeights, Config as NativeFungibleConfig,22};23use pallet_common::{dispatch::dispatch_weight, CommonWeightInfo, RefungibleExtensionsWeightInfo};24use pallet_fungible::{common::CommonWeights as FungibleWeights, Config as FungibleConfig};25use pallet_nonfungible::{26 common::CommonWeights as NonfungibleWeights, Config as NonfungibleConfig,27};28#[cfg(feature = "refungible")]29use pallet_refungible::{30 common::CommonWeights as RefungibleWeights, weights::WeightInfo, Config as RefungibleConfig,31};32use up_data_structs::{CreateItemData, CreateItemExData};3334pub mod xcm;3536macro_rules! max_weight_of {37 ($method:ident ( $($args:tt)* )) => {{38 let max_weight = <FungibleWeights<T>>::$method($($args)*)39 .max(<NativeFungibleWeights<T>>::$method($($args)*))40 .max(<NonfungibleWeights<T>>::$method($($args)*));4142 #[cfg(feature = "refungible")]43 let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));4445 max_weight46 }};47}4849#[cfg(not(feature = "refungible"))]50pub trait CommonWeightConfigs: FungibleConfig + NativeFungibleConfig + NonfungibleConfig {}5152#[cfg(not(feature = "refungible"))]53impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}5455#[cfg(feature = "refungible")]56pub trait CommonWeightConfigs:57 FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig58{59}6061#[cfg(feature = "refungible")]62impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig>63 CommonWeightConfigs for T64{65}6667pub struct CommonWeights<T>(PhantomData<T>);6869impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>70where71 T: CommonWeightConfigs,72{73 fn create_item(data: &CreateItemData) -> Weight {74 dispatch_weight::<T>() + max_weight_of!(create_item(data))75 }7677 fn create_multiple_items(data: &[CreateItemData]) -> Weight {78 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))79 }8081 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {82 dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))83 }8485 fn burn_item() -> Weight {86 dispatch_weight::<T>() + max_weight_of!(burn_item())87 }8889 fn set_collection_properties(amount: u32) -> Weight {90 dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))91 }9293 fn delete_collection_properties(amount: u32) -> Weight {94 dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))95 }9697 fn set_token_properties(amount: u32) -> Weight {98 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))99 }100101 fn delete_token_properties(amount: u32) -> Weight {102 dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))103 }104105 fn set_token_property_permissions(amount: u32) -> Weight {106 dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))107 }108109 fn transfer() -> Weight {110 dispatch_weight::<T>() + max_weight_of!(transfer())111 }112113 fn approve() -> Weight {114 dispatch_weight::<T>() + max_weight_of!(approve())115 }116117 fn approve_from() -> Weight {118 dispatch_weight::<T>() + max_weight_of!(approve_from())119 }120121 fn transfer_from() -> Weight {122 dispatch_weight::<T>() + max_weight_of!(transfer_from())123 }124125 fn burn_from() -> Weight {126 dispatch_weight::<T>() + max_weight_of!(burn_from())127 }128129 fn burn_recursively_self_raw() -> Weight {130 max_weight_of!(burn_recursively_self_raw())131 }132133 fn burn_recursively_breadth_raw(amount: u32) -> Weight {134 max_weight_of!(burn_recursively_breadth_raw(amount))135 }136137 fn token_owner() -> Weight {138 max_weight_of!(token_owner())139 }140141 fn set_allowance_for_all() -> Weight {142 max_weight_of!(set_allowance_for_all())143 }144145 fn force_repair_item() -> Weight {146 max_weight_of!(force_repair_item())147 }148}149150#[cfg(feature = "refungible")]151impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>152where153 T: FungibleConfig + NonfungibleConfig + RefungibleConfig,154{155 fn repartition() -> Weight {156 dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()157 }158}159160#[cfg(not(feature = "refungible"))]161impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>162where163 T: FungibleConfig + NonfungibleConfig,164{165 fn repartition() -> Weight {166 dispatch_weight::<T>()167 }168}