git.delta.rocks / unique-network / refs/commits / 14614bd234c3

difftreelog

doc(fungible-pallet): added new details & fix

PraetorP2022-07-18parent: #4fa2a42.patch.diff
in: master

1 file changed

modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
71//!71//!
72//! The Fungible pallet provides implementations for the following traits.72//! The Fungible pallet provides implementations for the following traits.
73//!73//!
74//! - [`WithRecorder`](pallet_evm_coder_substrate::WithRecorder):74//! - [`WithRecorder`](pallet_evm_coder_substrate::WithRecorder): Trait for EVM support
75//! - [`CommonCollectionOperations`](pallet_common::CommonCollectionOperations): Functions for dealing with collections75//! - [`CommonCollectionOperations`](pallet_common::CommonCollectionOperations): Functions for dealing with collections
76//! - [`CommonWeightInfo`](pallet_common::CommonWeightInfo): Functions for retrieval of transaction weight76//! - [`CommonWeightInfo`](pallet_common::CommonWeightInfo): Functions for retrieval of transaction weight
77//! - [`CommonEvmHandler`](pallet_common::erc::CommonEvmHandler): Function for handling EVM runtime calls77//! - [`CommonEvmHandler`](pallet_common::erc::CommonEvmHandler): Function for handling EVM runtime calls
169 QueryKind = ValueQuery,169 QueryKind = ValueQuery,
170 >;170 >;
171}171}
172/// Handler for fungible assets.172
173/// Wrapper around untyped collection handle, asserting inner collection is of fungible type.
174/// Required for interaction with Fungible collections, type safety and implementation [`solidity_interface`][`evm_coder::solidity_interface`].
175
173pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);176pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);
177
178/// Implementation of methods required for dispatching during runtime.
174impl<T: Config> FungibleHandle<T> {179impl<T: Config> FungibleHandle<T> {
175 /// Casts [pallet_common::CollectionHandle] into [FungibleHandle].180 /// Casts [`CollectionHandle`][`pallet_common::CollectionHandle`] into [`FungibleHandle`].
176 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {181 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {
177 Self(inner)182 Self(inner)
178 }183 }
179184
180 /// Casts [FungibleHandle] into [pallet_common::CollectionHandle].185 /// Casts [`FungibleHandle`] into [`CollectionHandle`][`pallet_common::CollectionHandle`].
181 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {186 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {
182 self.0187 self.0
183 }188 }
184 /// Returns a mutable reference to the internal [pallet_common::CollectionHandle].189 /// Returns a mutable reference to the internal [`CollectionHandle`][`pallet_common::CollectionHandle`].
185 pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {190 pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {
186 &mut self.0191 &mut self.0
187 }192 }
287292
288 /// Transfers the specified amount of tokens. Will check that293 /// Transfers the specified amount of tokens. Will check that
289 /// the transfer is allowed for the token.294 /// the transfer is allowed for the token.
295 ///
296 /// - `from`: Owner of tokens to transfer.
297 /// - `to`: Recepient of transfered tokens.
298 /// - `amount`: Amount of tokens to transfer.
299 /// - `collection`: Collection that contains the token
290 pub fn transfer(300 pub fn transfer(
291 collection: &FungibleHandle<T>,301 collection: &FungibleHandle<T>,
292 from: &T::CrossAccountId,302 from: &T::CrossAccountId,
358 }368 }
359369
360 /// Minting tokens for multiple IDs.370 /// Minting tokens for multiple IDs.
371 /// See [`create_item`][`Pallet::create_item`] for more details.
361 pub fn create_multiple_items(372 pub fn create_multiple_items(
362 collection: &FungibleHandle<T>,373 collection: &FungibleHandle<T>,
363 sender: &T::CrossAccountId,374 sender: &T::CrossAccountId,
459 ));470 ));
460 }471 }
461472
462 /// Sets the amount of owner tokens that the spender can manage.473 /// Set allowance for the spender to `transfer` or `burn` owner's tokens.
474 ///
475 /// - `amount`: Amount of tokens the spender is allowed to `transfer` or `burn`.
463 pub fn set_allowance(476 pub fn set_allowance(
464 collection: &FungibleHandle<T>,477 collection: &FungibleHandle<T>,
465 owner: &T::CrossAccountId,478 owner: &T::CrossAccountId,
484 Ok(())497 Ok(())
485 }498 }
486499
500 /// Returns allowance, which should be set after transaction
487 fn check_allowed(501 fn check_allowed(
488 collection: &FungibleHandle<T>,502 collection: &FungibleHandle<T>,
489 spender: &T::CrossAccountId,503 spender: &T::CrossAccountId,
523 Ok(allowance)537 Ok(allowance)
524 }538 }
525539
526 /// Transfers of tokens that `from` gave to `spender` to manage, to `to` ID.540 /// Transfer FT tokens from one account to another.
541 /// Same as the [`transfer`] but spender doesn't needs to be an owner of the token pieces.
542 /// The owner should set allowance for the spender to transfer pieces.
543 /// See [`set_allowance`][`Pallet::set_allowance`] for more details.
544 ///
545 /// [`transfer`]: struct.Pallet.html#method.transfer
527 pub fn transfer_from(546 pub fn transfer_from(
528 collection: &FungibleHandle<T>,547 collection: &FungibleHandle<T>,
529 spender: &T::CrossAccountId,548 spender: &T::CrossAccountId,
543 Ok(())562 Ok(())
544 }563 }
545564
546 /// Burns managed tokens.565 /// Burn FT tokens from the account.
566 ///
567 /// Same as the [`burn`][`Pallet::burn`] but spender doesn't need to be an owner of the tokens. The `from` should
568 /// set allowance for the spender to burn tokens.
569 /// See [`set_allowance`][`Pallet::set_allowance`] for more details.
547 pub fn burn_from(570 pub fn burn_from(
548 collection: &FungibleHandle<T>,571 collection: &FungibleHandle<T>,
549 spender: &T::CrossAccountId,572 spender: &T::CrossAccountId,
562 Ok(())585 Ok(())
563 }586 }
564587
565 /// Delegated to `create_multiple_items`588
589 /// Creates FT token.
590 ///
591 /// The sender should be the owner/admin of the collection or collection should be configured
592 /// to allow public minting.
593 ///
594 /// - `data`: Contains user who will become the owners of the tokens and amount
595 /// of tokens he will receive.
566 pub fn create_item(596 pub fn create_item(
567 collection: &FungibleHandle<T>,597 collection: &FungibleHandle<T>,
568 sender: &T::CrossAccountId,598 sender: &T::CrossAccountId,