Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
74bcfcb
comment updates
joepetrowski Mar 6, 2019
a544d4a
Merge branch 'master' into joe-balances-docs
joepetrowski Mar 6, 2019
1cc5721
added rustdoc and readme
joepetrowski Mar 6, 2019
e4a3bf7
clarified LockableCurrency trait
joepetrowski Mar 6, 2019
3e4b5e4
Currency trait rustdocs
joepetrowski Mar 7, 2019
077cde2
fixed typo
joepetrowski Mar 7, 2019
dd16fd6
fixed suggestions round 1
joepetrowski Mar 8, 2019
ceeb172
UpdateBalanceOutcome docs (open for discussion)
joepetrowski Mar 8, 2019
05894ab
rm description of enum, consolidation, rm ReclaimRebate
joepetrowski Mar 9, 2019
a654735
type clarification, examples overhaul, adoc formatting
joepetrowski Mar 10, 2019
02110b2
adoc to md
joepetrowski Mar 11, 2019
53680af
format change for rustdoc
joepetrowski Mar 12, 2019
f1b62a4
update links and fix typos
joepetrowski Mar 12, 2019
499c239
typos and links
joepetrowski Mar 13, 2019
cf750f8
Merge remote-tracking branch 'origin/master' into joe-balances-docs
joepetrowski Mar 13, 2019
2cf4009
updates according to comments
joepetrowski Mar 13, 2019
d863ff6
new example
joepetrowski Mar 14, 2019
5e28748
small clarifications
joepetrowski Mar 14, 2019
c8ec45a
trait implementation section
joepetrowski Mar 14, 2019
36b1689
missing ```
joepetrowski Mar 14, 2019
3c157e4
small changes, ready for review
joepetrowski Mar 14, 2019
a0ef9b7
line width update
joepetrowski Mar 15, 2019
2d28117
Merge branch 'master' into joe-balances-docs
joepetrowski Mar 18, 2019
df3ced9
Merge branch 'master' into joe-balances-docs
joepetrowski Mar 21, 2019
e42f6b6
small tweaks
joepetrowski Mar 25, 2019
e000871
Update srml/balances/src/lib.rs
gui1117 Mar 25, 2019
faccdbf
Update srml/balances/src/lib.rs
gui1117 Mar 25, 2019
513b377
Update srml/balances/src/lib.rs
gui1117 Mar 25, 2019
ce29349
Update srml/balances/src/lib.rs
gui1117 Mar 25, 2019
fa9f215
Update lib.rs
joepetrowski Mar 25, 2019
28a1d33
address review by thiolliere
joepetrowski Mar 25, 2019
aa43b56
remove common warning
joepetrowski Mar 26, 2019
191ecc0
Merge remote-tracking branch 'origin/master' into joe-balances-docs
gavofyork Mar 26, 2019
665fa6b
Update docs
gavofyork Mar 26, 2019
5f391ae
updated srml example
joepetrowski Mar 26, 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
Prev Previous commit
Next Next commit
fixed suggestions round 1
  • Loading branch information
joepetrowski committed Mar 8, 2019
commit dd16fd608b31db669c9bc365ae76fb1b3fc239b8
12 changes: 6 additions & 6 deletions srml/balances/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ The dispatchable function `transfer` ensures that the sender has signed the tran

The following example shows how to use the balances module in your custom module.

1 Import the `balances` module and derive your module configuration trait with the balances trait.
1. Import the `balances` module and derive your module configuration trait with the balances trait.

```
```rust
use balances;

pub trait Trait: balances::Trait { }
```

2 In your module, call the balance module:
2. In your module, call the balance module:

```
```rust
// Get existential deposit
let ed = Balances::existential_deposit();

