Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduce treasury and document #646

Merged
merged 17 commits into from
Sep 4, 2018
Prev Previous commit
Next Next commit
Fixes.
gavofyork committed Sep 3, 2018
commit 34b9838ab5b7c78ab7bfa29490ac4896e41d57c0
11 changes: 11 additions & 0 deletions substrate/runtime/balances/src/lib.rs
Original file line number Diff line number Diff line change
@@ -410,6 +410,17 @@ impl<T: Trait> Module<T> {
}
}

/// Adds up to `value` to the free balance of `who`. If `who` doesn't exist, it is created.
///
/// This is a sensitive function since it circumvents any fees associated with account
/// setup. Ensure it is only called by trusted code.
///
/// NOTE: This assumes that the total stake remains unchanged after this operation. If
/// you mean to actually mint value into existence, then use `reward` instead.
pub fn increase_free_balance_creating(who: &T::AccountId, value: T::Balance) -> UpdateBalanceOutcome {
Self::set_free_balance_creating(who, Self::free_balance(who) + value)
}

/// Deducts up to `value` from the combined balance of `who`, preferring to deduct from the
/// free balance. This function cannot fail.
///
16 changes: 8 additions & 8 deletions substrate/runtime/example/src/lib.rs
Original file line number Diff line number Diff line change
@@ -349,7 +349,7 @@ mod tests {
impl Trait for Test {
type Event = ();
}
type Treasury = Module<Test>;
type Example = Module<Test>;

// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
@@ -367,19 +367,19 @@ mod tests {
fn it_works() {
with_externalities(&mut new_test_ext(), || {
// Check that GenesisBuilder works properly.
assert_eq!(Treasury::dummy(), Some(42));
assert_eq!(Example::dummy(), Some(42));

// Check that accumulate works when we have Some value in Dummy already.
assert_ok!(Treasury::accumulate_dummy(27.into()));
assert_eq!(Treasury::dummy(), Some(69));
assert_ok!(Example::accumulate_dummy(27.into()));
assert_eq!(Example::dummy(), Some(69));

// Check that finalising the block removes Dummy from storage.
<Treasury as OnFinalise<u64>>::on_finalise(1);
assert_eq!(Treasury::dummy(), None);
<Example as OnFinalise<u64>>::on_finalise(1);
assert_eq!(Example::dummy(), None);

// Check that accumulate works when we Dummy has None in it.
assert_ok!(Treasury::accumulate_dummy(42.into()));
assert_eq!(Treasury::dummy(), Some(42));
assert_ok!(Example::accumulate_dummy(42.into()));
assert_eq!(Example::dummy(), Some(42));
});
}
}
Loading