diff --git a/srml/balances/src/lib.rs b/srml/balances/src/lib.rs index c14cd6235787d..e7c7caa82c6ef 100644 --- a/srml/balances/src/lib.rs +++ b/srml/balances/src/lib.rs @@ -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 for enum Call where origin: T::Origin { fn transfer(origin, dest: RawAddress, value: T::Balance) -> Result; - fn set_balance(origin, who: RawAddress, free: T::Balance, reserved: T::Balance) -> Result; + fn set_balance(who: RawAddress, free: T::Balance, reserved: T::Balance) -> Result; } } @@ -313,8 +313,7 @@ impl Module { } /// Set the balances of a given account. - fn set_balance(origin: T::Origin, who: Address, free: T::Balance, reserved: T::Balance) -> Result { - ensure_root(origin)?; + fn set_balance(who: Address, free: T::Balance, reserved: T::Balance) -> Result { let who = Self::lookup(who)?; Self::set_free_balance(&who, free); Self::set_reserved_balance(&who, reserved); diff --git a/srml/consensus/src/lib.rs b/srml/consensus/src/lib.rs index 40da2f25af0fb..522515d29b617 100644 --- a/srml/consensus/src/lib.rs +++ b/srml/consensus/src/lib.rs @@ -48,7 +48,7 @@ use runtime_support::storage::StorageValue; use runtime_support::storage::unhashed::StorageVec; use primitives::traits::{MaybeSerializeDebug, OnFinalise, Member, DigestItem}; use primitives::bft::MisbehaviorReport; -use system::{ensure_signed, ensure_inherent, ensure_root}; +use system::{ensure_signed, ensure_inherent}; #[cfg(any(feature = "std", test))] use substrate_primitives::Blake2Hasher; @@ -132,8 +132,8 @@ decl_module! { fn report_misbehavior(origin, report: MisbehaviorReport) -> Result; fn note_offline(origin, offline_val_indices: Vec) -> Result; fn remark(origin, remark: Vec) -> Result; - fn set_code(origin, new: Vec) -> Result; - fn set_storage(origin, items: Vec) -> Result; + fn set_code(new: Vec) -> Result; + fn set_storage(items: Vec) -> Result; } } @@ -144,15 +144,13 @@ impl Module { } /// Set the new code. - fn set_code(origin: T::Origin, new: Vec) -> Result { - ensure_root(origin)?; + fn set_code(new: Vec) -> Result { storage::unhashed::put_raw(CODE, &new); Ok(()) } /// Set some items of storage. - fn set_storage(origin: T::Origin, items: Vec) -> Result { - ensure_root(origin)?; + fn set_storage(items: Vec) -> Result { for i in &items { storage::unhashed::put_raw(&i.0, &i.1); } diff --git a/srml/council/src/seats.rs b/srml/council/src/seats.rs index 8941dbeccb919..4a7c0e3be8b9b 100644 --- a/srml/council/src/seats.rs +++ b/srml/council/src/seats.rs @@ -22,7 +22,7 @@ use runtime_io::print; use srml_support::{StorageValue, StorageMap, dispatch::Result}; use democracy; use balances::{self, address::Address}; -use system::{self, ensure_signed, ensure_root}; +use system::{self, ensure_signed}; // no polynomial attacks: // @@ -92,10 +92,10 @@ decl_module! { fn submit_candidacy(origin, slot: u32) -> Result; fn present_winner(origin, candidate: Address, total: T::Balance, index: VoteIndex) -> Result; - fn set_desired_seats(origin, count: u32) -> Result; - fn remove_member(origin, who: Address) -> Result; - fn set_presentation_duration(origin, count: T::BlockNumber) -> Result; - fn set_term_duration(origin, count: T::BlockNumber) -> Result; + fn set_desired_seats(count: u32) -> Result; + fn remove_member(who: Address) -> Result; + fn set_presentation_duration(count: T::BlockNumber) -> Result; + fn set_term_duration(count: T::BlockNumber) -> Result; } } @@ -406,8 +406,7 @@ impl Module { /// Set the desired member count; if lower than the current count, then seats will not be up /// election when they expire. If more, then a new vote will be started if one is not already /// in progress. - fn set_desired_seats(origin: T::Origin, count: u32) -> Result { - ensure_root(origin)?; + fn set_desired_seats(count: u32) -> Result { >::put(count); Ok(()) } @@ -415,8 +414,7 @@ impl Module { /// Remove a particular member. A tally will happen instantly (if not already in a presentation /// period) to fill the seat if removal means that the desired members are not met. /// This is effective immediately. - fn remove_member(origin: T::Origin, who: Address) -> Result { - ensure_root(origin)?; + fn remove_member(who: Address) -> Result { let who = >::lookup(who)?; let new_council: Vec<(T::AccountId, T::BlockNumber)> = Self::active_council() .into_iter() @@ -428,16 +426,14 @@ impl Module { /// Set the presentation duration. If there is currently a vote being presented for, will /// invoke `finalise_vote`. - fn set_presentation_duration(origin: T::Origin, count: T::BlockNumber) -> Result { - ensure_root(origin)?; + fn set_presentation_duration(count: T::BlockNumber) -> Result { >::put(count); Ok(()) } /// Set the presentation duration. If there is current a vote being presented for, will /// invoke `finalise_vote`. - fn set_term_duration(origin: T::Origin, count: T::BlockNumber) -> Result { - ensure_root(origin)?; + fn set_term_duration(count: T::BlockNumber) -> Result { >::put(count); Ok(()) } @@ -1073,7 +1069,7 @@ mod tests { assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::set_desired_seats(Origin::ROOT, 3)); + assert_ok!(Council::set_desired_seats(3)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); @@ -1326,7 +1322,7 @@ mod tests { System::set_block_number(8); assert_ok!(Council::set_approvals(Origin::signed(6), vec![false, false, true, false], 1)); - assert_ok!(Council::set_desired_seats(Origin::ROOT, 3)); + assert_ok!(Council::set_desired_seats(3)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); diff --git a/srml/council/src/voting.rs b/srml/council/src/voting.rs index 886adfc7bf664..b31c493141715 100644 --- a/srml/council/src/voting.rs +++ b/srml/council/src/voting.rs @@ -24,7 +24,7 @@ use srml_support::dispatch::Result; use srml_support::{StorageValue, StorageMap, IsSubType}; use {system, democracy}; use super::{Trait as CouncilTrait, Module as Council}; -use system::{ensure_signed, ensure_root}; +use system::ensure_signed; pub trait Trait: CouncilTrait { type Event: From> + Into<::Event>; @@ -36,8 +36,8 @@ decl_module! { fn vote(origin, proposal: T::Hash, approve: bool) -> Result; fn veto(origin, proposal_hash: T::Hash) -> Result; - fn set_cooloff_period(origin, blocks: T::BlockNumber) -> Result; - fn set_voting_period(origin, blocks: T::BlockNumber) -> Result; + fn set_cooloff_period(blocks: T::BlockNumber) -> Result; + fn set_voting_period(blocks: T::BlockNumber) -> Result; } } @@ -155,14 +155,12 @@ impl Module { Ok(()) } - fn set_cooloff_period(origin: T::Origin, blocks: T::BlockNumber) -> Result { - ensure_root(origin)?; + fn set_cooloff_period(blocks: T::BlockNumber) -> Result { >::put(blocks); Ok(()) } - fn set_voting_period(origin: T::Origin, blocks: T::BlockNumber) -> Result { - ensure_root(origin)?; + fn set_voting_period(blocks: T::BlockNumber) -> Result { >::put(blocks); Ok(()) } diff --git a/srml/democracy/src/lib.rs b/srml/democracy/src/lib.rs index f74f37094d8ae..f540aa60ceaf4 100644 --- a/srml/democracy/src/lib.rs +++ b/srml/democracy/src/lib.rs @@ -46,7 +46,7 @@ use rstd::result; use primitives::traits::{Zero, OnFinalise, As, MaybeSerializeDebug}; use srml_support::{StorageValue, StorageMap, Parameter, Dispatchable, IsSubType}; use srml_support::dispatch::Result; -use system::{ensure_signed, ensure_root}; +use system::ensure_signed; #[cfg(any(feature = "std", test))] use std::collections::HashMap; @@ -71,8 +71,8 @@ decl_module! { fn second(origin, proposal: PropIndex) -> Result; fn vote(origin, ref_index: ReferendumIndex, approve_proposal: bool) -> Result; - fn start_referendum(origin, proposal: Box, vote_threshold: VoteThreshold) -> Result; - fn cancel_referendum(origin, ref_index: ReferendumIndex) -> Result; + fn start_referendum(proposal: Box, vote_threshold: VoteThreshold) -> Result; + fn cancel_referendum(ref_index: ReferendumIndex) -> Result; } } @@ -215,8 +215,7 @@ impl Module { } /// Start a referendum. - fn start_referendum(origin: T::Origin, proposal: Box, vote_threshold: VoteThreshold) -> Result { - ensure_root(origin)?; + fn start_referendum(proposal: Box, vote_threshold: VoteThreshold) -> Result { Self::inject_referendum( >::block_number() + Self::voting_period(), *proposal, @@ -225,8 +224,7 @@ impl Module { } /// Remove a referendum. - fn cancel_referendum(origin: T::Origin, ref_index: ReferendumIndex) -> Result { - ensure_root(origin)?; + fn cancel_referendum(ref_index: ReferendumIndex) -> Result { Self::clear_referendum(ref_index); Ok(()) } @@ -598,7 +596,7 @@ mod tests { System::set_block_number(1); let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); assert_ok!(Democracy::vote(Origin::signed(1), r, true)); - assert_ok!(Democracy::cancel_referendum(Origin::ROOT, r)); + assert_ok!(Democracy::cancel_referendum(r)); assert_eq!(Democracy::end_block(System::block_number()), Ok(())); diff --git a/srml/example/src/lib.rs b/srml/example/src/lib.rs index 77e77ef1ad4df..28b30d51b110d 100644 --- a/srml/example/src/lib.rs +++ b/srml/example/src/lib.rs @@ -60,7 +60,7 @@ extern crate srml_balances as balances; use runtime_primitives::traits::OnFinalise; use runtime_support::{StorageValue, dispatch::Result}; -use system::{ensure_signed, ensure_root}; +use system::ensure_signed; /// Our module's configuration trait. All our types and consts go in here. If the /// module is dependent on specific other modules, then their configuration traits @@ -113,7 +113,7 @@ decl_module! { fn accumulate_foo(origin, increase_by: T::Balance) -> Result; /// A privileged call; in this case it resets our dummy value to something new. - fn set_dummy(origin, new_dummy: T::Balance) -> Result; + fn set_dummy(new_dummy: T::Balance) -> Result; } } @@ -264,10 +264,7 @@ impl Module { // calls to be executed - we don't need to care why. Because it's privileged, we can // assume it's a one-off operation and substantial processing/storage/memory can be used // without worrying about gameability or attack scenarios. - fn set_dummy(origin: T::Origin, new_value: T::Balance) -> Result { - // This is a privileged call, so we ensure that the origin is "Root". - ensure_root(origin)?; - + fn set_dummy(new_value: T::Balance) -> Result { // Put the new value into storage. >::put(new_value); diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index 61cf47a095717..919ba18c7a99a 100644 --- a/srml/session/src/lib.rs +++ b/srml/session/src/lib.rs @@ -52,7 +52,7 @@ use rstd::prelude::*; use primitives::traits::{Zero, One, OnFinalise, Convert, As}; use runtime_support::{StorageValue, StorageMap}; use runtime_support::dispatch::Result; -use system::{ensure_signed, ensure_root}; +use system::ensure_signed; #[cfg(any(feature = "std", test))] use std::collections::HashMap; @@ -77,8 +77,8 @@ decl_module! { pub struct Module for enum Call where origin: T::Origin { fn set_key(origin, key: T::SessionKey) -> Result; - fn set_length(origin, new: T::BlockNumber) -> Result; - fn force_new_session(origin, apply_rewards: bool) -> Result; + fn set_length(new: T::BlockNumber) -> Result; + fn force_new_session(apply_rewards: bool) -> Result; } } @@ -144,15 +144,13 @@ impl Module { } /// Set a new era length. Won't kick in until the next era change (at current length). - fn set_length(origin: T::Origin, new: T::BlockNumber) -> Result { - ensure_root(origin)?; + fn set_length(new: T::BlockNumber) -> Result { >::put(new); Ok(()) } /// Forces a new session. - pub fn force_new_session(origin: T::Origin, apply_rewards: bool) -> Result { - ensure_root(origin)?; + pub fn force_new_session(apply_rewards: bool) -> Result { Self::apply_force_new_session(apply_rewards) } @@ -357,7 +355,7 @@ mod tests { fn should_work_with_early_exit() { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); - assert_ok!(Session::set_length(Origin::ROOT, 10)); + assert_ok!(Session::set_length(10)); assert_eq!(Session::blocks_remaining(), 1); Session::check_rotate_session(1); @@ -369,7 +367,7 @@ mod tests { System::set_block_number(7); assert_eq!(Session::current_index(), 1); assert_eq!(Session::blocks_remaining(), 5); - assert_ok!(Session::force_new_session(Origin::ROOT, false)); + assert_ok!(Session::force_new_session(false)); Session::check_rotate_session(7); System::set_block_number(8); @@ -392,14 +390,14 @@ mod tests { with_externalities(&mut new_test_ext(), || { // Block 1: Change to length 3; no visible change. System::set_block_number(1); - assert_ok!(Session::set_length(Origin::ROOT, 3)); + assert_ok!(Session::set_length(3)); Session::check_rotate_session(1); assert_eq!(Session::length(), 2); assert_eq!(Session::current_index(), 0); // Block 2: Length now changed to 3. Index incremented. System::set_block_number(2); - assert_ok!(Session::set_length(Origin::ROOT, 3)); + assert_ok!(Session::set_length(3)); Session::check_rotate_session(2); assert_eq!(Session::length(), 3); assert_eq!(Session::current_index(), 1); @@ -412,7 +410,7 @@ mod tests { // Block 4: Change to length 2; no visible change. System::set_block_number(4); - assert_ok!(Session::set_length(Origin::ROOT, 2)); + assert_ok!(Session::set_length(2)); Session::check_rotate_session(4); assert_eq!(Session::length(), 3); assert_eq!(Session::current_index(), 1); diff --git a/srml/staking/src/lib.rs b/srml/staking/src/lib.rs index 1e0ec4b7b2078..165c8736c3c17 100644 --- a/srml/staking/src/lib.rs +++ b/srml/staking/src/lib.rs @@ -54,7 +54,7 @@ use session::OnSessionChange; use primitives::traits::{Zero, One, Bounded, OnFinalise, As, Lookup}; use balances::{address::Address, OnDilution}; -use system::{ensure_root, ensure_signed}; +use system::ensure_signed; mod mock; @@ -110,11 +110,11 @@ decl_module! { fn unnominate(origin, target_index: u32) -> Result; fn register_preferences(origin, intentions_index: u32, prefs: ValidatorPrefs) -> Result; - fn set_sessions_per_era(origin, new: T::BlockNumber) -> Result; - fn set_bonding_duration(origin, new: T::BlockNumber) -> Result; - fn set_validator_count(origin, new: u32) -> Result; - fn force_new_era(origin, apply_rewards: bool) -> Result; - fn set_offline_slash_grace(origin, new: u32) -> Result; + fn set_sessions_per_era(new: T::BlockNumber) -> Result; + fn set_bonding_duration(new: T::BlockNumber) -> Result; + fn set_validator_count(new: u32) -> Result; + fn force_new_era(apply_rewards: bool) -> Result; + fn set_offline_slash_grace(new: u32) -> Result; } } @@ -325,30 +325,26 @@ impl Module { // PRIV DISPATCH /// Set the number of sessions in an era. - fn set_sessions_per_era(origin: T::Origin, new: T::BlockNumber) -> Result { - ensure_root(origin)?; + fn set_sessions_per_era(new: T::BlockNumber) -> Result { >::put(&new); Ok(()) } /// The length of the bonding duration in eras. - fn set_bonding_duration(origin: T::Origin, new: T::BlockNumber) -> Result { - ensure_root(origin)?; + fn set_bonding_duration(new: T::BlockNumber) -> Result { >::put(&new); Ok(()) } /// The length of a staking era in sessions. - fn set_validator_count(origin: T::Origin, new: u32) -> Result { - ensure_root(origin)?; + fn set_validator_count(new: u32) -> Result { >::put(&new); Ok(()) } /// Force there to be a new era. This also forces a new session immediately after. /// `apply_rewards` should be true for validators to get the session reward. - fn force_new_era(origin: T::Origin, apply_rewards: bool) -> Result { - ensure_root(origin)?; + fn force_new_era(apply_rewards: bool) -> Result { Self::apply_force_new_era(apply_rewards) } @@ -360,8 +356,7 @@ impl Module { /// Set the offline slash grace period. - fn set_offline_slash_grace(origin: T::Origin, new: u32) -> Result { - ensure_root(origin)?; + fn set_offline_slash_grace(new: u32) -> Result { >::put(&new); Ok(()) } diff --git a/srml/staking/src/tests.rs b/srml/staking/src/tests.rs index 66da1ed1737be..0834598a6110a 100644 --- a/srml/staking/src/tests.rs +++ b/srml/staking/src/tests.rs @@ -75,7 +75,7 @@ fn note_offline_grace_should_work() { with_externalities(&mut new_test_ext(0, 3, 3, 0, true, 10), || { Balances::set_free_balance(&10, 70); Balances::set_free_balance(&20, 70); - assert_ok!(Staking::set_offline_slash_grace(Origin::ROOT, 1)); + assert_ok!(Staking::set_offline_slash_grace(1)); assert_eq!(Staking::offline_slash_grace(), 1); assert_eq!(Staking::slash_count(&10), 0); @@ -236,7 +236,7 @@ fn staking_should_work() { assert_eq!(Staking::validator_count(), 2); assert_eq!(Session::validators(), vec![10, 20]); - assert_ok!(Staking::set_bonding_duration(Origin::ROOT, 2)); + assert_ok!(Staking::set_bonding_duration(2)); assert_eq!(Staking::bonding_duration(), 2); // Block 1: Add three validators. No obvious change. @@ -440,7 +440,7 @@ fn staking_eras_work() { // Block 3: Schedule an era length change; no visible changes. System::set_block_number(3); - assert_ok!(Staking::set_sessions_per_era(Origin::ROOT, 3)); + assert_ok!(Staking::set_sessions_per_era(3)); Session::check_rotate_session(System::block_number()); assert_eq!(Session::current_index(), 3); assert_eq!(Staking::sessions_per_era(), 2); diff --git a/srml/support/src/dispatch.rs b/srml/support/src/dispatch.rs index 092f1560903ba..47ba7785cda48 100644 --- a/srml/support/src/dispatch.rs +++ b/srml/support/src/dispatch.rs @@ -64,13 +64,106 @@ macro_rules! decl_module { ( $(#[$attr:meta])* pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> - for enum $call_type:ident where origin: $origin_type:ty {$( + for enum $call_type:ident where origin: $origin_type:ty { + $($t:tt)* + } + ) => { + decl_module!(@normalize + $(#[$attr])* + pub struct $mod_type<$trait_instance: $trait_name> + for enum $call_type where origin: $origin_type where system = system + [] + $($t)* + ); + }; + ( + $(#[$attr:meta])* + pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> + for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident { + $($t:tt)* + } + ) => { + decl_module!(@normalize + $(#[$attr])* + pub struct $mod_type<$trait_instance: $trait_name> + for enum $call_type where origin: $origin_type where system = $system + [] + $($t)* + ); + }; + + (@normalize + $(#[$attr:meta])* + pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> + for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident + [ $($t:tt)* ] + $(#[doc = $doc_attr:tt])* + fn $fn_name:ident(origin $(, $param_name:ident : $param:ty)* ) -> $result:ty ; + $($rest:tt)* + ) => { + decl_module!(@normalize + $(#[$attr])* + pub struct $mod_type<$trait_instance: $trait_name> + for enum $call_type where origin: $origin_type where system = $system + [ $($t)* $(#[doc = $doc_attr])* fn $fn_name(origin $( , $param_name : $param )* ) -> $result; ] + $($rest)* + ); + }; + (@normalize + $(#[$attr:meta])* + pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> + for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident + [ $($t:tt)* ] + $(#[doc = $doc_attr:tt])* + fn $fn_name:ident($( $param_name:ident : $param:ty),* ) -> $result:ty ; + $($rest:tt)* + ) => { + decl_module!(@normalize + $(#[$attr])* + pub struct $mod_type<$trait_instance: $trait_name> + for enum $call_type where origin: $origin_type where system = $system + [ $($t)* $(#[doc = $doc_attr])* fn $fn_name(root $( , $param_name : $param )* ) -> $result; ] + $($rest)* + ); + }; + (@normalize + $(#[$attr:meta])* + pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> + for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident + [ $($t:tt)* ] + ) => { + decl_module!(@imp + $(#[$attr])* + pub struct $mod_type<$trait_instance: $trait_name> + for enum $call_type where origin: $origin_type where system = $system { + $($t)* + } + ); + }; + + (@call + origin + $mod_type:ident $trait_instance:ident $fn_name:ident $origin:ident $system:ident [ $( $param_name:ident),* ] + ) => { + <$mod_type<$trait_instance>>::$fn_name( $origin $(, $param_name )* ) + }; + (@call + root + $mod_type:ident $trait_instance:ident $fn_name:ident $origin:ident $system:ident [ $( $param_name:ident),* ] + ) => { + { + $system::ensure_root($origin)?; + <$mod_type<$trait_instance>>::$fn_name( $( $param_name ),* ) + } + }; + + (@imp + $(#[$attr:meta])* + pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident> + for enum $call_type:ident where origin: $origin_type:ty where system = $system:ident { + $( $(#[doc = $doc_attr:tt])* - fn $fn_name:ident(origin - $( - , $param_name:ident : $param:ty - )* - ) -> $result:ty; + fn $fn_name:ident($from:ident $( , $param_name:ident : $param:ty)*) -> $result:ty; )*} ) => { // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. @@ -194,8 +287,9 @@ macro_rules! decl_module { fn dispatch(self, _origin: Self::Origin) -> $crate::dispatch::Result { match self { $( - $call_type::$fn_name( $( $param_name ),* ) => - <$mod_type<$trait_instance>>::$fn_name( _origin $(, $param_name )* ), + $call_type::$fn_name( $( $param_name ),* ) => { + decl_module!(@call $from $mod_type $trait_instance $fn_name _origin $system [ $( $param_name ),* ]) + }, )* _ => { panic!("__PhantomItem should never be used.") }, } @@ -212,10 +306,9 @@ macro_rules! decl_module { d.dispatch(origin) } } - __dispatch_impl_json_metadata! { $mod_type $trait_instance $trait_name $call_type $origin_type - {$( $(#[doc = $doc_attr])* fn $fn_name(origin $(, $param_name : $param )*) -> $result; )*} + {$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $param_name : $param )*) -> $result; )*} } } } @@ -386,12 +479,11 @@ macro_rules! __dispatch_impl_json_metadata { #[macro_export] #[doc(hidden)] macro_rules! __call_to_json { - // WITH AUX ( $call_type:ident $origin_type:ty {$( $(#[doc = $doc_attr:tt])* - fn $fn_name:ident(origin + fn $fn_name:ident($from:ident $( , $param_name:ident : $param:ty )* @@ -402,7 +494,7 @@ macro_rules! __call_to_json { r#"{ "name": ""#, stringify!($call_type), r#"", "functions": {"#, __functions_to_json!(""; 0; $origin_type; $( - fn $fn_name(origin $(, $param_name: $param )* ) -> $result; + fn $fn_name($from $(, $param_name: $param )* ) -> $result; __function_doc_to_json!(""; $($doc_attr)*); )*), " } }" ) @@ -413,12 +505,15 @@ macro_rules! __call_to_json { #[macro_export] #[doc(hidden)] macro_rules! __functions_to_json { - // WITHOUT AUX + // ROOT ( $prefix_str:tt; $fn_id:expr; - fn $fn_name:ident( - $($param_name:ident : $param:ty),* + $origin_type:ty; + fn $fn_name:ident(root + $( + , $param_name:ident : $param:ty + )* ) -> $result:ty; $fn_doc:expr; $($rest:tt)* @@ -426,14 +521,14 @@ macro_rules! __functions_to_json { concat!($prefix_str, " ", __function_to_json!( fn $fn_name( - $($param_name : $param),* + $( $param_name : $param ),* ) -> $result; $fn_doc; $fn_id; - ), __functions_to_json!(","; $fn_id + 1; $($rest)*) + ), __functions_to_json!(","; $fn_id + 1; $origin_type; $($rest)*) ) }; - // WITH AUX + // NON ROOT ( $prefix_str:tt; $fn_id:expr; @@ -489,6 +584,18 @@ macro_rules! __function_to_json { r#" ], "description": ["#, $fn_doc, " ] }" ) }; + ( + fn $fn_name:ident() -> $result:ty; + $fn_doc:tt; + $fn_id:expr; + ) => { + concat!( + r#"""#, stringify!($fn_id), r#"""#, + r#": { "name": ""#, stringify!($fn_name), + r#"", "params": [ "#, + r#" ], "description": ["#, $fn_doc, " ] }" + ) + }; } /// Convert a function documentation attribute into its JSON representation. @@ -526,12 +633,22 @@ mod tests { type Origin; } + pub mod system { + use super::Result; + + pub fn ensure_root(_: R) -> Result { + Ok(()) + } + } + decl_module! { pub struct Module for enum Call where origin: T::Origin { /// Hi, this is a comment. fn aux_0(origin) -> Result; fn aux_1(origin, data: i32) -> Result; fn aux_2(origin, data: i32, data2: String) -> Result; + fn aux_3() -> Result; + fn aux_4(data: i32) -> Result; } } @@ -541,14 +658,23 @@ mod tests { r#""0": { "name": "aux_0", "params": [ "#, r#"{ "name": "origin", "type": "T::Origin" }"#, r#" ], "description": [ " Hi, this is a comment." ] }, "#, + r#""0 + 1": { "name": "aux_1", "params": [ "#, r#"{ "name": "origin", "type": "T::Origin" }, "#, r#"{ "name": "data", "type": "i32" }"#, r#" ], "description": [ ] }, "#, + r#""0 + 1 + 1": { "name": "aux_2", "params": [ "#, r#"{ "name": "origin", "type": "T::Origin" }, "#, r#"{ "name": "data", "type": "i32" }, "#, r#"{ "name": "data2", "type": "String" }"#, + r#" ], "description": [ ] }, "#, + + r#""0 + 1 + 1 + 1": { "name": "aux_3", "params": [ "#, + r#" ], "description": [ ] }, "#, + + r#""0 + 1 + 1 + 1 + 1": { "name": "aux_4", "params": [ "#, + r#"{ "name": "data", "type": "i32" }"#, r#" ], "description": [ ] }"#, r#" } }"#, r#" }"#, @@ -566,6 +692,14 @@ mod tests { fn aux_2(_: T::Origin, _: i32, _: String) -> Result { unreachable!() } + + fn aux_3() -> Result { + unreachable!() + } + + fn aux_4(_: i32) -> Result { + unreachable!() + } } struct TraitImpl {} diff --git a/srml/treasury/src/lib.rs b/srml/treasury/src/lib.rs index 867cd631bcace..d0dc2fe8c1792 100644 --- a/srml/treasury/src/lib.rs +++ b/srml/treasury/src/lib.rs @@ -46,7 +46,7 @@ use runtime_support::{StorageValue, StorageMap}; use runtime_support::dispatch::Result; use runtime_primitives::{Permill, traits::{OnFinalise, Zero, EnsureOrigin}}; use balances::OnDilution; -use system::{ensure_signed, ensure_root}; +use system::ensure_signed; /// Our module's configuration trait. All our types and consts go in here. If the /// module is dependent on specific other modules, then their configuration traits @@ -77,10 +77,10 @@ decl_module! { fn propose_spend(origin, value: T::Balance, beneficiary: T::AccountId) -> Result; // Set the balance of funds available to spend. - fn set_pot(origin, new_pot: T::Balance) -> Result; + fn set_pot(new_pot: T::Balance) -> Result; // (Re-)configure this module. - fn configure(origin, proposal_bond: Permill, proposal_bond_minimum: T::Balance, spend_period: T::BlockNumber, burn: Permill) -> Result; + fn configure(proposal_bond: Permill, proposal_bond_minimum: T::Balance, spend_period: T::BlockNumber, burn: Permill) -> Result; // Reject a proposed spend. The original deposit will be slashed. fn reject_proposal(origin, roposal_id: ProposalIndex) -> Result; @@ -197,8 +197,7 @@ impl Module { Ok(()) } - fn set_pot(origin: T::Origin, new_pot: T::Balance) -> Result { - ensure_root(origin)?; + fn set_pot(new_pot: T::Balance) -> Result { // Put the new value into storage. >::put(new_pot); @@ -207,13 +206,11 @@ impl Module { } fn configure( - origin: T::Origin, proposal_bond: Permill, proposal_bond_minimum: T::Balance, spend_period: T::BlockNumber, burn: Permill ) -> Result { - ensure_root(origin)?; >::put(proposal_bond); >::put(proposal_bond_minimum); >::put(spend_period);