enhance dispatch (#720)

* normalize decl_storage

* dispatch the function call

* add test case

* fix the root case

* add system

* fix the typo in unit test

* fix the doc generation for decl_module

* fix the unit test due to the interface change
This commit is contained in:
Guanqun Lu
2018-09-12 21:56:37 +08:00
committed by Gav Wood
parent 1e01162505
commit 4685018991
11 changed files with 214 additions and 104 deletions
+3 -4
View File
@@ -48,7 +48,7 @@ use runtime_support::dispatch::Result;
use primitives::traits::{Zero, One, SimpleArithmetic, OnFinalise, MakePayment,
As, Lookup, Member, CheckedAdd, CheckedSub};
use address::Address as RawAddress;
use system::{ensure_signed, ensure_root};
use system::ensure_signed;
mod mock;
@@ -131,7 +131,7 @@ pub trait Trait: system::Trait {
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn transfer(origin, dest: RawAddress<T::AccountId, T::AccountIndex>, value: T::Balance) -> Result;
fn set_balance(origin, who: RawAddress<T::AccountId, T::AccountIndex>, free: T::Balance, reserved: T::Balance) -> Result;
fn set_balance(who: RawAddress<T::AccountId, T::AccountIndex>, free: T::Balance, reserved: T::Balance) -> Result;
}
}
@@ -313,8 +313,7 @@ impl<T: Trait> Module<T> {
}
/// Set the balances of a given account.
fn set_balance(origin: T::Origin, who: Address<T>, free: T::Balance, reserved: T::Balance) -> Result {
ensure_root(origin)?;
fn set_balance(who: Address<T>, free: T::Balance, reserved: T::Balance) -> Result {
let who = Self::lookup(who)?;
Self::set_free_balance(&who, free);
Self::set_reserved_balance(&who, reserved);