git.delta.rocks / unique-network / refs/commits / 278a2699c682

difftreelog

style cargo fmt

Fahrrader2022-06-08parent: #2050a76.patch.diff
in: master

1 file changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
before · pallets/common/src/dispatch.rs
1use frame_support::{2	dispatch::{3		DispatchResultWithPostInfo, PostDispatchInfo, Weight, DispatchErrorWithPostInfo,4		DispatchResult,5	},6	weights::Pays,7	traits::Get,8};9use up_data_structs::{CollectionId, CreateCollectionData};1011use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};1213// TODO: move to benchmarking14/// Price of [`dispatch_call`] call with noop `call` argument15pub fn dispatch_weight<T: Config>() -> Weight {16	// Read collection17	<T as frame_system::Config>::DbWeight::get().reads(1)18	// Dynamic dispatch?19	+ 6_000_00020	// submit_logs is measured as part of collection pallets21}2223/// Helper function to implement substrate calls for common collection methods24pub fn dispatch_call<25	T: Config,26	C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,27>(28	collection: CollectionId,29	call: C,30) -> DispatchResultWithPostInfo {31	let handle =32		CollectionHandle::try_get(collection).map_err(|error| DispatchErrorWithPostInfo {33			post_info: PostDispatchInfo {34				actual_weight: Some(dispatch_weight::<T>()),35				pays_fee: Pays::Yes,36			},37			error,38		})?;39	handle.check_is_internal().map_err(|error| DispatchErrorWithPostInfo {40		post_info: PostDispatchInfo {41			actual_weight: Some(dispatch_weight::<T>()),42			pays_fee: Pays::Yes,43		},44		error,45	})?;46	let dispatched = T::CollectionDispatch::dispatch(handle);47	let mut result = call(dispatched.as_dyn());48	match &mut result {49		Ok(PostDispatchInfo {50			actual_weight: Some(weight),51			..52		})53		| Err(DispatchErrorWithPostInfo {54			post_info: PostDispatchInfo {55				actual_weight: Some(weight),56				..57			},58			..59		}) => *weight += dispatch_weight::<T>(),60		_ => {}61	}62	result63}6465pub trait CollectionDispatch<T: Config> {66	fn create(67		sender: T::CrossAccountId,68		data: CreateCollectionData<T::AccountId>,69	) -> DispatchResult;70	fn destroy(sender: T::CrossAccountId, handle: CollectionHandle<T>) -> DispatchResult;7172	fn dispatch(handle: CollectionHandle<T>) -> Self;73	fn into_inner(self) -> CollectionHandle<T>;7475	fn as_dyn(&self) -> &dyn CommonCollectionOperations<T>;76}
after · pallets/common/src/dispatch.rs
1use frame_support::{2	dispatch::{3		DispatchResultWithPostInfo, PostDispatchInfo, Weight, DispatchErrorWithPostInfo,4		DispatchResult,5	},6	weights::Pays,7	traits::Get,8};9use up_data_structs::{CollectionId, CreateCollectionData};1011use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};1213// TODO: move to benchmarking14/// Price of [`dispatch_call`] call with noop `call` argument15pub fn dispatch_weight<T: Config>() -> Weight {16	// Read collection17	<T as frame_system::Config>::DbWeight::get().reads(1)18	// Dynamic dispatch?19	+ 6_000_00020	// submit_logs is measured as part of collection pallets21}2223/// Helper function to implement substrate calls for common collection methods24pub fn dispatch_call<25	T: Config,26	C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,27>(28	collection: CollectionId,29	call: C,30) -> DispatchResultWithPostInfo {31	let handle =32		CollectionHandle::try_get(collection).map_err(|error| DispatchErrorWithPostInfo {33			post_info: PostDispatchInfo {34				actual_weight: Some(dispatch_weight::<T>()),35				pays_fee: Pays::Yes,36			},37			error,38		})?;39	handle40		.check_is_internal()41		.map_err(|error| DispatchErrorWithPostInfo {42			post_info: PostDispatchInfo {43				actual_weight: Some(dispatch_weight::<T>()),44				pays_fee: Pays::Yes,45			},46			error,47		})?;48	let dispatched = T::CollectionDispatch::dispatch(handle);49	let mut result = call(dispatched.as_dyn());50	match &mut result {51		Ok(PostDispatchInfo {52			actual_weight: Some(weight),53			..54		})55		| Err(DispatchErrorWithPostInfo {56			post_info: PostDispatchInfo {57				actual_weight: Some(weight),58				..59			},60			..61		}) => *weight += dispatch_weight::<T>(),62		_ => {}63	}64	result65}6667pub trait CollectionDispatch<T: Config> {68	fn create(69		sender: T::CrossAccountId,70		data: CreateCollectionData<T::AccountId>,71	) -> DispatchResult;72	fn destroy(sender: T::CrossAccountId, handle: CollectionHandle<T>) -> DispatchResult;7374	fn dispatch(handle: CollectionHandle<T>) -> Self;75	fn into_inner(self) -> CollectionHandle<T>;7677	fn as_dyn(&self) -> &dyn CommonCollectionOperations<T>;78}