git.delta.rocks / unique-network / refs/commits / ed0719fab73d

difftreelog

source

runtime/common/weights/mod.rs4.6 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use 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 set_token_property_permissions(amount: u32) -> Weight {102		dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))103	}104105	fn transfer() -> Weight {106		dispatch_weight::<T>() + max_weight_of!(transfer())107	}108109	fn approve() -> Weight {110		dispatch_weight::<T>() + max_weight_of!(approve())111	}112113	fn approve_from() -> Weight {114		dispatch_weight::<T>() + max_weight_of!(approve_from())115	}116117	fn transfer_from() -> Weight {118		dispatch_weight::<T>() + max_weight_of!(transfer_from())119	}120121	fn burn_from() -> Weight {122		dispatch_weight::<T>() + max_weight_of!(burn_from())123	}124125	fn set_allowance_for_all() -> Weight {126		dispatch_weight::<T>() + max_weight_of!(set_allowance_for_all())127	}128129	fn force_repair_item() -> Weight {130		dispatch_weight::<T>() + max_weight_of!(force_repair_item())131	}132}133134#[cfg(feature = "refungible")]135impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>136where137	T: FungibleConfig + NonfungibleConfig + RefungibleConfig,138{139	fn repartition() -> Weight {140		dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()141	}142}143144#[cfg(not(feature = "refungible"))]145impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>146where147	T: FungibleConfig + NonfungibleConfig,148{149	fn repartition() -> Weight {150		dispatch_weight::<T>()151	}152}