difftreelog
doc: Fix PR
in: master
3 files changed
pallets/common/src/dispatch.rsdiffbeforeafterboth1//! Module with interfaces for dispatching collections.23use frame_support::{4 dispatch::{5 DispatchResultWithPostInfo, PostDispatchInfo, Weight, DispatchErrorWithPostInfo,6 DispatchResult,7 },8 weights::Pays,9 traits::Get,10};11use up_data_structs::{CollectionId, CreateCollectionData};1213use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};1415// TODO: move to benchmarking16/// Price of [`dispatch_tx`] call with noop `call` argument17pub fn dispatch_weight<T: Config>() -> Weight {18 // Read collection19 <T as frame_system::Config>::DbWeight::get().reads(1)20 // Dynamic dispatch?21 + 6_000_00022 // submit_logs is measured as part of collection pallets23}2425/// Helper function to implement substrate calls for common collection methods.26///27/// * `collection` - The collection on which to call the method.28/// * `call` - The function in which to call the corresponding method from [CommonCollectionOperations].29pub fn dispatch_tx<30 T: Config,31 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,32>(33 collection: CollectionId,34 call: C,35) -> DispatchResultWithPostInfo {36 let handle =37 CollectionHandle::try_get(collection).map_err(|error| DispatchErrorWithPostInfo {38 post_info: PostDispatchInfo {39 actual_weight: Some(dispatch_weight::<T>()),40 pays_fee: Pays::Yes,41 },42 error,43 })?;44 handle45 .check_is_internal()46 .map_err(|error| DispatchErrorWithPostInfo {47 post_info: PostDispatchInfo {48 actual_weight: Some(dispatch_weight::<T>()),49 pays_fee: Pays::Yes,50 },51 error,52 })?;53 let dispatched = T::CollectionDispatch::dispatch(handle);54 let mut result = call(dispatched.as_dyn());55 match &mut result {56 Ok(PostDispatchInfo {57 actual_weight: Some(weight),58 ..59 })60 | Err(DispatchErrorWithPostInfo {61 post_info: PostDispatchInfo {62 actual_weight: Some(weight),63 ..64 },65 ..66 }) => *weight += dispatch_weight::<T>(),67 _ => {}68 }69 result70}7172/// Interface for working with different collections through the dispatcher.73pub trait CollectionDispatch<T: Config> {74 /// Create a collection. The collection will be created according to the value of [data.mode](CreateCollectionData::mode).75 ///76 /// * `sender` - The user who will become the owner of the collection.77 /// * `data` - Description of the created collection.78 fn create(79 sender: T::CrossAccountId,80 data: CreateCollectionData<T::AccountId>,81 ) -> DispatchResult;8283 /// Delete the collection.84 ///85 /// * `sender` - The owner of the collection.86 /// * `handle` - Collection handle.87 fn destroy(sender: T::CrossAccountId, handle: CollectionHandle<T>) -> DispatchResult;8889 /// Get a specialized collection from the handle.90 ///91 /// * `handle` - Collection handle.92 fn dispatch(handle: CollectionHandle<T>) -> Self;9394 /// Get the collection handle for the corresponding implementation.95 fn into_inner(self) -> CollectionHandle<T>;9697 /// Получить реализацию [CommonCollectionOperations].98 fn as_dyn(&self) -> &dyn CommonCollectionOperations<T>;99}pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-//! The module contains a number of functions for converting and checking etherium identifiers.
+//! The module contains a number of functions for converting and checking ethereum identifiers.
use up_data_structs::CollectionId;
use sp_core::H160;
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -132,6 +132,9 @@
/// Collection handle contains information about collection data and id.
/// Also provides functionality to count consumed gas.
+/// CollectionHandle is used as a generic wrapper for collections of all types.
+/// It allows to perform common operations and queries on any collection type,
+/// both completely general for all, as well as their respective implementations of [CommonCollectionOperations].
#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]
pub struct CollectionHandle<T: Config> {
/// Collection id