// Get transfer fee for the network
let tf = Balances::transfer_fee();
```

3 Include a balance transfer in a block (example from the `executor` module tests):
3. Include a balance transfer in a block (example from the `executor` module tests):

```
```rust
let mut t = new_test_ext(COMPACT_CODE, false);
let block1 = construct_block(
&mut t,
Expand Down
17 changes: 11 additions & 6 deletions srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ impl<T: Trait> Module<T> {
/// Doesn't do any preparatory work for creating a new account, so should only be used when it
/// is known that the account already exists.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to have a standardized preconditions documentation section, many method here have preconditions that have to be meet in order to ensure consistency.

///
/// Returns either `Updated` or `AccountKilled`.
/// Returns `Updated` if the account was successfully updated
/// or `AccountKilled` if the update has led to killing the account.
pub fn set_reserved_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
if balance < Self::existential_deposit() {
<ReservedBalance<T>>::insert(who, balance);
Expand All @@ -249,7 +250,8 @@ impl<T: Trait> Module<T> {
/// Doesn't do any preparatory work for creating a new account, so should only be used when it
/// is known that the account already exists.
///
/// Returns either `Updated` or `AccountKilled`.
/// Returns `Updated` if the account was successfully updated
/// or `AccountKilled` if the update has led to killing the account.
pub fn set_free_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
// Commented out for now - but consider it instructive.
// assert!(!Self::total_balance(who).is_zero());
Expand All @@ -268,7 +270,8 @@ impl<T: Trait> Module<T> {
///
/// Same as `set_free_balance`, but will create a new account.
///
/// Returns either `Updated` or `AccountKilled`.
/// Returns `Updated` if the account was successfully updated
/// or `AccountKilled` if the update has led to killing the account.
pub fn set_free_balance_creating(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
let ed = <Module<T>>::existential_deposit();
// If the balance is too low, then the account is reaped.
Expand Down Expand Up @@ -296,9 +299,11 @@ impl<T: Trait> Module<T> {

/// Transfer some liquid free balance from one account to another.
///
/// Enforces `ExistentialDeposit` law, reaping the sender's account if it's balance is
/// Enforces `ExistentialDeposit` law, reaping the sender's account if its balance is
/// too low as a result of the transfer.
///
/// #NOTES
///
/// Will create a new account for the destination if the account does not exist.
pub fn make_transfer(transactor: &T::AccountId, dest: &T::AccountId, value: T::Balance) -> Result {
let from_balance = Self::free_balance(transactor);
Expand Down Expand Up @@ -371,14 +376,14 @@ impl<T: Trait> Module<T> {
}
}

/// Increase `TotalIssuance` by `value`.
/// Increase stake by `value`.
pub fn increase_total_stake_by(value: T::Balance) {
if let Some(v) = <Module<T>>::total_issuance().checked_add(&value) {
<TotalIssuance<T>>::put(v);
}
}

/// Decrease `TotalIssuance` by `value`.
/// Decrease stake by `value`.
pub fn decrease_total_stake_by(value: T::Balance) {
if let Some(v) = <Module<T>>::total_issuance().checked_sub(&value) {
<TotalIssuance<T>>::put(v);
Expand Down
9 changes: 6 additions & 3 deletions srml/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ pub trait Currency<AccountId> {
/// Returns `Updated` if the account was successfully updated
/// or `AccountKilled` if the update has led to killing the account.
///
/// NOTE: This assumes that the total stake remains unchanged after this operation.
/// #NOTES
///
/// This assumes that the total stake remains unchanged after this operation.
fn increase_free_balance_creating(who: &AccountId, value: Self::Balance) -> UpdateBalanceOutcome;

/// Moves `value` from balance to reserved balance.
Expand All @@ -154,9 +156,10 @@ pub trait Currency<AccountId> {
/// is less than `value`, then `Some(remaining)` will be returned. If all of `value` is
/// moved, the function will return `None`.
///
/// NOTE: This is different to `reserve`.
/// #NOTES
///
/// NOTE: If the remaining reserved balance is less than `ExistentialDeposit`, it will
/// - This is different to `reserve`.
/// - If the remaining reserved balance is less than `ExistentialDeposit`, it will
/// invoke `on_reserved_too_low` and could reap the account.
fn unreserve(who: &AccountId, value: Self::Balance) -> Option<Self::Balance>;

Expand Down