difftreelog
fix rename create_raw to avoid misunderstanding
in: master
3 files changed
pallets/common/src/dispatch.rsdiffbeforeafterboth1//! Module with interfaces for dispatching collections.23use frame_support::{4 dispatch::{5 DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, Pays,6 PostDispatchInfo,7 },8 traits::Get,9};10use sp_runtime::DispatchError;11use sp_weights::Weight;12use up_data_structs::{CollectionId, CreateCollectionData};1314use crate::{pallet::Config, CommonCollectionOperations};1516// TODO: move to benchmarking17/// Price of [`dispatch_tx`] call with noop `call` argument18pub fn dispatch_weight<T: Config>() -> Weight {19 // Read collection20 <T as frame_system::Config>::DbWeight::get().reads(1)21 // Dynamic dispatch?22 + Weight::from_parts(6_000_000, 0)23 // submit_logs is measured as part of collection pallets24}2526/// Helper function to implement substrate calls for common collection methods.27///28/// * `collection` - The collection on which to call the method.29/// * `call` - The function in which to call the corresponding method from [`CommonCollectionOperations`].30pub fn dispatch_tx<31 T: Config,32 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,33>(34 collection: CollectionId,35 call: C,36) -> DispatchResultWithPostInfo {37 let dispatched = T::CollectionDispatch::dispatch(collection)38 .and_then(|dispatched| {39 dispatched.check_is_internal()?;40 Ok(dispatched)41 })42 .map_err(|error| DispatchErrorWithPostInfo {43 post_info: PostDispatchInfo {44 actual_weight: Some(dispatch_weight::<T>()),45 pays_fee: Pays::Yes,46 },47 error,48 })?;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}6667/// Interface for working with different collections through the dispatcher.68pub trait CollectionDispatch<T: Config> {69 /// Check if the collection is internal.70 fn check_is_internal(&self) -> DispatchResult;7172 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).73 ///74 /// * `sender` - The user who will become the owner of the collection.75 /// * `payer` - If set, the user who pays the collection creation deposit.76 /// * `data` - Description of the created collection.77 fn create(78 sender: T::CrossAccountId,79 payer: Option<T::CrossAccountId>,80 data: CreateCollectionData<T::CrossAccountId>,81 ) -> Result<CollectionId, DispatchError> {82 Self::create_internal(sender, payer, false, data)83 }8485 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).86 ///87 /// * `sender` - The user who will become the owner of the collection.88 /// * `payer` - If set, the user who pays the collection creation deposit.89 /// * `data` - Description of the created collection.90 /// * `is_special_collection` -- Whether this collection is a system one, i.e. can have special flags set.91 fn create_internal(92 sender: T::CrossAccountId,93 payer: Option<T::CrossAccountId>,94 is_special_collection: bool,95 data: CreateCollectionData<T::CrossAccountId>,96 ) -> Result<CollectionId, DispatchError>;9798 /// Delete the collection.99 ///100 /// * `sender` - The owner of the collection.101 /// * `handle` - Collection handle.102 fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult;103104 /// Get a specialized collection from the handle.105 ///106 /// * `handle` - Collection handle.107 fn dispatch(collection_id: CollectionId) -> Result<Self, DispatchError>108 where109 Self: Sized;110111 /// Get the implementation of [`CommonCollectionOperations`].112 fn as_dyn(&self) -> &dyn CommonCollectionOperations<T>;113}1//! Module with interfaces for dispatching collections.23use frame_support::{4 dispatch::{5 DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, Pays,6 PostDispatchInfo,7 },8 traits::Get,9};10use sp_runtime::DispatchError;11use sp_weights::Weight;12use up_data_structs::{CollectionId, CreateCollectionData};1314use crate::{pallet::Config, CommonCollectionOperations};1516// TODO: move to benchmarking17/// Price of [`dispatch_tx`] call with noop `call` argument18pub fn dispatch_weight<T: Config>() -> Weight {19 // Read collection20 <T as frame_system::Config>::DbWeight::get().reads(1)21 // Dynamic dispatch?22 + Weight::from_parts(6_000_000, 0)23 // submit_logs is measured as part of collection pallets24}2526/// Helper function to implement substrate calls for common collection methods.27///28/// * `collection` - The collection on which to call the method.29/// * `call` - The function in which to call the corresponding method from [`CommonCollectionOperations`].30pub fn dispatch_tx<31 T: Config,32 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,33>(34 collection: CollectionId,35 call: C,36) -> DispatchResultWithPostInfo {37 let dispatched = T::CollectionDispatch::dispatch(collection)38 .and_then(|dispatched| {39 dispatched.check_is_internal()?;40 Ok(dispatched)41 })42 .map_err(|error| DispatchErrorWithPostInfo {43 post_info: PostDispatchInfo {44 actual_weight: Some(dispatch_weight::<T>()),45 pays_fee: Pays::Yes,46 },47 error,48 })?;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}6667/// Interface for working with different collections through the dispatcher.68pub trait CollectionDispatch<T: Config> {69 /// Check if the collection is internal.70 fn check_is_internal(&self) -> DispatchResult;7172 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).73 ///74 /// * `sender` - The user who will become the owner of the collection.75 /// * `payer` - If set, the user who pays the collection creation deposit.76 /// * `data` - Description of the created collection.77 fn create(78 sender: T::CrossAccountId,79 payer: Option<T::CrossAccountId>,80 data: CreateCollectionData<T::CrossAccountId>,81 ) -> Result<CollectionId, DispatchError> {82 Self::create_raw(sender, payer, false, data)83 }8485 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).86 ///87 /// * `sender` - The user who will become the owner of the collection.88 /// * `payer` - If set, the user who pays the collection creation deposit.89 /// * `data` - Description of the created collection.90 /// * `is_special_collection` -- Whether this collection is a system one, i.e. can have special flags set.91 fn create_raw(92 sender: T::CrossAccountId,93 payer: Option<T::CrossAccountId>,94 is_special_collection: bool,95 data: CreateCollectionData<T::CrossAccountId>,96 ) -> Result<CollectionId, DispatchError>;9798 /// Delete the collection.99 ///100 /// * `sender` - The owner of the collection.101 /// * `handle` - Collection handle.102 fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult;103104 /// Get a specialized collection from the handle.105 ///106 /// * `handle` - Collection handle.107 fn dispatch(collection_id: CollectionId) -> Result<Self, DispatchError>108 where109 Self: Sized;110111 /// Get the implementation of [`CommonCollectionOperations`].112 fn as_dyn(&self) -> &dyn CommonCollectionOperations<T>;113}pallets/foreign-assets/src/lib.rsdiffbeforeafterboth--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -156,7 +156,7 @@
let payer = None;
let is_special_collection = true;
- let collection_id = T::CollectionDispatch::create_internal(
+ let collection_id = T::CollectionDispatch::create_raw(
foreign_collection_owner,
payer,
is_special_collection,
runtime/common/dispatch.rsdiffbeforeafterboth--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -66,7 +66,7 @@
}
}
- fn create_internal(
+ fn create_raw(
sender: T::CrossAccountId,
payer: Option<T::CrossAccountId>,
is_special_collection: bool,