difftreelog
doc(fungible-pallet): added new details & fix
in: master
1 file changed
pallets/fungible/src/lib.rsdiffbeforeafterboth71//!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 support75//! - [`CommonCollectionOperations`](pallet_common::CommonCollectionOperations): Functions for dealing with collections75//! - [`CommonCollectionOperations`](pallet_common::CommonCollectionOperations): Functions for dealing with collections76//! - [`CommonWeightInfo`](pallet_common::CommonWeightInfo): Functions for retrieval of transaction weight76//! - [`CommonWeightInfo`](pallet_common::CommonWeightInfo): Functions for retrieval of transaction weight77//! - [`CommonEvmHandler`](pallet_common::erc::CommonEvmHandler): Function for handling EVM runtime calls77//! - [`CommonEvmHandler`](pallet_common::erc::CommonEvmHandler): Function for handling EVM runtime calls169 QueryKind = ValueQuery,169 QueryKind = ValueQuery,170 >;170 >;171}171}172/// Handler for fungible assets.172173/// 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`].175173pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);176pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);177178/// 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 }179184180 /// 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.0183 }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.0187 }192 }287292288 /// Transfers the specified amount of tokens. Will check that293 /// Transfers the specified amount of tokens. Will check that289 /// 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 token290 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 }359369360 /// 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 }461472462 /// 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 }486499500 /// Returns allowance, which should be set after transaction487 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 }525539526 /// 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.transfer527 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 }545564546 /// 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` should568 /// 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 }564587565 /// 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 configured592 /// to allow public minting.593 ///594 /// - `data`: Contains user who will become the owners of the tokens and amount595 /// 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,