This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Documentation for assets module #1945
Merged
Merged
Changes from 13 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
35e32f7
WIP - SRML Assets Module README
ltfschoen 2b11c74
docs: Tweaks for consistency
ltfschoen 7fadb76
docs: Add missing newline
ltfschoen 14d701d
review-fix: Remove non-SRML trait dependencies
ltfschoen bc16608
review-fix: Replace const with let
ltfschoen eaedc6c
review-fix: Remove use of compact in signature
ltfschoen b8fa0a7
review-fix: Change const to let since cannot use result of function call
ltfschoen dd69935
fix: Add backticks around type and mention type it derives from
ltfschoen 94d2f3e
review-fix: Update variable names since changed to lowercase since us…
ltfschoen 0383d9b
fix: Change type to bold instead of code
ltfschoen 33465e1
review-fix: Update Asset module
ltfschoen 93024da
refactor: Consistent bullet points. Remove whitespace between items
ltfschoen 9d0c1bb
review-fix: Remove useless blah
ltfschoen f8ffcee
review-fix: Remove Storage Items
ltfschoen 4852b4d
review-fix: Remove Types
ltfschoen 0b63d4a
review-fix: Remove duplicate instructions
ltfschoen 5979ba9
Update srml/assets/src/lib.rs
joepetrowski 372271f
Update srml/assets/src/lib.rs
joepetrowski e53434d
Update srml/assets/src/lib.rs
joepetrowski 9bbd04e
Update srml/assets/src/lib.rs
joepetrowski 8814fc9
Update srml/assets/src/lib.rs
joepetrowski d335b65
Update srml/assets/src/lib.rs
joepetrowski e6e4391
Update srml/assets/src/lib.rs
joepetrowski e0f123f
Update srml/assets/src/lib.rs
joepetrowski d9e4284
Update srml/assets/src/lib.rs
joepetrowski b91d52a
Update srml/assets/src/lib.rs
joepetrowski d714424
Update srml/assets/src/lib.rs
joepetrowski 75b04b1
Update srml/assets/src/lib.rs
joepetrowski 8f2d0b9
Update srml/assets/src/lib.rs
joepetrowski 31b8ad3
Update srml/assets/src/lib.rs
joepetrowski a2dab4d
Update srml/assets/src/lib.rs
joepetrowski 0a80973
review-fix: Remove since will be replaced after macro expansion #2068…
ltfschoen cf3083e
review-fix: Move Goals within overview
ltfschoen 57f99cf
fix: Fix indentation
ltfschoen 76cd804
Merge remote-tracking branch 'origin/master' into luke-22-assets-modu…
joepetrowski d7d65cf
style and a few minor changes
joepetrowski 0c4dcb7
remove Events
joepetrowski a3948e8
capitalization
joepetrowski ac9f29f
Merge branch 'master' into luke-22-assets-module-docs
ltfschoen 319d763
docs: Reword the Goals to remove mention of cold wallets based on dis…
ltfschoen 4334531
Wording
joepetrowski ef9f200
Update lib.rs
gavofyork 0b75448
Update lib.rs
gavofyork 1709427
Update lib.rs
gavofyork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,149 @@ | |
| // 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 | ||
| //! <!-- Original author of paragraph: @gavofyork --> | ||
| //! | ||
| //! A simple, secure module for dealing with fungible assets. | ||
| //! | ||
| //! Run `cargo doc --package srml-assets --open` to view this module's documentation. | ||
| //! | ||
| //! ## 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 module, you need to implement the assets [`Trait`].<br /> | ||
| //! The supported dispatchable functions are documented in the [`Call`] enum. | ||
| //! | ||
| //! ## Terminology | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! * **Asset issuance:** The process of an account issuing a total fixed supply of a new asset class. | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! * **Asset transfer:** The process of an account transfering units of their holding of an asset to a recipient. | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! * **Asset destruction:** The process of an account destroying their entire holding of an asset. | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! * **Fungible asset:** An asset that may be interchanged into an identical equivalent. | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! * **Non-fungible asset:** An asset that is scarce and offers unique characteristics. | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! ## Goals | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! <!-- Original inspiration of paragraph: @gavofyork / staking module documentation --> | ||
| //! <!-- FIXME - assumptions only. require an expert to peer review (or re-write) --> | ||
| //! | ||
| //! The assets system in Substrate is designed to achieve the following goals: | ||
| //! * It should be possible to create a unique fungible asset. | ||
| //! * It should be possible to issue fungible assets that are controlled by a cold wallet. | ||
| //! * It should be possible to transfer fungible assets between cold wallets. | ||
|
||
| //! * It should be possible to destroy a proportion of fungible assets that are controlled by a cold wallet. | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! ## Interface | ||
| //! | ||
| //! ### Supported Origins | ||
| //! | ||
| //! **signed** - Used to issue, transfer, and destroy an asset holding. | ||
| //! | ||
| //! ### Types | ||
| //! | ||
| //! * `AssetId`: `u32` | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! ### Dispatchable Functions ([`Call`]) | ||
| //! | ||
| //! * `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 a fungible asset `id` from the balance of the sender's account (`origin`) that called the function to a `target` account. | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! * `destroy` - Destroys the entire holding of a fungible asset `id` associated with the account that called the function from its total supply. | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! Please refer to the [`Call`] enum and its associated variants for a detailed list of dispatchable functions. | ||
| //! | ||
| //! ### Public Functions ([`Module`]) | ||
| //! <!-- 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`] enum for details of publicly available functions. | ||
| //! | ||
| //! <!-- Original author of paragraph: @Kianenigma --> | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! Note that when using the publicly exposed functions, you (the runtime developer) are responsible for implementing any necessary checks (e.g. that the sender is the signer) before calling a function that will affect storage. | ||
| //! | ||
| //! ### Storage Items: | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! * Balances | ||
| //! * NextAssetId | ||
| //! * TotalSupply | ||
| //! | ||
| //! Please refer to the <a href="https://github.com/paritytech/substrate/blob/master/srml/assets/src/lib.rs#L99" target="_blank">`decl_storage!`</a> block in the Asset SRML source code for details of storage items. | ||
| //! | ||
| //! ### Events: | ||
| //! | ||
| //! * [`Issued`](https://crates.parity.io/srml_system/enum.RawEvent.html#variants) | ||
| //! * [`Transferred`](https://crates.parity.io/srml_system/enum.RawEvent.html#variants) | ||
| //! * [`Destroyed`](https://crates.parity.io/srml_system/enum.RawEvent.html#variants) | ||
| //! | ||
| //! Please refer to the [`RawEvent`] enum and its associated variants for a detailed list of events. | ||
| //! | ||
| //! ## Usage | ||
| //! | ||
| //! The following example shows how to use the Asset Module in your custom module by exposing public functions to: | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! * 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 custom module configuration traits from the `assets` module trait. | ||
| //! | ||
| //! ### Simple Code Snippet | ||
| //! <!-- Original author of example approach: @gautamdhameja, @shawntabrizi. See documentation for other SRML modules --> | ||
| //! | ||
| //! ```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 get_time(origin) -> Result { | ||
| //! let _sender = ensure_signed(origin)?; | ||
| //! let _now = <timestamp::Module<T>>::get(); | ||
| //! Ok(()) | ||
| //! } | ||
| //! | ||
| //! pub fn issue_token_airdrop(origin) -> Results { | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! const ACCOUNT_ALICE: u64 = 1; | ||
joepetrowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! const ACCOUNT_BOB: u64 = 2; | ||
| //! const COUNT_AIRDROP_RECIPIENTS = 2; | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! const TOKENS_FIXED_SUPPLY: u64 = 100; | ||
| //! let _sender = ensure_signed(origin)?; | ||
| //! let _asset_id = Self::next_asset_id(); | ||
| //! | ||
joepetrowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| //! <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, origin, TOKENS_FIXED_SUPPLY)); | ||
| //! Ok(()) | ||
| //! } | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! pub fn get_balance(asset_id, who) -> Result { | ||
| //! let _balance = <assets::Module<T>>::balance::get(asset_id, who); | ||
ltfschoen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! Ok(()) | ||
| //! } | ||
| //! | ||
| //! pub fn get_total_supply(asset_id) -> Result { | ||
| //! let _total_supply = <assets::Module<T>>::total_supply::get(asset_id); | ||
| //! Ok(()) | ||
| //! } | ||
| //! } | ||
| //! } | ||
| //! ``` | ||
| //! | ||
| //! ## Related Modules | ||
| //! | ||
| //! * [`System`](https://crates.parity.io/srml_system/index.html) | ||
| //! * [`Support`](https://crates.parity.io/srml_support/index.html) | ||
|
|
||
| // Ensure we're `no_std` when compiling for Wasm. | ||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
@@ -23,6 +165,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>; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.