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

difftreelog

doc: fix PR

Trubnikov Sergey2022-07-19parent: #f37009b.patch.diff
in: master

3 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
25/// Helper function to implement substrate calls for common collection methods.25/// Helper function to implement substrate calls for common collection methods.
26///26///
27/// * `collection` - The collection on which to call the method.27/// * `collection` - The collection on which to call the method.
28/// * `call` - The function in which to call the corresponding method from [CommonCollectionOperations].28/// * `call` - The function in which to call the corresponding method from [`CommonCollectionOperations`].
29pub fn dispatch_tx<29pub fn dispatch_tx<
30 T: Config,30 T: Config,
31 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,31 C: FnOnce(&dyn CommonCollectionOperations<T>) -> DispatchResultWithPostInfo,
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
51pub trait CommonEvmHandler {51pub trait CommonEvmHandler {
52 const CODE: &'static [u8];52 const CODE: &'static [u8];
5353
54 /// Call precompiled handle.
54 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;55 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;
55}56}
5657
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
1616
17//! # Common pallet17//! # Common pallet
18//!18//!
19//! The Common pallet provides functionality for handling collections.19//! The Common pallet provides an interface for common collection operations for different collection types
20//! (see [CommonCollectionOperations], as well as a generic dispatcher for these, see [dispatch] module.
21//! It also provides this functionality to EVM, see [erc] and [eth] modules.
20//!22//!
21//! ## Overview23//! ## Overview
22//!24//!
42//! **Collection properties** - Collection properties are simply key-value stores where various44//! **Collection properties** - Collection properties are simply key-value stores where various
43//! metadata can be placed.45//! metadata can be placed.
44//!46//!
45//! **Collection property permissions** - For each property in the collection can be set permission47//! **Permissions on token properties** - For each property in the token can be set permission
46//! to change, see [PropertyPermission].48//! to change, see [PropertyPermission].
47//!
48//! **Permissions on token properties** - Similar to _permissions on collection properties_,
49//! only restrictions apply to token properties.
50//!49//!
51//! **Collection administrator** - For a collection, you can set administrators who have the right50//! **Collection administrator** - For a collection, you can set administrators who have the right
52//! to most actions on the collection.51//! to most actions on the collection.
132131
133/// Collection handle contains information about collection data and id.132/// Collection handle contains information about collection data and id.
134/// Also provides functionality to count consumed gas.133/// Also provides functionality to count consumed gas.
134///
135/// CollectionHandle is used as a generic wrapper for collections of all types.135/// CollectionHandle is used as a generic wrapper for collections of all types.
136/// It allows to perform common operations and queries on any collection type,136/// It allows to perform common operations and queries on any collection type,
137/// both completely general for all, as well as their respective implementations of [CommonCollectionOperations].137/// both completely general for all, as well as their respective implementations of [`CommonCollectionOperations`].
138#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]138#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]
139pub struct CollectionHandle<T: Config> {139pub struct CollectionHandle<T: Config> {
140 /// Collection id140 /// Collection id
163 })163 })
164 }164 }
165165
166 /// Same as [CollectionHandle::new] but with an existed [SubstrateRecorder].166 /// Same as [CollectionHandle::new] but with an existed [`SubstrateRecorder`].
167 pub fn new_with_recorder(id: CollectionId, recorder: SubstrateRecorder<T>) -> Option<Self> {167 pub fn new_with_recorder(id: CollectionId, recorder: SubstrateRecorder<T>) -> Option<Self> {
168 <CollectionById<T>>::get(id).map(|collection| Self {168 <CollectionById<T>>::get(id).map(|collection| Self {
169 id,169 id,
178 Self::new_with_gas_limit(id, u64::MAX)178 Self::new_with_gas_limit(id, u64::MAX)
179 }179 }
180180
181 /// Same as [CollectionHandle::new] but if collection not found [Error::CollectionNotFound] returned.181 /// Same as [`CollectionHandle::new`] but if collection not found [`Error::CollectionNotFound`] returned.
182 pub fn try_get(id: CollectionId) -> Result<Self, DispatchError> {182 pub fn try_get(id: CollectionId) -> Result<Self, DispatchError> {
183 Ok(Self::new(id).ok_or(<Error<T>>::CollectionNotFound)?)183 Ok(Self::new(id).ok_or(<Error<T>>::CollectionNotFound)?)
184 }184 }
213 ///213 ///
214 /// Unique collections allows sponsoring for certain actions.214 /// Unique collections allows sponsoring for certain actions.
215 /// This method allows you to set the sponsor of the collection.215 /// This method allows you to set the sponsor of the collection.
216 /// In order for sponsorship to become active, it must be confirmed through [Self::confirm_sponsorship].216 /// In order for sponsorship to become active, it must be confirmed through [`Self::confirm_sponsorship`].
217 pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {217 pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {
218 self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);218 self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);
219 Ok(())219 Ok(())
222 /// Confirm sponsorship222 /// Confirm sponsorship
223 ///223 ///
224 /// In order for the sponsorship to become active, the user set as the sponsor must confirm their participation.224 /// In order for the sponsorship to become active, the user set as the sponsor must confirm their participation.
225 /// Before confirming sponsorship, the user must be specified as the sponsor of the collection via [Self::set_sponsor].225 /// Before confirming sponsorship, the user must be specified as the sponsor of the collection via [`Self::set_sponsor`].
226 pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {226 pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {
227 if self.collection.sponsorship.pending_sponsor() != Some(sender) {227 if self.collection.sponsorship.pending_sponsor() != Some(sender) {
228 return Ok(false);228 return Ok(false);
233 }233 }
234234
235 /// Checks that the collection was created with, and must be operated upon through **Unique API**.235 /// Checks that the collection was created with, and must be operated upon through **Unique API**.
236 /// Now check only the `external_collection` flag and if it's **true**, then return [Error::CollectionIsExternal] error.236 /// Now check only the `external_collection` flag and if it's **true**, then return [`Error::CollectionIsExternal`] error.
237 pub fn check_is_internal(&self) -> DispatchResult {237 pub fn check_is_internal(&self) -> DispatchResult {
238 if self.external_collection {238 if self.external_collection {
239 return Err(<Error<T>>::CollectionIsExternal)?;239 return Err(<Error<T>>::CollectionIsExternal)?;
243 }243 }
244244
245 /// Checks that the collection was created with, and must be operated upon through an **assimilated API**.245 /// Checks that the collection was created with, and must be operated upon through an **assimilated API**.
246 /// Now check only the `external_collection` flag and if it's **false**, then return [Error::CollectionIsInternal] error.246 /// Now check only the `external_collection` flag and if it's **false**, then return [`Error::CollectionIsInternal`] error.
247 pub fn check_is_external(&self) -> DispatchResult {247 pub fn check_is_external(&self) -> DispatchResult {
248 if !self.external_collection {248 if !self.external_collection {
249 return Err(<Error<T>>::CollectionIsInternal)?;249 return Err(<Error<T>>::CollectionIsInternal)?;
325 + TypeInfo325 + TypeInfo
326 + account::Config326 + account::Config
327 {327 {
328 /// Weight info.328 /// Weight information for functions of this pallet.
329 type WeightInfo: WeightInfo;329 type WeightInfo: WeightInfo;
330330
331 /// Events compatible with [frame_system::Config::Event].331 /// Events compatible with [`frame_system::Config::Event`].
332 type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;332 type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;
333333
334 /// Currency.334 /// Currency.
340 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,340 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,
341 >;341 >;
342342
343 /// Collection dispatcher.343 /// Dispatcher of operations on collections.
344 type CollectionDispatch: CollectionDispatch<Self>;344 type CollectionDispatch: CollectionDispatch<Self>;
345345
346 /// Treasury account id getter.346 /// Treasury account id getter.
347 type TreasuryAccountId: Get<Self::AccountId>;347 type TreasuryAccountId: Get<Self::AccountId>;
348348
349 /// Contract address getter.349 /// Address under which the CollectionHelper contract would be available.
350 type ContractAddress: Get<H160>;350 type ContractAddress: Get<H160>;
351351
352 /// Mapper for tokens to Etherium addresses.352 /// Mapper for tokens to Etherium addresses.
353 type EvmTokenAddressMapping: TokenAddressMapping<H160>;353 type EvmTokenAddressMapping: TokenAddressMapping<H160>;
354354
355 /// Mapper for tokens to [CrossAccountId].355 /// Mapper for tokens to [`CrossAccountId`].
356 type CrossTokenAddressMapping: TokenAddressMapping<Self::CrossAccountId>;356 type CrossTokenAddressMapping: TokenAddressMapping<Self::CrossAccountId>;
357 }357 }
358358
378 CollectionCreated(378 CollectionCreated(
379 /// Globally unique identifier of newly created collection.379 /// Globally unique identifier of newly created collection.
380 CollectionId,380 CollectionId,
381 /// [CollectionMode] converted into _u8_.381 /// [`CollectionMode`] converted into _u8_.
382 u8,382 u8,
383 /// Collection owner.383 /// Collection owner.
384 T::AccountId,384 T::AccountId,
1469 fn burn_from() -> Weight;1469 fn burn_from() -> Weight;
14701470
1471 /// Differs from burn_item in case of Fungible and Refungible, as it should burn1471 /// Differs from burn_item in case of Fungible and Refungible, as it should burn
1472 /// whole users's balance1472 /// whole users's balance.
1473 ///1473 ///
1474 /// This method shouldn't be used directly, as it doesn't count breadth price, use [burn_recursively](CommonWeightInfo::burn_recursively) instead1474 /// This method shouldn't be used directly, as it doesn't count breadth price, use [burn_recursively](CommonWeightInfo::burn_recursively) instead
1475 fn burn_recursively_self_raw() -> Weight;1475 fn burn_recursively_self_raw() -> Weight;
14761476
1477 /// Cost of iterating over `amount` children while burning, without counting child burning itself1477 /// Cost of iterating over `amount` children while burning, without counting child burning itself.
1478 ///1478 ///
1479 /// This method shouldn't be used directly, as it doesn't count depth price, use [burn_recursively](CommonWeightInfo::burn_recursively) instead1479 /// This method shouldn't be used directly, as it doesn't count depth price, use [burn_recursively](CommonWeightInfo::burn_recursively) instead
1480 fn burn_recursively_breadth_raw(amount: u32) -> Weight;1480 fn burn_recursively_breadth_raw(amount: u32) -> Weight;
14811481
1482 /// The price of recursive burning a token.1482 /// The price of recursive burning a token.
1483 ///1483 ///
1484 /// `max_selfs` -1484 /// `max_selfs` - The maximum burning weight of the token itself.
1485 /// `max_breadth` - The maximum number of nested tokens to burn.
1485 fn burn_recursively(max_selfs: u32, max_breadth: u32) -> Weight {1486 fn burn_recursively(max_selfs: u32, max_breadth: u32) -> Weight {
1486 Self::burn_recursively_self_raw()1487 Self::burn_recursively_self_raw()
1487 .saturating_mul(max_selfs.max(1) as u64)1488 .saturating_mul(max_selfs.max(1) as u64)
15891590
1590 /// Set token properties.1591 /// Set token properties.
1591 ///1592 ///
1592 /// The appropriate [PropertyPermission] for the token property1593 /// The appropriate [`PropertyPermission`] for the token property
1593 /// must be set with [Self::set_token_property_permissions].1594 /// must be set with [`Self::set_token_property_permissions`].
1594 ///1595 ///
1595 /// * `sender` - Must be either the owner of the token or its admin.1596 /// * `sender` - Must be either the owner of the token or its admin.
1596 /// * `token_id` - The token for which the properties are being set.1597 /// * `token_id` - The token for which the properties are being set.
16061607
1607 /// Remove token properties.1608 /// Remove token properties.
1608 ///1609 ///
1609 /// The appropriate [PropertyPermission] for the token property1610 /// The appropriate [`PropertyPermission`] for the token property
1610 /// must be set with [Self::set_token_property_permissions].1611 /// must be set with [`Self::set_token_property_permissions`].
1611 ///1612 ///
1612 /// * `sender` - Must be either the owner of the token or its admin.1613 /// * `sender` - Must be either the owner of the token or its admin.
1613 /// * `token_id` - The token for which the properties are being remove.1614 /// * `token_id` - The token for which the properties are being remove.
16651666
1666 /// Send parts of a token owned by another user.1667 /// Send parts of a token owned by another user.
1667 ///1668 ///
1668 /// Before calling this method, you must grant rights to the calling user via [Self::approve].1669 /// Before calling this method, you must grant rights to the calling user via [`Self::approve`].
1669 ///1670 ///
1670 /// * `sender` - The user who has access to the token.1671 /// * `sender` - The user who must have access to the token (see [`Self::approve`]).
1671 /// * `from` - The user who owns the token.1672 /// * `from` - The user who owns the token.
1672 /// * `to` - Recepient user.1673 /// * `to` - Recepient user.
1673 /// * `token` - The token of which parts are being sent.1674 /// * `token` - The token of which parts are being sent.
16851686
1686 /// Burn parts of a token owned by another user.1687 /// Burn parts of a token owned by another user.
1687 ///1688 ///
1688 /// Before calling this method, you must grant rights to the calling user via [Self::approve].1689 /// Before calling this method, you must grant rights to the calling user via [`Self::approve`].
1689 ///1690 ///
1690 /// * `sender` - The user who has access to the token.1691 /// * `sender` - The user who must have access to the token (see [`Self::approve`]).
1691 /// * `from` - The user who owns the token.1692 /// * `from` - The user who owns the token.
1692 /// * `token` - The token of which parts are being sent.1693 /// * `token` - The token of which parts are being sent.
1693 /// * `amount` - The number of parts of the token that will be transferred.1694 /// * `amount` - The number of parts of the token that will be transferred.
17501751
1751 /// Get the value of the token property by key.1752 /// Get the value of the token property by key.
1752 ///1753 ///
1753 /// * `token` - Token property to get.1754 /// * `token` - Token with the property to get.
1754 /// * `key` - Property name.1755 /// * `key` - Property name.
1755 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue>;1756 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue>;
17561757
1757 /// Get a set of token properties by key vector.1758 /// Get a set of token properties by key vector.
1758 ///1759 ///
1759 /// * `token` - Token property to get.1760 /// * `token` - Token with the property to get.
1760 /// * `keys` - Vector of keys. If this parameter is [None](sp_std::result::Result),1761 /// * `keys` - Vector of property keys. If this parameter is [None](sp_std::result::Result),
1761 /// then all properties are returned.1762 /// then all properties are returned.
1762 fn token_properties(&self, token: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property>;1763 fn token_properties(&self, token: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property>;
17631764
1811 ) -> DispatchResultWithPostInfo;1812 ) -> DispatchResultWithPostInfo;
1812}1813}
18131814
1814/// Merge [DispatchResult] with [Weight] into [DispatchResultWithPostInfo].1815/// Merge [`DispatchResult`] with [`Weight`] into [`DispatchResultWithPostInfo`].
1815///1816///
1816/// Used for [CommonCollectionOperations] implementations and flexible enough to do so.1817/// Used for [`CommonCollectionOperations`] implementations and flexible enough to do so.
1817pub fn with_weight(res: DispatchResult, weight: Weight) -> DispatchResultWithPostInfo {1818pub fn with_weight(res: DispatchResult, weight: Weight) -> DispatchResultWithPostInfo {
1818 let post_info = PostDispatchInfo {1819 let post_info = PostDispatchInfo {
1819 actual_weight: Some(weight),1820 actual_weight: Some(weight),