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};23use pallet_refungible::{24 Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,25};26use up_data_structs::{CreateItemExData, CreateItemData};2728macro_rules! max_weight_of {29 ($method:ident ( $($args:tt)* )) => {{30 let max_weight = <FungibleWeights<T>>::$method($($args)*)31 .max(<NonfungibleWeights<T>>::$method($($args)*));3233 #[cfg(feature = "refungible")]34 let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));3536 max_weight37 }};38}3940#[cfg(not(feature = "refungible"))]41pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}4243#[cfg(not(feature = "refungible"))]44impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}4546#[cfg(feature = "refungible")]47pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}4849#[cfg(feature = "refungible")]50impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}515253pub struct CommonWeights<T>(PhantomData<T>);5455impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>56where57 T: CommonWeightConfigs,58{59 fn create_item() -> Weight {60 dispatch_weight::<T>() + max_weight_of!(create_item())61 }6263 fn create_multiple_items(data: &[CreateItemData]) -> Weight {64 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))65 }6667 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {68 dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))69 }7071 fn burn_item() -> Weight {72 dispatch_weight::<T>() + max_weight_of!(burn_item())73 }7475 fn set_collection_properties(amount: u32) -> Weight {76 dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))77 }7879 fn delete_collection_properties(amount: u32) -> Weight {80 dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))81 }8283 fn set_token_properties(amount: u32) -> Weight {84 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))85 }8687 fn delete_token_properties(amount: u32) -> Weight {88 dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))89 }9091 fn set_token_property_permissions(amount: u32) -> Weight {92 dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))93 }9495 fn transfer() -> Weight {96 dispatch_weight::<T>() + max_weight_of!(transfer())97 }9899 fn approve() -> Weight {100 dispatch_weight::<T>() + max_weight_of!(approve())101 }102103 fn transfer_from() -> Weight {104 dispatch_weight::<T>() + max_weight_of!(transfer_from())105 }106107 fn burn_from() -> Weight {108 dispatch_weight::<T>() + max_weight_of!(burn_from())109 }110111 fn burn_recursively_self_raw() -> Weight {112 max_weight_of!(burn_recursively_self_raw())113 }114115 fn burn_recursively_breadth_raw(amount: u32) -> Weight {116 max_weight_of!(burn_recursively_breadth_raw(amount))117 }118}119120#[cfg(feature = "refungible")]121impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>122where123 T: FungibleConfig + NonfungibleConfig + RefungibleConfig,124{125 fn repartition() -> Weight {126 dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()127 }128}129130#[cfg(not(feature = "refungible"))]131impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>132where133 T: FungibleConfig + NonfungibleConfig,134{135 fn repartition() -> Weight {136 dispatch_weight::<T>()137 }138}