diff --git a/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index 5ca74bfa6b..a88f31d9c0 100644 Binary files a/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/substrate/core/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ diff --git a/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm b/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm index 2e58c0458a..de9eee8f33 100644 Binary files a/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm and b/substrate/node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm differ diff --git a/substrate/srml/assets/src/lib.rs b/substrate/srml/assets/src/lib.rs index 09f81cb843..18b92f9034 100644 --- a/substrate/srml/assets/src/lib.rs +++ b/substrate/srml/assets/src/lib.rs @@ -45,7 +45,7 @@ extern crate sr_primitives as primitives; // depend on it being around. extern crate srml_system as system; -use runtime_support::{StorageValue, StorageMap, dispatch::Result, Parameter}; +use runtime_support::{StorageValue, StorageMap, Parameter}; use primitives::traits::{Member, SimpleArithmetic, Zero}; use system::ensure_signed; @@ -66,7 +66,7 @@ decl_module! { /// Issue a new class of fungible assets. There are, and will only ever be, `total` /// such assets and they'll all belong to the `origin` initially. It will have an /// identifier `AssetId` instance: this will be specified in the `Issued` event. - fn issue(origin, total: T::Balance) -> Result { + fn issue(origin, total: T::Balance) { let origin = ensure_signed(origin)?; let id = Self::next_asset_id(); @@ -75,11 +75,10 @@ decl_module! { >::insert((id, origin.clone()), total); Self::deposit_event(RawEvent::Issued(id, origin, total)); - Ok(()) } /// Move some assets from one holder to another. - fn transfer(origin, id: AssetId, target: T::AccountId, amount: T::Balance) -> Result { + fn transfer(origin, id: AssetId, target: T::AccountId, amount: T::Balance) { let origin = ensure_signed(origin)?; let origin_account = (id, origin.clone()); let origin_balance = >::get(&origin_account); @@ -88,20 +87,16 @@ decl_module! { Self::deposit_event(RawEvent::Transfered(id, origin, target.clone(), amount)); >::insert(origin_account, origin_balance - amount); >::mutate((id, target), |balance| *balance += amount); - - Ok(()) } /// Destroy any assets of `id` owned by `origin`. - fn destroy(origin, id: AssetId) -> Result { + fn destroy(origin, id: AssetId) { let origin = ensure_signed(origin)?; let balance = >::take((id, origin.clone())); ensure!(!balance.is_zero(), "origin balance should be non-zero"); Self::deposit_event(RawEvent::Destroyed(id, origin, balance)); - - Ok(()) } } } diff --git a/substrate/srml/balances/src/lib.rs b/substrate/srml/balances/src/lib.rs index f945a5ee2e..778b34b4f7 100644 --- a/substrate/srml/balances/src/lib.rs +++ b/substrate/srml/balances/src/lib.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! Balances: Handles setting and retrieval of free balance, -//! retrieving total balance, reserve and unreserve balance, +//! Balances: Handles setting and retrieval of free balance, +//! retrieving total balance, reserve and unreserve balance, //! repatriating a reserved balance to a beneficiary account that exists, //! transfering a balance between accounts (when not reserved), //! slashing an account balance, account removal, rewards, @@ -134,7 +134,7 @@ decl_module! { origin, dest: RawAddress, value: ::Type - ) -> Result { + ) { let transactor = ensure_signed(origin)?; let dest = Self::lookup(dest)?; @@ -170,8 +170,6 @@ decl_module! { Self::set_free_balance_creating(&dest, new_to_balance); Self::deposit_event(RawEvent::Transfer(transactor, dest, value, fee)); } - - Ok(()) } /// Set the balances of a given account. @@ -179,11 +177,10 @@ decl_module! { who: RawAddress, free: ::Type, reserved: ::Type - ) -> Result { + ) { let who = Self::lookup(who)?; Self::set_free_balance(&who, free.into()); Self::set_reserved_balance(&who, reserved.into()); - Ok(()) } } } diff --git a/substrate/srml/consensus/src/lib.rs b/substrate/srml/consensus/src/lib.rs index 6a30327d81..0502e505ea 100644 --- a/substrate/srml/consensus/src/lib.rs +++ b/substrate/srml/consensus/src/lib.rs @@ -41,7 +41,6 @@ use rstd::prelude::*; use rstd::result; use parity_codec::Encode; use runtime_support::{storage, Parameter}; -use runtime_support::dispatch::Result; use runtime_support::storage::StorageValue; use runtime_support::storage::unhashed::StorageVec; use primitives::CheckInherentError; @@ -142,16 +141,15 @@ decl_storage! { decl_module! { pub struct Module for enum Call where origin: T::Origin { /// Report some misbehaviour. - fn report_misbehavior(origin, _report: Vec) -> Result { + fn report_misbehavior(origin, _report: Vec) { ensure_signed(origin)?; // TODO. - Ok(()) } /// Note the previous block's validator missed their opportunity to propose a block. /// This only comes in if 2/3+1 of the validators agree that no proposal was submitted. /// It's only relevant for the previous block. - fn note_offline(origin, offline_val_indices: Vec) -> Result { + fn note_offline(origin, offline_val_indices: Vec) { ensure_inherent(origin)?; assert!( >::extrinsic_index() == Some(T::NOTE_OFFLINE_POSITION), @@ -162,34 +160,28 @@ decl_module! { for validator_index in offline_val_indices.into_iter() { T::OnOfflineValidator::on_offline_validator(validator_index as usize); } - - Ok(()) } /// Make some on-chain remark. - fn remark(origin, _remark: Vec) -> Result { + fn remark(origin, _remark: Vec) { ensure_signed(origin)?; - Ok(()) } /// Set the number of pages in the WebAssembly environment's heap. - fn set_heap_pages(pages: u64) -> Result { + fn set_heap_pages(pages: u64) { storage::unhashed::put_raw(well_known_keys::HEAP_PAGES, &pages.encode()); - Ok(()) } /// Set the new code. - pub fn set_code(new: Vec) -> Result { + pub fn set_code(new: Vec) { storage::unhashed::put_raw(well_known_keys::CODE, &new); - Ok(()) } /// Set some items of storage. - fn set_storage(items: Vec) -> Result { + fn set_storage(items: Vec) { for i in &items { storage::unhashed::put_raw(&i.0, &i.1); } - Ok(()) } fn on_finalise() { diff --git a/substrate/srml/council/src/motions.rs b/substrate/srml/council/src/motions.rs index d6b875c58f..5316d5c681 100644 --- a/substrate/srml/council/src/motions.rs +++ b/substrate/srml/council/src/motions.rs @@ -21,7 +21,7 @@ use rstd::result; use codec::Compact; use substrate_primitives::u32_trait::Value as U32; use primitives::traits::{Hash, EnsureOrigin}; -use srml_support::dispatch::{Result, Dispatchable, Parameter}; +use srml_support::dispatch::{Dispatchable, Parameter}; use srml_support::{StorageValue, StorageMap}; use super::{Trait as CouncilTrait, Module as Council}; use system::{self, ensure_signed}; @@ -68,7 +68,7 @@ decl_event!( decl_module! { pub struct Module for enum Call where origin: ::Origin { fn deposit_event() = default; - fn propose(origin, threshold: Compact, proposal: Box<::Proposal>) -> Result { + fn propose(origin, threshold: Compact, proposal: Box<::Proposal>) { let who = ensure_signed(origin)?; let threshold = threshold.into(); @@ -90,10 +90,9 @@ decl_module! { Self::deposit_event(RawEvent::Proposed(who, index, proposal_hash, threshold)); } - Ok(()) } - fn vote(origin, proposal: T::Hash, index: Compact, approve: bool) -> Result { + fn vote(origin, proposal: T::Hash, index: Compact, approve: bool) { let who = ensure_signed(origin)?; let index = index.into(); @@ -154,8 +153,6 @@ decl_module! { // update voting >::insert(&proposal, voting); } - - Ok(()) } } } diff --git a/substrate/srml/council/src/seats.rs b/substrate/srml/council/src/seats.rs index d582ac6904..7fef771d38 100644 --- a/substrate/srml/council/src/seats.rs +++ b/substrate/srml/council/src/seats.rs @@ -91,7 +91,7 @@ decl_module! { /// Set candidate approvals. Approval slots stay valid as long as candidates in those slots /// are registered. - fn set_approvals(origin, votes: Vec, index: Compact) -> Result { + fn set_approvals(origin, votes: Vec, index: Compact) { let who = ensure_signed(origin)?; let index: VoteIndex = index.into(); @@ -110,7 +110,6 @@ decl_module! { } >::insert(&who, index); >::insert(&who, votes); - Ok(()) } /// Remove a voter. For it not to be a bond-consuming no-op, all approved candidate indices @@ -124,7 +123,7 @@ decl_module! { who: Address, who_index: Compact, assumed_vote_index: Compact - ) -> Result { + ) { let reporter = ensure_signed(origin)?; let assumed_vote_index: VoteIndex = assumed_vote_index.into(); @@ -166,11 +165,10 @@ decl_module! { >::slash_reserved(&reporter, Self::voting_bond()); Self::deposit_event(RawEvent::BadReaperSlashed(reporter)); } - Ok(()) } /// Remove a voter. All votes are cancelled and the voter deposit is returned. - fn retract_voter(origin, index: Compact) -> Result { + fn retract_voter(origin, index: Compact) { let who = ensure_signed(origin)?; ensure!(!Self::presentation_active(), "cannot retract when presenting"); @@ -183,13 +181,12 @@ decl_module! { Self::remove_voter(&who, index, voters); >::unreserve(&who, Self::voting_bond()); - Ok(()) } /// Submit oneself for candidacy. /// /// Account must have enough transferrable funds in it to pay the bond. - fn submit_candidacy(origin, slot: Compact) -> Result { + fn submit_candidacy(origin, slot: Compact) { let who = ensure_signed(origin)?; ensure!(!Self::is_a_candidate(&who), "duplicate candidate submission"); @@ -215,7 +212,6 @@ decl_module! { } >::put(candidates); >::put(count as u32 + 1); - Ok(()) } /// Claim that `signed` is one of the top Self::carry_count() + current_vote().1 candidates. @@ -276,37 +272,33 @@ decl_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(count: Compact) -> Result { + fn set_desired_seats(count: Compact) { let count: u32 = count.into(); >::put(count); - Ok(()) } /// 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(who: Address) -> Result { + fn remove_member(who: Address) { let who = >::lookup(who)?; let new_council: Vec<(T::AccountId, T::BlockNumber)> = Self::active_council() .into_iter() .filter(|i| i.0 != who) .collect(); >::put(new_council); - Ok(()) } /// Set the presentation duration. If there is currently a vote being presented for, will /// invoke `finalise_vote`. - fn set_presentation_duration(count: ::Type) -> Result { + fn set_presentation_duration(count: ::Type) { >::put(count.into()); - Ok(()) } /// Set the presentation duration. If there is current a vote being presented for, will /// invoke `finalise_vote`. - fn set_term_duration(count: ::Type) -> Result { + fn set_term_duration(count: ::Type) { >::put(count.into()); - Ok(()) } fn on_finalise(n: T::BlockNumber) { diff --git a/substrate/srml/council/src/voting.rs b/substrate/srml/council/src/voting.rs index b598e8ca05..d61e5f2a33 100644 --- a/substrate/srml/council/src/voting.rs +++ b/substrate/srml/council/src/voting.rs @@ -35,7 +35,7 @@ decl_module! { pub struct Module for enum Call where origin: T::Origin { fn deposit_event() = default; - fn propose(origin, proposal: Box) -> Result { + fn propose(origin, proposal: Box) { let who = ensure_signed(origin)?; let expiry = >::block_number() + Self::voting_period(); @@ -54,11 +54,9 @@ decl_module! { >::insert(proposal_hash, *proposal); >::insert(proposal_hash, vec![who.clone()]); >::insert((proposal_hash, who.clone()), true); - - Ok(()) } - fn vote(origin, proposal: T::Hash, approve: bool) -> Result { + fn vote(origin, proposal: T::Hash, approve: bool) { let who = ensure_signed(origin)?; ensure!(Self::is_councillor(&who), "only councillors may vote on council proposals"); @@ -67,10 +65,9 @@ decl_module! { >::mutate(proposal, |voters| voters.push(who.clone())); } >::insert((proposal, who), approve); - Ok(()) } - fn veto(origin, proposal_hash: T::Hash) -> Result { + fn veto(origin, proposal_hash: T::Hash) { let who = ensure_signed(origin)?; ensure!(Self::is_councillor(&who), "only councillors may veto council proposals"); @@ -96,17 +93,14 @@ decl_module! { for (c, _) in >::active_council() { >::remove((proposal_hash, c)); } - Ok(()) } - fn set_cooloff_period(blocks: ::Type) -> Result { + fn set_cooloff_period(blocks: ::Type) { >::put(blocks.into()); - Ok(()) } - fn set_voting_period(blocks: ::Type) -> Result { + fn set_voting_period(blocks: ::Type) { >::put(blocks.into()); - Ok(()) } fn on_finalise(n: T::BlockNumber) { diff --git a/substrate/srml/democracy/src/lib.rs b/substrate/srml/democracy/src/lib.rs index c0c25bd1ca..23b942c597 100644 --- a/substrate/srml/democracy/src/lib.rs +++ b/substrate/srml/democracy/src/lib.rs @@ -65,7 +65,7 @@ decl_module! { origin, proposal: Box, value: ::Type - ) -> Result { + ) { let who = ensure_signed(origin)?; let value = value.into(); @@ -80,11 +80,10 @@ decl_module! { let mut props = Self::public_props(); props.push((index, (*proposal).clone(), who)); >::put(props); - Ok(()) } /// Propose a sensitive action to be taken. - fn second(origin, proposal: Compact) -> Result { + fn second(origin, proposal: Compact) { let who = ensure_signed(origin)?; let proposal: PropIndex = proposal.into(); let mut deposit = Self::deposit_of(proposal) @@ -93,12 +92,11 @@ decl_module! { .map_err(|_| "seconder's balance too low")?; deposit.1.push(who); >::insert(proposal, deposit); - Ok(()) } /// Vote in a referendum. If `approve_proposal` is true, the vote is to enact the proposal; /// false would be a vote to keep the status quo. - fn vote(origin, ref_index: Compact, approve_proposal: bool) -> Result { + fn vote(origin, ref_index: Compact, approve_proposal: bool) { let who = ensure_signed(origin)?; let ref_index = ref_index.into(); ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum."); @@ -108,7 +106,6 @@ decl_module! { >::mutate(ref_index, |voters| voters.push(who.clone())); } >::insert(&(ref_index, who), approve_proposal); - Ok(()) } /// Start a referendum. @@ -121,9 +118,8 @@ decl_module! { } /// Remove a referendum. - fn cancel_referendum(ref_index: Compact) -> Result { + fn cancel_referendum(ref_index: Compact) { Self::clear_referendum(ref_index.into()); - Ok(()) } fn on_finalise(n: T::BlockNumber) { diff --git a/substrate/srml/example/src/lib.rs b/substrate/srml/example/src/lib.rs index 8dcbb7094b..31baac20f7 100644 --- a/substrate/srml/example/src/lib.rs +++ b/substrate/srml/example/src/lib.rs @@ -173,12 +173,11 @@ decl_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(new_value: T::Balance) -> Result { + // If you not specify `Result` explicitly as return value, it will be added automatically + // for you and `Ok(())` will be returned. + fn set_dummy(new_value: T::Balance) { // Put the new value into storage. >::put(new_value); - - // All good. - Ok(()) } // The signature could also look like: `fn on_finalise()` diff --git a/substrate/srml/grandpa/src/lib.rs b/substrate/srml/grandpa/src/lib.rs index 8173b9a725..2a9df1b852 100644 --- a/substrate/srml/grandpa/src/lib.rs +++ b/substrate/srml/grandpa/src/lib.rs @@ -189,10 +189,9 @@ decl_module! { fn deposit_event() = default; /// Report some misbehaviour. - fn report_misbehavior(origin, _report: Vec) -> Result { + fn report_misbehavior(origin, _report: Vec) { ensure_signed(origin)?; // TODO: https://github.com/paritytech/substrate/issues/1112 - Ok(()) } fn on_finalise(block_number: T::BlockNumber) { diff --git a/substrate/srml/session/src/lib.rs b/substrate/srml/session/src/lib.rs index 34137c6de4..56398823c1 100644 --- a/substrate/srml/session/src/lib.rs +++ b/substrate/srml/session/src/lib.rs @@ -93,17 +93,15 @@ decl_module! { /// Sets the session key of `_validator` to `_key`. This doesn't take effect until the next /// session. - fn set_key(origin, key: T::SessionKey) -> Result { + fn set_key(origin, key: T::SessionKey) { let who = ensure_signed(origin)?; // set new value for next session >::insert(who, key); - Ok(()) } /// Set a new session length. Won't kick in until the next session change (at current length). - fn set_length(new: ::Type) -> Result { + fn set_length(new: ::Type) { >::put(new.into()); - Ok(()) } /// Forces a new session. diff --git a/substrate/srml/staking/src/lib.rs b/substrate/srml/staking/src/lib.rs index 55c453e7cb..2d78ae5af7 100644 --- a/substrate/srml/staking/src/lib.rs +++ b/substrate/srml/staking/src/lib.rs @@ -105,7 +105,7 @@ decl_module! { /// Declare the desire to stake for the transactor. /// /// Effects will be felt at the beginning of the next era. - fn stake(origin) -> Result { + fn stake(origin) { let who = ensure_signed(origin)?; ensure!(Self::nominating(&who).is_none(), "Cannot stake if already nominating."); let mut intentions = >::get(); @@ -115,7 +115,6 @@ decl_module! { >::insert(&who, T::BlockNumber::max_value()); intentions.push(who); >::put(intentions); - Ok(()) } /// Retract the desire to stake for the transactor. @@ -131,7 +130,7 @@ decl_module! { Self::apply_unstake(&who, intentions_index as usize) } - fn nominate(origin, target: Address) -> Result { + fn nominate(origin, target: Address) { let who = ensure_signed(origin)?; let target = >::lookup(target)?; @@ -148,13 +147,11 @@ decl_module! { // Update bondage >::insert(&who, T::BlockNumber::max_value()); - - Ok(()) } /// Will panic if called when source isn't currently nominating target. /// Updates Nominating, NominatorsFor and NominationBalance. - fn unnominate(origin, target_index: Compact) -> Result { + fn unnominate(origin, target_index: Compact) { let source = ensure_signed(origin)?; let target_index: u32 = target_index.into(); let target_index = target_index as usize; @@ -180,7 +177,6 @@ decl_module! { source, >::block_number() + Self::bonding_duration() ); - Ok(()) } /// Set the given account's preference for slashing behaviour should they be a validator. @@ -190,7 +186,7 @@ decl_module! { origin, intentions_index: Compact, prefs: ValidatorPrefs - ) -> Result { + ) { let who = ensure_signed(origin)?; let intentions_index: u32 = intentions_index.into(); @@ -199,27 +195,22 @@ decl_module! { } >::insert(who, prefs); - - Ok(()) } /// Set the number of sessions in an era. - fn set_sessions_per_era(new: ::Type) -> Result { + fn set_sessions_per_era(new: ::Type) { >::put(new.into()); - Ok(()) } /// The length of the bonding duration in eras. - fn set_bonding_duration(new: ::Type) -> Result { + fn set_bonding_duration(new: ::Type) { >::put(new.into()); - Ok(()) } /// The ideal number of validators. - fn set_validator_count(new: Compact) -> Result { + fn set_validator_count(new: Compact) { let new: u32 = new.into(); >::put(new); - Ok(()) } /// Force there to be a new era. This also forces a new session immediately after. @@ -229,10 +220,9 @@ decl_module! { } /// Set the offline slash grace period. - fn set_offline_slash_grace(new: Compact) -> Result { + fn set_offline_slash_grace(new: Compact) { let new: u32 = new.into(); >::put(new); - Ok(()) } } } diff --git a/substrate/srml/support/src/dispatch.rs b/substrate/srml/support/src/dispatch.rs index 436ed87b9a..4d0815c41f 100644 --- a/substrate/srml/support/src/dispatch.rs +++ b/substrate/srml/support/src/dispatch.rs @@ -167,7 +167,9 @@ macro_rules! decl_module { { $( $on_finalise:tt )* } [ $($t:tt)* ] $(#[doc = $doc_attr:tt])* - $fn_vis:vis fn $fn_name:ident($origin:ident $(, $param_name:ident : $param:ty)* ) -> $result:ty { $( $impl:tt )* } + $fn_vis:vis fn $fn_name:ident( + $origin:ident $(, $param_name:ident : $param:ty)* + ) $( -> $result:ty )* { $( $impl:tt )* } $($rest:tt)* ) => { decl_module!(@normalize @@ -179,7 +181,9 @@ macro_rules! decl_module { [ $($t)* $(#[doc = $doc_attr])* - $fn_vis fn $fn_name($origin $( , $param_name : $param )* ) -> $result { $( $impl )* } + $fn_vis fn $fn_name( + $origin $( , $param_name : $param )* + ) $( -> $result )* { $( $impl )* } ] $($rest)* ); @@ -192,12 +196,16 @@ macro_rules! decl_module { { $( $on_finalise:tt )* } [ $($t:tt)* ] $(#[doc = $doc_attr:tt])* - $fn_vis:vis fn $fn_name:ident($origin:ident : T::Origin $(, $param_name:ident : $param:ty)* ) -> $result:ty { $( $impl:tt )* } + $fn_vis:vis fn $fn_name:ident( + $origin:ident : T::Origin $(, $param_name:ident : $param:ty)* + ) $( -> $result:ty )* { $( $impl:tt )* } $($rest:tt)* ) => { - compile_error!("\ -first parameter of dispatch should be marked `origin` only, with no type specified (a bit like `self`)\n\ -(For root-matching dispatches, ensure the first parameter does not use the `T::Origin` type.)") + compile_error!( + "First parameter of dispatch should be marked `origin` only, with no type specified \ + (a bit like `self`). (For root-matching dispatches, ensure the first parameter does \ + not use the `T::Origin` type.)" + ) }; (@normalize $(#[$attr:meta])* @@ -207,12 +215,16 @@ first parameter of dispatch should be marked `origin` only, with no type specifi { $( $on_finalise:tt )* } [ $($t:tt)* ] $(#[doc = $doc_attr:tt])* - $fn_vis:vis fn $fn_name:ident(origin : $origin:ty $(, $param_name:ident : $param:ty)* ) -> $result:ty { $( $impl:tt )* } + $fn_vis:vis fn $fn_name:ident( + origin : $origin:ty $(, $param_name:ident : $param:ty)* + ) $( -> $result:ty )* { $( $impl:tt )* } $($rest:tt)* ) => { - compile_error!("\ -first parameter of dispatch should be marked `origin` only, with no type specified (a bit like `self`)\n\ -(For root-matching dispatches, ensure the first parameter is not named`origin`.)") + compile_error!( + "First parameter of dispatch should be marked `origin` only, with no type specified \ + (a bit like `self`). (For root-matching dispatches, ensure the first parameter does \ + not use the `T::Origin` type.)" + ) }; (@normalize $(#[$attr:meta])* @@ -222,7 +234,9 @@ first parameter of dispatch should be marked `origin` only, with no type specifi { $( $on_finalise:tt )* } [ $($t:tt)* ] $(#[doc = $doc_attr:tt])* - $fn_vis:vis fn $fn_name:ident($( $param_name:ident : $param:ty),* ) -> $result:ty { $( $impl:tt )* } + $fn_vis:vis fn $fn_name:ident( + $( $param_name:ident : $param:ty),* + ) $( -> $result:ty )* { $( $impl:tt )* } $($rest:tt)* ) => { decl_module!(@normalize @@ -234,7 +248,9 @@ first parameter of dispatch should be marked `origin` only, with no type specifi [ $($t)* $(#[doc = $doc_attr])* - $fn_vis fn $fn_name(root $( , $param_name : $param )* ) -> $result { $( $impl )* } + $fn_vis fn $fn_name( + root $( , $param_name : $param )* + ) $( -> $result )* { $( $impl )* } ] $($rest)* ); @@ -340,7 +356,23 @@ first parameter of dispatch should be marked `origin` only, with no type specifi $module:ident<$trait_instance:ident: $trait_name:ident>; $origin_ty:ty; root; - $vis:vis fn $name:ident ( root $(, $param:ident : $param_ty:ty )* ) -> $result:ty { $( $impl:tt )* } + $vis:vis fn $name:ident ( root $(, $param:ident : $param_ty:ty )* ) { $( $impl:tt )* } + ) => { + impl<$trait_instance: $trait_name> $module<$trait_instance> { + $vis fn $name($( $param: $param_ty ),* ) -> $crate::dispatch::Result { + { $( $impl )* } + Ok(()) + } + } + }; + + (@impl_function + $module:ident<$trait_instance:ident: $trait_name:ident>; + $origin_ty:ty; + root; + $vis:vis fn $name:ident ( + root $(, $param:ident : $param_ty:ty )* + ) -> $result:ty { $( $impl:tt )* } ) => { impl<$trait_instance: $trait_name> $module<$trait_instance> { $vis fn $name($( $param: $param_ty ),* ) -> $result { @@ -348,11 +380,32 @@ first parameter of dispatch should be marked `origin` only, with no type specifi } } }; + (@impl_function $module:ident<$trait_instance:ident: $trait_name:ident>; $origin_ty:ty; $ignore:ident; - $vis:vis fn $name:ident ( $origin:ident $(, $param:ident : $param_ty:ty )* ) -> $result:ty { $( $impl:tt )* } + $vis:vis fn $name:ident ( + $origin:ident $(, $param:ident : $param_ty:ty )* + ) { $( $impl:tt )* } + ) => { + impl<$trait_instance: $trait_name> $module<$trait_instance> { + $vis fn $name( + $origin: $origin_ty $(, $param: $param_ty )* + ) -> $crate::dispatch::Result { + { $( $impl )* } + Ok(()) + } + } + }; + + (@impl_function + $module:ident<$trait_instance:ident: $trait_name:ident>; + $origin_ty:ty; + $ignore:ident; + $vis:vis fn $name:ident ( + $origin:ident $(, $param:ident : $param_ty:ty )* + ) -> $result:ty { $( $impl:tt )* } ) => { impl<$trait_instance: $trait_name> $module<$trait_instance> { $vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result { @@ -369,7 +422,7 @@ first parameter of dispatch should be marked `origin` only, with no type specifi $(#[doc = $doc_attr:tt])* $fn_vis:vis fn $fn_name:ident( $from:ident $( , $param_name:ident : $param:ty)* - ) -> $result:ty { $( $impl:tt )* } + ) $( -> $result:ty )* { $( $impl:tt )* } )* } { $( $deposit_event:tt )* } @@ -409,7 +462,9 @@ first parameter of dispatch should be marked `origin` only, with no type specifi $mod_type<$trait_instance: $trait_name>; $origin_type; $from; - $fn_vis fn $fn_name ($from $(, $param_name : $param )* ) -> $result { $( $impl )* } + $fn_vis fn $fn_name ( + $from $(, $param_name : $param )* + ) $( -> $result )* { $( $impl )* } } )* @@ -542,7 +597,7 @@ first parameter of dispatch should be marked `origin` only, with no type specifi } __dispatch_impl_metadata! { $mod_type $trait_instance $trait_name $call_type $origin_type - {$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $param_name : $param )*) -> $result; )*} + {$( $(#[doc = $doc_attr])* fn $fn_name($from $(, $param_name : $param )*); )*} } } } @@ -764,13 +819,13 @@ macro_rules! __call_to_metadata { $( , $param_name:ident : $param:ty )* - ) -> $result:ty; + ); )*} ) => { $crate::dispatch::CallMetadata { name: $crate::dispatch::DecodeDifferent::Encode(stringify!($call_type)), functions: __functions_to_metadata!(0; $origin_type;; $( - fn $fn_name( $( $param_name: $param ),* ) -> $result; + fn $fn_name( $( $param_name: $param ),* ); $( $doc_attr ),*; )*), } @@ -789,14 +844,14 @@ macro_rules! __functions_to_metadata{ $( $param_name:ident : $param:ty ),* - ) -> $result:ty; + ); $( $fn_doc:expr ),*; $( $rest:tt )* ) => { __functions_to_metadata!( $fn_id + 1; $origin_type; $( $function_metadata, )* __function_to_metadata!( - fn $fn_name($( $param_name : $param ),*) -> $result; $( $fn_doc ),*; $fn_id; + fn $fn_name($( $param_name : $param ),*); $( $fn_doc ),*; $fn_id; ); $($rest)* ) @@ -817,7 +872,7 @@ macro_rules! __function_to_metadata { ( fn $fn_name:ident( $($param_name:ident : $param:ty),* - ) -> $result:ty; + ); $( $fn_doc:expr ),*; $fn_id:expr; ) => { diff --git a/substrate/srml/timestamp/src/lib.rs b/substrate/srml/timestamp/src/lib.rs index 2c4675fb1d..4b63a34b01 100644 --- a/substrate/srml/timestamp/src/lib.rs +++ b/substrate/srml/timestamp/src/lib.rs @@ -49,7 +49,6 @@ extern crate parity_codec as codec; use codec::HasCompact; use runtime_support::{StorageValue, Parameter}; -use runtime_support::dispatch::Result; use runtime_primitives::CheckInherentError; use runtime_primitives::traits::{ As, SimpleArithmetic, Zero, ProvideInherent, Block as BlockT, Extrinsic @@ -75,7 +74,7 @@ decl_module! { /// if this call hasn't been invoked by that time. /// /// The timestamp should be greater than the previous one by the amount specified by `block_period`. - fn set(origin, now: ::Type) -> Result { + fn set(origin, now: ::Type) { ensure_inherent(origin)?; let now = now.into(); @@ -91,7 +90,6 @@ decl_module! { ); ::Now::put(now); ::DidUpdate::put(true); - Ok(()) } fn on_finalise() { diff --git a/substrate/srml/treasury/src/lib.rs b/substrate/srml/treasury/src/lib.rs index 340ab48a8c..abbe0e7899 100644 --- a/substrate/srml/treasury/src/lib.rs +++ b/substrate/srml/treasury/src/lib.rs @@ -40,7 +40,6 @@ extern crate srml_balances as balances; use rstd::prelude::*; use runtime_support::{StorageValue, StorageMap}; -use runtime_support::dispatch::Result; use runtime_primitives::{Permill, traits::{Zero, EnsureOrigin}}; use codec::{HasCompact, Compact}; use balances::{OnDilution, address::Address}; @@ -77,7 +76,7 @@ decl_module! { origin, value: ::Type, beneficiary: Address - ) -> Result { + ) { let proposer = ensure_signed(origin)?; let beneficiary = >::lookup(beneficiary)?; let value = value.into(); @@ -91,17 +90,12 @@ decl_module! { >::insert(c, Proposal { proposer, value, beneficiary, bond }); Self::deposit_event(RawEvent::Proposed(c)); - - Ok(()) } /// Set the balance of funds available to spend. - fn set_pot(new_pot: ::Type) -> Result { + fn set_pot(new_pot: ::Type) { // Put the new value into storage. >::put(new_pot.into()); - - // All good. - Ok(()) } /// (Re-)configure this module. @@ -110,16 +104,15 @@ decl_module! { proposal_bond_minimum: ::Type, spend_period: ::Type, burn: Permill - ) -> Result { + ) { >::put(proposal_bond); >::put(proposal_bond_minimum.into()); >::put(spend_period.into()); >::put(burn); - Ok(()) } /// Reject a proposed spend. The original deposit will be slashed. - fn reject_proposal(origin, proposal_id: Compact) -> Result { + fn reject_proposal(origin, proposal_id: Compact) { T::RejectOrigin::ensure_origin(origin)?; let proposal_id: ProposalIndex = proposal_id.into(); @@ -127,21 +120,17 @@ decl_module! { let value = proposal.bond; let _ = >::slash_reserved(&proposal.proposer, value); - - Ok(()) } /// Approve a proposal. At a later time, the proposal will be allocated to the beneficiary /// and the original deposit will be returned. - fn approve_proposal(origin, proposal_id: Compact) -> Result { + fn approve_proposal(origin, proposal_id: Compact) { T::ApproveOrigin::ensure_origin(origin)?; let proposal_id = proposal_id.into(); ensure!(>::exists(proposal_id), "No proposal at that index"); >::mutate(|v| v.push(proposal_id)); - - Ok(()) } fn on_finalise(n: T::BlockNumber) { diff --git a/substrate/srml/upgrade-key/src/lib.rs b/substrate/srml/upgrade-key/src/lib.rs index 028ac26ab1..3957b080d3 100644 --- a/substrate/srml/upgrade-key/src/lib.rs +++ b/substrate/srml/upgrade-key/src/lib.rs @@ -35,7 +35,7 @@ extern crate srml_system as system; extern crate srml_consensus as consensus; use sr_std::prelude::*; -use support::{StorageValue, dispatch::Result}; +use support::StorageValue; use system::ensure_signed; pub trait Trait: consensus::Trait + system::Trait { @@ -47,26 +47,22 @@ decl_module! { // Simple declaration of the `Module` type. Lets the macro know what its working on. pub struct Module for enum Call where origin: T::Origin { fn deposit_event() = default; - fn upgrade(origin, new: Vec) -> Result { + fn upgrade(origin, new: Vec) { // This is a public call, so we ensure that the origin is some signed account. let _sender = ensure_signed(origin)?; ensure!(_sender == Self::key(), "only the current upgrade key can use the upgrade_key module"); >::set_code(new)?; Self::deposit_event(RawEvent::Upgraded); - - Ok(()) } - fn set_key(origin, new: T::AccountId) -> Result { + fn set_key(origin, new: T::AccountId) { // This is a public call, so we ensure that the origin is some signed account. let _sender = ensure_signed(origin)?; ensure!(_sender == Self::key(), "only the current upgrade key can use the upgrade_key module"); Self::deposit_event(RawEvent::KeyChanged(Self::key())); >::put(new); - - Ok(()) } } }