* Initial work * Tests for frame system * Self-sufficient account ref-counting * Fixes * Benchmarks building. * Update frame/system/src/lib.rs Co-authored-by: Jaco Greeff <jacogr@gmail.com> * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Test approvals * Fixes * Report assets pallet tests * Tests for approvals & force_cancel_approval * Use structs rather than tuples for approval data * Add force_asset_status, force_set_metadata * Add clear_metadata. * approval benchmarks * force_asset_status benchmarks * final benchmarks * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/system/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Docs for new approval dispatches. * Docs for pallet. * Remove accidental code. * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Fixes * Update frame/assets/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Grumbles. * Transfer zero works, use DispatchResult * fix test * Remove force_destroy * Remove TODO * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs * transfer_keep_alive * Fixes * Fixes * Fixes * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs Co-authored-by: Jaco Greeff <jacogr@gmail.com> Co-authored-by: Parity Benchmarking Bot <admin@parity.io> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Assets Module
A simple, secure module for dealing with fungible assets.
Overview
The Assets module provides functionality for asset management of fungible asset classes with a fixed supply, including:
- Asset Issuance
- Asset Transfer
- Asset Destruction
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.
Terminology
- Asset issuance: The creation of a new asset, whose total supply will belong to the account that issues the asset.
- Asset transfer: The action of transferring assets from one account to another.
- Asset destruction: The process of an account removing its entire holding of an asset.
- Fungible asset: An asset whose units are interchangeable.
- Non-fungible asset: An asset for which each unit has unique characteristics.
Goals
The assets system in Substrate is designed to make the following possible:
- Issue a unique asset to its creator's account.
- Move assets between accounts.
- Remove an account's balance of an asset when requested by that account's owner and update the asset's total supply.
Interface
Dispatchable Functions
issue- Issues the total supply of a new fungible asset to the account of the caller of the function.transfer- Transfers anamountof units of fungible assetidfrom the balance of the function caller's account (origin) to atargetaccount.destroy- Destroys the entire holding of a fungible assetidassociated with the account that called the function.
Please refer to the Call enum and its associated variants for documentation on each function.
Public Functions
balance- Get the assetidbalance ofwho.total_supply- Get the total supply of an assetid.
Please refer to the Module struct for details on publicly available functions.
Usage
The following example shows how to use the Assets module in your runtime by exposing public functions to:
- Issue a new fungible asset for a token distribution event (airdrop).
- Query the fungible asset holding balance of an account.
- Query the total supply of a fungible asset that has been issued.
Prerequisites
Import the Assets module and types and derive your runtime's configuration traits from the Assets module trait.
Simple Code Snippet
use pallet_assets as assets;
use frame_support::{decl_module, dispatch, ensure};
use frame_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(())
}
}
}
Assumptions
Below are assumptions that must be held when using this module. If any of them are violated, the behavior of this module is undefined.
- The total count of assets should be less than
Config::AssetId::max_value().
Related Modules
License: Apache-2.0