Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
35e32f7
WIP - SRML Assets Module README
ltfschoen Mar 7, 2019
2b11c74
docs: Tweaks for consistency
ltfschoen Mar 7, 2019
7fadb76
docs: Add missing newline
ltfschoen Mar 7, 2019
14d701d
review-fix: Remove non-SRML trait dependencies
ltfschoen Mar 8, 2019
bc16608
review-fix: Replace const with let
ltfschoen Mar 8, 2019
eaedc6c
review-fix: Remove use of compact in signature
ltfschoen Mar 8, 2019
b8fa0a7
review-fix: Change const to let since cannot use result of function call
ltfschoen Mar 8, 2019
dd69935
fix: Add backticks around type and mention type it derives from
ltfschoen Mar 8, 2019
94d2f3e
review-fix: Update variable names since changed to lowercase since us…
ltfschoen Mar 8, 2019
0383d9b
fix: Change type to bold instead of code
ltfschoen Mar 8, 2019
33465e1
review-fix: Update Asset module
ltfschoen Mar 20, 2019
93024da
refactor: Consistent bullet points. Remove whitespace between items
ltfschoen Mar 20, 2019
9d0c1bb
review-fix: Remove useless blah
ltfschoen Mar 23, 2019
f8ffcee
review-fix: Remove Storage Items
ltfschoen Mar 24, 2019
4852b4d
review-fix: Remove Types
ltfschoen Mar 24, 2019
0b63d4a
review-fix: Remove duplicate instructions
ltfschoen Mar 24, 2019
5979ba9
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
372271f
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
e53434d
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
9bbd04e
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
8814fc9
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
d335b65
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
e6e4391
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
e0f123f
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
d9e4284
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
b91d52a
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
d714424
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
75b04b1
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
8f2d0b9
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
31b8ad3
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
a2dab4d
Update srml/assets/src/lib.rs
joepetrowski Mar 25, 2019
0a80973
review-fix: Remove since will be replaced after macro expansion #2068…
ltfschoen Mar 25, 2019
cf3083e
review-fix: Move Goals within overview
ltfschoen Mar 25, 2019
57f99cf
fix: Fix indentation
ltfschoen Mar 25, 2019
76cd804
Merge remote-tracking branch 'origin/master' into luke-22-assets-modu…
joepetrowski Apr 1, 2019
d7d65cf
style and a few minor changes
joepetrowski Apr 1, 2019
0c4dcb7
remove Events
joepetrowski Apr 1, 2019
a3948e8
capitalization
joepetrowski Apr 5, 2019
ac9f29f
Merge branch 'master' into luke-22-assets-module-docs
ltfschoen Apr 10, 2019
319d763
docs: Reword the Goals to remove mention of cold wallets based on dis…
ltfschoen Apr 13, 2019
4334531
Wording
joepetrowski Apr 15, 2019
ef9f200
Update lib.rs
gavofyork Apr 23, 2019
0b75448
Update lib.rs
gavofyork Apr 23, 2019
1709427
Update lib.rs
gavofyork Apr 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 104 additions & 3 deletions srml/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,108 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! # 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 [`Trait`](./trait.Trait.html).
//!
//! The supported dispatchable functions are documented in the [`Call`](./enum.Call.html) 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 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.Call.html) enum and its associated variants for documentation on each function.
//!
//! ### Public Functions
//! <!-- Original author of descriptions: @gavofyork -->
//!
//! * `balance` - Get the asset `id` balance of `who`.
//! * `total_supply` - Get the total supply of an asset `id`.
//!
//! Please refer to the [`Module`](./struct.Module.html) 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
//!
//! ```rust,ignore
//! use support::{decl_module, dispatch::Result};
//! use system::ensure_signed;
//!
//! pub trait Trait: assets::Trait { }
//!
//! decl_module! {
//! pub struct Module<T: Trait> for enum Call where origin: T::Origin {
//! pub fn issue_token_airdrop(origin) -> Result {
//! const ACCOUNT_ALICE: u64 = 1;
//! const ACCOUNT_BOB: u64 = 2;
//! const COUNT_AIRDROP_RECIPIENTS = 2;
//! const TOKENS_FIXED_SUPPLY: u64 = 100;
//!
//! ensure!(!COUNT_AIRDROP_RECIPIENTS.is_zero(), "Divide by zero error.");
//!
//! let sender = ensure_signed(origin)?;
//! 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(())
//! }
//! }
//! }
//! ```
//!
//! ## Related Modules
//!
//! * [`System`](../srml_system/index.html)
//! * [`Support`](../srml_support/index.html)

// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
Expand All @@ -23,6 +124,7 @@ use srml_support::{StorageValue, StorageMap, Parameter, decl_module, decl_event,
use primitives::traits::{Member, SimpleArithmetic, Zero, StaticLookup};
use system::ensure_signed;

/// The module configuration trait.
pub trait Trait: system::Trait {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
Expand All @@ -34,7 +136,6 @@ pub trait Trait: system::Trait {
type AssetId = u32;

decl_module! {
// Simple declaration of the `Module` type. Lets the macro know what its working on.
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event<T>() = default;
/// Issue a new class of fungible assets. There are, and will only ever be, `total`
Expand Down Expand Up @@ -99,7 +200,7 @@ decl_storage! {
Balances: map (AssetId, T::AccountId) => T::Balance;
/// The next asset identifier up for grabs.
NextAssetId get(next_asset_id): AssetId;
/// The total unit supply of an asset
/// The total unit supply of an asset.
TotalSupply: map AssetId => T::Balance;
}
}
Expand All @@ -113,7 +214,7 @@ impl<T: Trait> Module<T> {
<Balances<T>>::get((id, who))
}

// Get the total supply of an asset `id`
/// Get the total supply of an asset `id`.
pub fn total_supply(id: AssetId) -> T::Balance {
<TotalSupply<T>>::get(id)
}
Expand Down