Struct smarthub_sdk::mt::base::core_impl::MultiFungibleToken
source · pub struct MultiFungibleToken {
pub tokens: TreeMap<AccountId, MtToken>,
pub account_storage_usage: StorageUsage,
}Expand description
Implementation of a MultiFungibleToken standard. Allows to include NEP-141 compatible token to any contract. There are next traits that any contract may implement: - MultiFungibleTokenCore – interface with mt_transfer methods. MultiFungibleToken provides methods for it. - MultiFungibleTokenMetaData – return metadata for the token in NEP-148, up to contract to implement. - StorageManager – interface for NEP-145 for allocating storage per account. MultiFungibleToken provides methods for it. - AccountRegistrar – interface for an account to register and unregister
For example usage, see examples/fungible-token/src/lib.rs.
Fields§
§tokens: TreeMap<AccountId, MtToken>§account_storage_usage: StorageUsageThe storage size in bytes for one account.
Implementations§
source§impl MultiFungibleToken
impl MultiFungibleToken
pub fn new<S>(prefix: S) -> Selfwhere
S: IntoStorageKey,
pub fn internal_unwrap_balance_of(
&self,
mft: &MtToken,
account_id: &AccountId
) -> Balance
pub fn internal_deposit(
&mut self,
token_id: &AccountId,
account_id: &AccountId,
amount: Balance
)
pub fn internal_withdraw(
&mut self,
token_id: &AccountId,
account_id: &AccountId,
amount: Balance
)
pub fn internal_transfer_batch(
&mut self,
token_ids: &Vec<AccountId>,
sender_id: &AccountId,
receiver_id: &AccountId,
amounts: &Vec<U128>,
memo: Option<String>
)
pub fn internal_transfer(
&mut self,
token_id: &AccountId,
sender_id: &AccountId,
receiver_id: &AccountId,
amount: Balance,
_memo: Option<String>
)
pub fn internal_register_account(
&mut self,
token_id: &AccountId,
account_id: &AccountId
)
pub fn internal_on_ft_transfer(
&mut self,
ft_token_id: &AccountId,
sender_id: &AccountId,
amount: &U128
) -> PromiseOrValue<U128>
source§impl MultiFungibleToken
impl MultiFungibleToken
sourcepub fn internal_mt_resolve_transfer(
&mut self,
token_ids: &Vec<AccountId>,
sender_id: &AccountId,
receiver_id: AccountId,
amounts: &Vec<U128>
) -> Vec<U128>
pub fn internal_mt_resolve_transfer(
&mut self,
token_ids: &Vec<AccountId>,
sender_id: &AccountId,
receiver_id: AccountId,
amounts: &Vec<U128>
) -> Vec<U128>
Internal method that returns the amount of burned tokens in a corner case when the sender
has deleted (unregistered) their account while the mt_transfer_call was still in flight.
Returns (Used token amount, Burned token amount)
Trait Implementations§
source§impl BorshDeserialize for MultiFungibleTokenwhere
TreeMap<AccountId, MtToken>: BorshDeserialize,
StorageUsage: BorshDeserialize,
impl BorshDeserialize for MultiFungibleTokenwhere
TreeMap<AccountId, MtToken>: BorshDeserialize,
StorageUsage: BorshDeserialize,
source§impl BorshSerialize for MultiFungibleTokenwhere
TreeMap<AccountId, MtToken>: BorshSerialize,
StorageUsage: BorshSerialize,
impl BorshSerialize for MultiFungibleTokenwhere
TreeMap<AccountId, MtToken>: BorshSerialize,
StorageUsage: BorshSerialize,
source§impl MultiFungibleTokenCore for MultiFungibleToken
impl MultiFungibleTokenCore for MultiFungibleToken
source§fn mt_batch_transfer(
&mut self,
receiver_id: AccountId,
token_ids: Vec<AccountId>,
amounts: Vec<U128>,
memo: Option<String>
)
fn mt_batch_transfer(
&mut self,
receiver_id: AccountId,
token_ids: Vec<AccountId>,
amounts: Vec<U128>,
memo: Option<String>
)
amount of tokens from the env::predecessor_account_id to receiver_id.
Both accounts must be registered with the contract for transfer to succeed. (See NEP-145)
This method must to be able to accept attached deposits, and must not panic on attached deposit.
Exactly 1 yoctoNEAR must be attached.
See the Security section of the standard. Read moresource§fn mt_batch_transfer_call(
&mut self,
receiver_id: AccountId,
token_ids: Vec<AccountId>,
amounts: Vec<U128>,
memo: Option<String>,
msg: String
) -> PromiseOrValue<U128>
fn mt_batch_transfer_call(
&mut self,
receiver_id: AccountId,
token_ids: Vec<AccountId>,
amounts: Vec<U128>,
memo: Option<String>,
msg: String
) -> PromiseOrValue<U128>
amount of tokens from the env::predecessor_account_id to receiver_id account. Then
calls mt_on_transfer method on receiver_id contract and attaches a callback to resolve this transfer.
mt_on_transfer method must return the amount of tokens unused by the receiver contract, the remaining tokens
must be refunded to the predecessor_account_id at the resolve transfer callback. Read moresource§fn mt_total_supply(&self, token_id: AccountId) -> U128
fn mt_total_supply(&self, token_id: AccountId) -> U128
source§fn mt_balance_of(&self, account_id: AccountId, token_id: AccountId) -> U128
fn mt_balance_of(&self, account_id: AccountId, token_id: AccountId) -> U128
"0".fn mt_add_token(&mut self, token_id: AccountId)
source§impl StorageManagement for MultiFungibleToken
impl StorageManagement for MultiFungibleToken
source§fn storage_withdraw(
&mut self,
token_id: AccountId,
amount: Option<U128>
) -> StorageBalance
fn storage_withdraw(
&mut self,
token_id: AccountId,
amount: Option<U128>
) -> StorageBalance
While storage_withdraw normally allows the caller to retrieve available balance, the basic
MultiFungible Token implementation sets storage_balance_bounds.min == storage_balance_bounds.max,
which means available balance will always be 0. So this implementation:
- panics if
amount > 0 - never transfers Ⓝ to caller
- returns a
storage_balancestruct ifamountis 0