| Crates.io | noble-assets |
| lib.rs | noble-assets |
| version | 2.0.1 |
| created_at | 2021-04-04 05:43:26.893674+00 |
| updated_at | 2021-04-04 05:43:26.893674+00 |
| description | FABRIC asset management noble |
| homepage | https://core.tetcoin.org |
| repository | https://github.com/tetcoin/tetcore |
| max_upload_size | |
| id | 378645 |
| size | 84,740 |
A simple, secure module for dealing with fungible assets.
The Assets module provides functionality for asset management of fungible asset classes with a fixed supply, including:
To use it in your runtime, you need to implement the assets assets::Trait.
The supported dispatchable functions are documented in the assets::Call enum.
The assets system in Tetcore is designed to make the following possible:
issue - Issues the total supply of a new fungible asset to the account of the caller of the function.transfer - Transfers an amount of units of fungible asset id from the balance of
the function caller's account (origin) to a target account.destroy - Destroys the entire holding of a fungible asset id associated with the account
that called the function.Please refer to the Call enum and its associated variants for documentation on each function.
balance - Get the asset id balance of who.total_supply - Get the total supply of an asset id.Please refer to the Module struct for details on publicly available functions.
The following example shows how to use the Assets module in your runtime by exposing public functions to:
Import the Assets module and types and derive your runtime's configuration traits from the Assets module trait.
use noble_assets as assets;
use fabric_support::{decl_module, dispatch, ensure};
use fabric_system::ensure_signed;
pub trait Config: assets::Config { }
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
pub fn issue_token_airdrop(origin) -> dispatch::DispatchResult {
let sender = ensure_signed(origin).map_err(|e| e.as_str())?;
const ACCOUNT_ALICE: u64 = 1;
const ACCOUNT_BOB: u64 = 2;
const COUNT_AIRDROP_RECIPIENTS: u64 = 2;
const TOKENS_FIXED_SUPPLY: u64 = 100;
ensure!(!COUNT_AIRDROP_RECIPIENTS.is_zero(), "Divide by zero error.");
let asset_id = Self::next_asset_id();
<NextAssetId<T>>::mutate(|asset_id| *asset_id += 1);
<Balances<T>>::insert((asset_id, &ACCOUNT_ALICE), TOKENS_FIXED_SUPPLY / COUNT_AIRDROP_RECIPIENTS);
<Balances<T>>::insert((asset_id, &ACCOUNT_BOB), TOKENS_FIXED_SUPPLY / COUNT_AIRDROP_RECIPIENTS);
<TotalSupply<T>>::insert(asset_id, TOKENS_FIXED_SUPPLY);
Self::deposit_event(RawEvent::Issued(asset_id, sender, TOKENS_FIXED_SUPPLY));
Ok(())
}
}
}
Below are assumptions that must be held when using this module. If any of them are violated, the behavior of this module is undefined.
Config::AssetId::max_value().License: Apache-2.0