Substrate中assets模块
一个处理可分割资产的简单、安全的模块。这个模块太简单,可以深入看看generic-asset模块。
Trait
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
/// 余额记录
type Balance: Member + Parameter + SimpleArithmetic + Default + Copy;
/// 资产identifier
type AssetId: Parameter + SimpleArithmetic + Default + Copy;
Storage
/// 账号余额记录
Balances: map (T::AssetId, T::AccountId) => T::Balance;
/// 下一个资产identifier
NextAssetId get(fn next_asset_id): T::AssetId;
/// 某个资产的总发行量
TotalSupply: map T::AssetId => T::Balance;
Module
- fn issue(origin,#[compact] total: T::Balance)
- 发行资产
- fn transfer(origin,#[compact] id: T::AssetId,target: <T::Lookup as StaticLookup>::Source, #[compact] amount: T::Balance)
- 转账
- fn destroy(origin, #[compact] id: T::AssetId)
- 销毁资产
- pub fn balance(id: T::AssetId, who: T::AccountId) -> T::Balance
- 查询某个用户某个资产的余额
- pub fn total_supply(id: T::AssetId) -> T::Balance
- 获取某个资产的发行总量
Event
decl_event!(
pub enum Event<T>
where <T as system::Trait>::AccountId,
<T as Trait>::Balance,
<T as Trait>::AssetId {
/// Some assets were issued.
Issued(AssetId, AccountId, Balance),
/// Some assets were transferred.
Transferred(AssetId, AccountId, AccountId, Balance),
/// Some assets were destroyed.
Destroyed(AssetId, AccountId, Balance),
}
);






网友评论