Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 10 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
108 changes: 108 additions & 0 deletions srml/assets/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Assets Module

## Overview

The assets module provides functionality for asset management of fungible asset classes with a fixed supply, including:

* Asset Issuance
* Asset Transfer
* Asset Destruction

The SRML Support Module implements the `Currency` trait abstraction over the SRML Assets Module's fungible assets system.

### Types

* `AssetId`: `u32`

## Public Interface

### Supported Origins

**signed** - Used to issue, transfer, and destroy an asset holding.

### Public Immutable functions (getters)

#### `balance(id: AssetId, who: T::AccountId) -> T::Balance`

#### `total_supply(id: AssetId) -> T::Balance`

### Public Mutable functions (changing state)

#### `issue(origin, total: T::Balance)`

#### `transfer(origin, id: AssetId, target: <T::Lookup as StaticLookup>::Source, amount: T::Balance)`

#### `destroy(origin, id: AssetId)`

### Events:

#### `Issued(AssetId, AccountId, Balance)`

#### `Transferred(AssetId, AccountId, AccountId, Balance)`

#### `Destroyed(AssetId, AccountId, Balance)`

## Usage

The following example shows how to use the Asset Module in your custom module to query an account's asset holding, and query the total supply of an asset and an account's asset holding balance.

**1. Import Asset Module and Types**

Import the `assets` module and derive your custom module configuration traits from the `assets` module trait.

```rust
use assets;

pub trait Trait: assets::Trait { }
```

**2. Import Accounts**

```rust
const ALICE: u64 = 1;
const BOB: u64 = 2;

// Initial Asset ID is 0
let initial_asset_id: u32 = <assets::Module<T>>::next_asset_id();
const FIXED_SUPPLY: u64 = 100;
```

**3. Issue a new Fungible Asset to an Account**

Issue the `total` amount of a new class of fungible asset with a fixed supply of units to a signed sender's (`origin`) account (i.e. Alice) and trigger the `Issued` event that contains the generated `AssetId`.

```rust
<assets::Module<T>>::issue(Origin::signed(&ALICE), FIXED_SUPPLY);
```

**4. Transfer a Fungible Asset between Accounts**

Transfer a signed sender's (i.e. Alice) account holding of an asset's `AssetId` to a `target` recipient account (i.e. Bob) using the public call `transfer`. It only triggers the `Transferred` event if the transfer is valid.

```rust
<assets::Module<T>>::transfer(Origin::signed(&ALICE), initial_asset_id, BOB, FIXED_SUPPLY);
```

**5. Destroy the Fungible Asset holding of an Account**

Destroy a signed sender's (i.e. Alice) entire account holding of a fungible asset and trigger the `Destroyed` event if they have a non-zero balance.

```rust
<assets::Module<T>>::destroy(Origin::signed(&ALICE), initial_asset_id);
```

**6. Query the Fungible Asset holding of an Account**

Query an account's holding balance (i.e. Alice) of a fungible asset by calling the asset module's `balance` function.

```rust
let balance = <assets::Module<T>>::balance(initial_asset_id, Origin::signed(&ALICE));
```

**7. Query the Total Supply of a Fungible Asset**

Query the total supply of a fungible asset that has been issued by calling the asset module's `total_supply` function.

```rust
let total_supply = <assets::Module<T>>::total_supply(initial_asset_id);
```