From 1f84d6d41d9e6a00a52c48fc6278d1b9bdf29889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 10 Dec 2019 14:21:34 +0100 Subject: [PATCH] Fix warnings when compiling runtime. (#4332) * Remove warnings when compiling runtime. * Remove dispatch::Result imports. * Add missing imports. * Fix missing vecs. #4333 * Fix oom function. * Remove superfluous import. * More warnings. --- .../bin/node-template/runtime/src/template.rs | 4 +- substrate/client/tracing/src/lib.rs | 4 +- substrate/frame/assets/src/lib.rs | 4 +- substrate/frame/authorship/src/lib.rs | 9 ++-- substrate/frame/democracy/src/lib.rs | 24 +++++------ substrate/frame/evm/src/lib.rs | 12 +++--- substrate/frame/generic-asset/src/lib.rs | 43 +++++++++++-------- substrate/frame/grandpa/src/lib.rs | 8 ++-- substrate/frame/im-online/src/lib.rs | 4 +- .../randomness-collective-flip/src/lib.rs | 4 +- substrate/frame/scored-pool/src/lib.rs | 4 +- substrate/frame/session/src/lib.rs | 6 +-- substrate/frame/staking/src/lib.rs | 4 +- substrate/frame/sudo/src/lib.rs | 4 +- .../procedural/src/construct_runtime/parse.rs | 2 +- substrate/frame/support/src/dispatch.rs | 18 ++++---- .../src/storage/generator/double_map.rs | 2 +- .../support/src/storage/generator/map.rs | 2 +- .../support/src/storage/generator/value.rs | 2 +- .../tests/reserved_keyword/on_initialize.rs | 8 ++-- substrate/frame/system/src/lib.rs | 4 +- substrate/frame/timestamp/src/lib.rs | 4 +- .../consensus/aura/src/inherents.rs | 7 +-- substrate/primitives/core/src/crypto.rs | 4 +- substrate/primitives/sr-io/src/lib.rs | 4 +- 25 files changed, 104 insertions(+), 87 deletions(-) diff --git a/substrate/bin/node-template/runtime/src/template.rs b/substrate/bin/node-template/runtime/src/template.rs index e3e053da53..6cdadc72ff 100644 --- a/substrate/bin/node-template/runtime/src/template.rs +++ b/substrate/bin/node-template/runtime/src/template.rs @@ -8,7 +8,7 @@ /// For more guidance on Substrate modules, see the example module /// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs -use support::{decl_module, decl_storage, decl_event, dispatch::Result}; +use support::{decl_module, decl_storage, decl_event, dispatch}; use system::ensure_signed; /// The module's configuration trait. @@ -40,7 +40,7 @@ decl_module! { // Just a dummy entry point. // function that can be called by the external world as an extrinsics call // takes a parameter of the type `AccountId`, stores it and emits an event - pub fn do_something(origin, something: u32) -> Result { + pub fn do_something(origin, something: u32) -> dispatch::Result { // TODO: You only need this if you want to check it was signed. let who = ensure_signed(origin)?; diff --git a/substrate/client/tracing/src/lib.rs b/substrate/client/tracing/src/lib.rs index 4be87bc2f7..288d5e7019 100644 --- a/substrate/client/tracing/src/lib.rs +++ b/substrate/client/tracing/src/lib.rs @@ -293,5 +293,7 @@ fn send_telemetry(span_datum: SpanDatum) { fn send_grafana(span_datum: SpanDatum) { let name = format!("{}::{}", span_datum.target, span_datum.name); - record_metrics!(&name => span_datum.overall_time.as_nanos(),); + if let Err(e) = record_metrics!(&name => span_datum.overall_time.as_nanos(),) { + log::warn!("Unable to send metrics to grafana: {:?}", e); + } } diff --git a/substrate/frame/assets/src/lib.rs b/substrate/frame/assets/src/lib.rs index 7810b75305..306ac30d09 100644 --- a/substrate/frame/assets/src/lib.rs +++ b/substrate/frame/assets/src/lib.rs @@ -84,14 +84,14 @@ //! ### Simple Code Snippet //! //! ```rust,ignore -//! use support::{decl_module, dispatch::Result}; +//! use support::{decl_module, dispatch}; //! use system::ensure_signed; //! //! pub trait Trait: assets::Trait { } //! //! decl_module! { //! pub struct Module for enum Call where origin: T::Origin { -//! pub fn issue_token_airdrop(origin) -> Result { +//! pub fn issue_token_airdrop(origin) -> dispatch::Result { //! const ACCOUNT_ALICE: u64 = 1; //! const ACCOUNT_BOB: u64 = 2; //! const COUNT_AIRDROP_RECIPIENTS = 2; diff --git a/substrate/frame/authorship/src/lib.rs b/substrate/frame/authorship/src/lib.rs index edb01b7d2a..a5a032165d 100644 --- a/substrate/frame/authorship/src/lib.rs +++ b/substrate/frame/authorship/src/lib.rs @@ -22,14 +22,13 @@ use sp_std::{result, prelude::*}; use sp_std::collections::btree_set::BTreeSet; -use support::{decl_module, decl_storage, ensure}; +use support::{decl_module, decl_storage, dispatch, ensure}; use support::traits::{FindAuthor, VerifySeal, Get}; -use support::dispatch::Result as DispatchResult; use codec::{Encode, Decode}; use system::ensure_none; use sp_runtime::traits::{Header as HeaderT, One, Zero}; use support::weights::SimpleDispatchInfo; -use inherents::{InherentIdentifier, ProvideInherent, InherentData, MakeFatalError}; +use inherents::{InherentIdentifier, ProvideInherent, InherentData}; use sp_authorship::{INHERENT_IDENTIFIER, UnclesInherentData, InherentError}; const MAX_UNCLES: usize = 10; @@ -185,7 +184,7 @@ decl_module! { /// Provide a set of uncles. #[weight = SimpleDispatchInfo::FixedOperational(10_000)] - fn set_uncles(origin, new_uncles: Vec) -> DispatchResult { + fn set_uncles(origin, new_uncles: Vec) -> dispatch::Result { ensure_none(origin)?; ensure!(new_uncles.len() <= MAX_UNCLES, "Too many uncles"); @@ -220,7 +219,7 @@ impl Module { } } - fn verify_and_import_uncles(new_uncles: Vec) -> DispatchResult { + fn verify_and_import_uncles(new_uncles: Vec) -> dispatch::Result { let now = >::block_number(); let mut uncles = ::Uncles::get(); diff --git a/substrate/frame/democracy/src/lib.rs b/substrate/frame/democracy/src/lib.rs index 2bbef15d60..d5d8850645 100644 --- a/substrate/frame/democracy/src/lib.rs +++ b/substrate/frame/democracy/src/lib.rs @@ -27,6 +27,7 @@ use sp_runtime::{ use codec::{Ref, Encode, Decode, Input, Output, Error}; use support::{ decl_module, decl_storage, decl_event, ensure, + dispatch, Parameter, weights::SimpleDispatchInfo, traits::{ @@ -34,7 +35,6 @@ use support::{ OnFreeBalanceZero, OnUnbalanced } }; -use support::dispatch::Result; use system::{ensure_signed, ensure_root}; mod vote_threshold; @@ -445,7 +445,7 @@ decl_module! { fn vote(origin, #[compact] ref_index: ReferendumIndex, vote: Vote - ) -> Result { + ) -> dispatch::Result { let who = ensure_signed(origin)?; Self::do_vote(who, ref_index, vote) } @@ -461,7 +461,7 @@ decl_module! { fn proxy_vote(origin, #[compact] ref_index: ReferendumIndex, vote: Vote - ) -> Result { + ) -> dispatch::Result { let who = Self::proxy(ensure_signed(origin)?).ok_or("not a proxy")?; Self::do_vote(who, ref_index, vote) } @@ -885,7 +885,7 @@ impl Module { // private. /// Actually enact a vote, if legit. - fn do_vote(who: T::AccountId, ref_index: ReferendumIndex, vote: Vote) -> Result { + fn do_vote(who: T::AccountId, ref_index: ReferendumIndex, vote: Vote) -> dispatch::Result { ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum."); if !>::exists((ref_index, &who)) { >::append_or_insert(ref_index, &[&who][..]); @@ -927,7 +927,7 @@ impl Module { } /// Enact a proposal from a referendum. - fn enact_proposal(proposal_hash: T::Hash, index: ReferendumIndex) -> Result { + fn enact_proposal(proposal_hash: T::Hash, index: ReferendumIndex) -> dispatch::Result { if let Some((encoded_proposal, who, amount, _)) = >::take(&proposal_hash) { if let Ok(proposal) = T::Proposal::decode(&mut &encoded_proposal[..]) { let _ = T::Currency::unreserve(&who, amount); @@ -949,7 +949,7 @@ impl Module { } /// Table the next waiting proposal for a vote. - fn launch_next(now: T::BlockNumber) -> Result { + fn launch_next(now: T::BlockNumber) -> dispatch::Result { if LastTabledWasExternal::take() { Self::launch_public(now).or_else(|_| Self::launch_external(now)) } else { @@ -958,7 +958,7 @@ impl Module { } /// Table the waiting external proposal for a vote, if there is one. - fn launch_external(now: T::BlockNumber) -> Result { + fn launch_external(now: T::BlockNumber) -> dispatch::Result { if let Some((proposal, threshold)) = >::take() { LastTabledWasExternal::put(true); Self::deposit_event(RawEvent::ExternalTabled); @@ -975,7 +975,7 @@ impl Module { } /// Table the waiting public proposal with the highest backing for a vote. - fn launch_public(now: T::BlockNumber) -> Result { + fn launch_public(now: T::BlockNumber) -> dispatch::Result { let mut public_props = Self::public_props(); if let Some((winner_index, _)) = public_props.iter() .enumerate() @@ -1009,7 +1009,7 @@ impl Module { now: T::BlockNumber, index: ReferendumIndex, info: ReferendumInfo - ) -> Result { + ) -> dispatch::Result { let (approve, against, capital) = Self::tally(index); let total_issuance = T::Currency::total_issuance(); let approved = info.threshold.approved(approve, against, capital, total_issuance); @@ -1056,7 +1056,7 @@ impl Module { } /// Current era is ending; we should finish up any proposals. - fn begin_block(now: T::BlockNumber) -> Result { + fn begin_block(now: T::BlockNumber) -> dispatch::Result { // pick out another public referendum if it's time. if (now % T::LaunchPeriod::get()).is_zero() { // Errors come from the queue being empty. we don't really care about that, and even if @@ -1241,7 +1241,7 @@ mod tests { h } - fn propose_set_balance(who: u64, value: u64, delay: u64) -> super::Result { + fn propose_set_balance(who: u64, value: u64, delay: u64) -> dispatch::Result { Democracy::propose( Origin::signed(who), set_balance_proposal_hash(value), @@ -1249,7 +1249,7 @@ mod tests { ) } - fn propose_set_balance_and_note(who: u64, value: u64, delay: u64) -> super::Result { + fn propose_set_balance_and_note(who: u64, value: u64, delay: u64) -> dispatch::Result { Democracy::propose( Origin::signed(who), set_balance_proposal_hash_and_note(value), diff --git a/substrate/frame/evm/src/lib.rs b/substrate/frame/evm/src/lib.rs index 8ad7fbc139..4a62dae9ad 100644 --- a/substrate/frame/evm/src/lib.rs +++ b/substrate/frame/evm/src/lib.rs @@ -24,7 +24,7 @@ mod backend; pub use crate::backend::{Account, Log, Vicinity, Backend}; use sp_std::{vec::Vec, marker::PhantomData}; -use support::{dispatch::Result, decl_module, decl_storage, decl_event}; +use support::{dispatch, decl_module, decl_storage, decl_event}; use support::weights::{Weight, WeighData, ClassifyDispatch, DispatchClass, PaysFee}; use support::traits::{Currency, WithdrawReason, ExistenceRequirement}; use system::ensure_signed; @@ -150,7 +150,7 @@ decl_module! { fn deposit_event() = default; #[weight = SimpleDispatchInfo::FixedNormal(10_000)] - fn deposit_balance(origin, value: BalanceOf) -> Result { + fn deposit_balance(origin, value: BalanceOf) -> dispatch::Result { let sender = ensure_signed(origin)?; let imbalance = T::Currency::withdraw( @@ -171,7 +171,7 @@ decl_module! { } #[weight = SimpleDispatchInfo::FixedNormal(10_000)] - fn withdraw_balance(origin, value: BalanceOf) -> Result { + fn withdraw_balance(origin, value: BalanceOf) -> dispatch::Result { let sender = ensure_signed(origin)?; let address = T::ConvertAccountId::convert_account_id(&sender); let bvalue = U256::from(UniqueSaturatedInto::::unique_saturated_into(value)); @@ -195,7 +195,9 @@ decl_module! { } #[weight = WeightForCallCreate::::default()] - fn call(origin, target: H160, input: Vec, value: U256, gas_limit: u32) -> Result { + fn call(origin, target: H160, input: Vec, value: U256, gas_limit: u32) + -> dispatch::Result + { let sender = ensure_signed(origin)?; let source = T::ConvertAccountId::convert_account_id(&sender); let gas_price = T::FeeCalculator::gas_price(); @@ -246,7 +248,7 @@ decl_module! { } #[weight = WeightForCallCreate::::default()] - fn create(origin, init: Vec, value: U256, gas_limit: u32) -> Result { + fn create(origin, init: Vec, value: U256, gas_limit: u32) -> dispatch::Result { let sender = ensure_signed(origin)?; let source = T::ConvertAccountId::convert_account_id(&sender); let gas_price = T::FeeCalculator::gas_price(); diff --git a/substrate/frame/generic-asset/src/lib.rs b/substrate/frame/generic-asset/src/lib.rs index ba7cdae7df..9315b36674 100644 --- a/substrate/frame/generic-asset/src/lib.rs +++ b/substrate/frame/generic-asset/src/lib.rs @@ -115,15 +115,15 @@ //! //! ``` //! use support::{ +//! dispatch, //! traits::{Currency, ExistenceRequirement, WithdrawReason}, -//! dispatch::Result, //! }; //! # pub trait Trait: system::Trait { //! # type Currency: Currency; //! # } //! type AssetOf = <::Currency as Currency<::AccountId>>::Balance; //! -//! fn charge_fee(transactor: &T::AccountId, amount: AssetOf) -> Result { +//! fn charge_fee(transactor: &T::AccountId, amount: AssetOf) -> dispatch::Result { //! // ... //! T::Currency::withdraw( //! transactor, @@ -135,7 +135,7 @@ //! Ok(()) //! } //! -//! fn refund_fee(transactor: &T::AccountId, amount: AssetOf) -> Result { +//! fn refund_fee(transactor: &T::AccountId, amount: AssetOf) -> dispatch::Result { //! // ... //! T::Currency::deposit_into_existing(transactor, amount)?; //! // ... @@ -161,9 +161,8 @@ use sp_runtime::traits::{ use sp_std::prelude::*; use sp_std::{cmp, result, fmt::Debug}; -use support::dispatch::Result; use support::{ - decl_event, decl_module, decl_storage, ensure, + decl_event, decl_module, decl_storage, ensure, dispatch, traits::{ Currency, ExistenceRequirement, Imbalance, LockIdentifier, LockableCurrency, ReservableCurrency, SignedImbalance, UpdateBalanceOutcome, WithdrawReason, WithdrawReasons, TryDrop, @@ -326,7 +325,7 @@ decl_module! { fn deposit_event() = default; /// Create a new kind of asset. - fn create(origin, options: AssetOptions) -> Result { + fn create(origin, options: AssetOptions) -> dispatch::Result { let origin = ensure_signed(origin)?; let id = Self::next_asset_id(); @@ -359,7 +358,7 @@ decl_module! { origin, #[compact] asset_id: T::AssetId, new_permission: PermissionLatest - ) -> Result { + ) -> dispatch::Result { let origin = ensure_signed(origin)?; let permissions: PermissionVersions = new_permission.into(); @@ -377,7 +376,9 @@ decl_module! { /// Mints an asset, increases its total issuance. /// The origin must have `mint` permissions. - fn mint(origin, #[compact] asset_id: T::AssetId, to: T::AccountId, amount: T::Balance) -> Result { + fn mint(origin, #[compact] asset_id: T::AssetId, to: T::AccountId, amount: T::Balance) + -> dispatch::Result + { let origin = ensure_signed(origin)?; if Self::check_permission(&asset_id, &origin, &PermissionType::Mint) { let original_free_balance = Self::free_balance(&asset_id, &to); @@ -401,7 +402,9 @@ decl_module! { /// Burns an asset, decreases its total issuance. /// /// The `origin` must have `burn` permissions. - fn burn(origin, #[compact] asset_id: T::AssetId, to: T::AccountId, amount: T::Balance) -> Result { + fn burn(origin, #[compact] asset_id: T::AssetId, to: T::AccountId, amount: T::Balance) + -> dispatch::Result + { let origin = ensure_signed(origin)?; if Self::check_permission(&asset_id, &origin, &PermissionType::Burn) { @@ -427,7 +430,11 @@ decl_module! { /// Can be used to create reserved tokens. /// Requires Root call. - fn create_reserved(origin, asset_id: T::AssetId, options: AssetOptions) -> Result { + fn create_reserved( + origin, + asset_id: T::AssetId, + options: AssetOptions + ) -> dispatch::Result { ensure_root(origin)?; Self::create_asset(Some(asset_id), None, options) } @@ -536,7 +543,7 @@ impl Module { asset_id: Option, from_account: Option, options: AssetOptions, - ) -> Result { + ) -> dispatch::Result { let asset_id = if let Some(asset_id) = asset_id { ensure!(!>::exists(&asset_id), "Asset id already taken."); ensure!(asset_id < Self::next_asset_id(), "Asset id not available."); @@ -569,7 +576,7 @@ impl Module { from: &T::AccountId, to: &T::AccountId, amount: T::Balance - ) -> Result { + ) -> dispatch::Result { let new_balance = Self::free_balance(asset_id, from) .checked_sub(&amount) .ok_or_else(|| "balance too low to send amount")?; @@ -590,7 +597,7 @@ impl Module { from: &T::AccountId, to: &T::AccountId, amount: T::Balance, - ) -> Result { + ) -> dispatch::Result { Self::make_transfer(asset_id, from, to, amount)?; if from != to { @@ -604,7 +611,9 @@ impl Module { /// /// If the free balance is lower than `amount`, then no funds will be moved and an `Err` will /// be returned. This is different behavior than `unreserve`. - pub fn reserve(asset_id: &T::AssetId, who: &T::AccountId, amount: T::Balance) -> Result { + pub fn reserve(asset_id: &T::AssetId, who: &T::AccountId, amount: T::Balance) + -> dispatch::Result + { // Do we need to consider that this is an atomic transaction? let original_reserve_balance = Self::reserved_balance(asset_id, who); let original_free_balance = Self::free_balance(asset_id, who); @@ -742,7 +751,7 @@ impl Module { _amount: T::Balance, reasons: WithdrawReasons, new_balance: T::Balance, - ) -> Result { + ) -> dispatch::Result { if asset_id != &Self::staking_asset_id() { return Ok(()); } @@ -1124,7 +1133,7 @@ where dest: &T::AccountId, value: Self::Balance, _: ExistenceRequirement, // no existential deposit policy for generic asset - ) -> Result { + ) -> dispatch::Result { >::make_transfer(&U::asset_id(), transactor, dest, value) } @@ -1133,7 +1142,7 @@ where amount: Self::Balance, reasons: WithdrawReasons, new_balance: Self::Balance, - ) -> Result { + ) -> dispatch::Result { >::ensure_can_withdraw(&U::asset_id(), who, amount, reasons, new_balance) } diff --git a/substrate/frame/grandpa/src/lib.rs b/substrate/frame/grandpa/src/lib.rs index f80974a31a..301a09d107 100644 --- a/substrate/frame/grandpa/src/lib.rs +++ b/substrate/frame/grandpa/src/lib.rs @@ -32,7 +32,7 @@ pub use sp_finality_grandpa as fg_primitives; use sp_std::prelude::*; use codec::{self as codec, Encode, Decode, Error}; -use support::{decl_event, decl_storage, decl_module, dispatch::Result, storage}; +use support::{decl_event, decl_storage, decl_module, dispatch, storage}; use sp_runtime::{ generic::{DigestItem, OpaqueDigestItemId}, traits::Zero, Perbill, }; @@ -264,7 +264,7 @@ impl Module { /// Schedule GRANDPA to pause starting in the given number of blocks. /// Cannot be done when already paused. - pub fn schedule_pause(in_blocks: T::BlockNumber) -> Result { + pub fn schedule_pause(in_blocks: T::BlockNumber) -> dispatch::Result { if let StoredState::Live = >::get() { let scheduled_at = >::block_number(); >::put(StoredState::PendingPause { @@ -280,7 +280,7 @@ impl Module { } /// Schedule a resume of GRANDPA after pausing. - pub fn schedule_resume(in_blocks: T::BlockNumber) -> Result { + pub fn schedule_resume(in_blocks: T::BlockNumber) -> dispatch::Result { if let StoredState::Paused = >::get() { let scheduled_at = >::block_number(); >::put(StoredState::PendingResume { @@ -313,7 +313,7 @@ impl Module { next_authorities: AuthorityList, in_blocks: T::BlockNumber, forced: Option, - ) -> Result { + ) -> dispatch::Result { if !>::exists() { let scheduled_at = >::block_number(); diff --git a/substrate/frame/im-online/src/lib.rs b/substrate/frame/im-online/src/lib.rs index 24556b717e..70ffc40378 100644 --- a/substrate/frame/im-online/src/lib.rs +++ b/substrate/frame/im-online/src/lib.rs @@ -42,7 +42,7 @@ //! ## Usage //! //! ``` -//! use support::{decl_module, dispatch::Result}; +//! use support::{decl_module, dispatch}; //! use system::ensure_signed; //! use pallet_im_online::{self as im_online}; //! @@ -50,7 +50,7 @@ //! //! decl_module! { //! pub struct Module for enum Call where origin: T::Origin { -//! pub fn is_online(origin, authority_index: u32) -> Result { +//! pub fn is_online(origin, authority_index: u32) -> dispatch::Result { //! let _sender = ensure_signed(origin)?; //! let _is_online = >::is_online(authority_index); //! Ok(()) diff --git a/substrate/frame/randomness-collective-flip/src/lib.rs b/substrate/frame/randomness-collective-flip/src/lib.rs index a250f50092..a4c568abd0 100644 --- a/substrate/frame/randomness-collective-flip/src/lib.rs +++ b/substrate/frame/randomness-collective-flip/src/lib.rs @@ -35,13 +35,13 @@ //! ### Example - Get random seed for the current block //! //! ``` -//! use support::{decl_module, dispatch::Result, traits::Randomness}; +//! use support::{decl_module, dispatch, traits::Randomness}; //! //! pub trait Trait: system::Trait {} //! //! decl_module! { //! pub struct Module for enum Call where origin: T::Origin { -//! pub fn random_module_example(origin) -> Result { +//! pub fn random_module_example(origin) -> dispatch::Result { //! let _random_seed = >::random_seed(); //! Ok(()) //! } diff --git a/substrate/frame/scored-pool/src/lib.rs b/substrate/frame/scored-pool/src/lib.rs index 9645560d53..30dfbbbccf 100644 --- a/substrate/frame/scored-pool/src/lib.rs +++ b/substrate/frame/scored-pool/src/lib.rs @@ -53,7 +53,7 @@ //! ## Usage //! //! ``` -//! use support::{decl_module, dispatch::Result}; +//! use support::{decl_module, dispatch}; //! use system::ensure_signed; //! use pallet_scored_pool::{self as scored_pool}; //! @@ -61,7 +61,7 @@ //! //! decl_module! { //! pub struct Module for enum Call where origin: T::Origin { -//! pub fn candidate(origin) -> Result { +//! pub fn candidate(origin) -> dispatch::Result { //! let who = ensure_signed(origin)?; //! //! let _ = >::submit_candidacy( diff --git a/substrate/frame/session/src/lib.rs b/substrate/frame/session/src/lib.rs index c71d2dbfba..6c6be7a573 100644 --- a/substrate/frame/session/src/lib.rs +++ b/substrate/frame/session/src/lib.rs @@ -125,7 +125,7 @@ use sp_runtime::{KeyTypeId, Perbill, RuntimeAppPublic, BoundToRuntimeAppPublic}; use support::weights::SimpleDispatchInfo; use sp_runtime::traits::{Convert, Zero, Member, OpaqueKeys}; use sp_staking::SessionIndex; -use support::{dispatch::Result, ConsensusEngineId, decl_module, decl_event, decl_storage}; +use support::{dispatch, ConsensusEngineId, decl_module, decl_event, decl_storage}; use support::{ensure, traits::{OnFreeBalanceZero, Get, FindAuthor, ValidatorRegistration}, Parameter}; use system::{self, ensure_signed}; @@ -483,7 +483,7 @@ decl_module! { /// - One extra DB entry. /// # #[weight = SimpleDispatchInfo::FixedNormal(150_000)] - fn set_keys(origin, keys: T::Keys, proof: Vec) -> Result { + fn set_keys(origin, keys: T::Keys, proof: Vec) -> dispatch::Result { let who = ensure_signed(origin)?; ensure!(keys.ownership_proof_is_valid(&proof), "invalid ownership proof"); @@ -631,7 +631,7 @@ impl Module { // perform the set_key operation, checking for duplicates. // does not set `Changed`. - fn do_set_keys(who: &T::ValidatorId, keys: T::Keys) -> Result { + fn do_set_keys(who: &T::ValidatorId, keys: T::Keys) -> dispatch::Result { let old_keys = Self::load_keys(&who); for id in T::Keys::key_ids() { diff --git a/substrate/frame/staking/src/lib.rs b/substrate/frame/staking/src/lib.rs index 952c0cbd62..d468b110c5 100644 --- a/substrate/frame/staking/src/lib.rs +++ b/substrate/frame/staking/src/lib.rs @@ -138,7 +138,7 @@ //! ### Example: Rewarding a validator by id. //! //! ``` -//! use support::{decl_module, dispatch::Result}; +//! use support::{decl_module, dispatch}; //! use system::ensure_signed; //! use pallet_staking::{self as staking}; //! @@ -147,7 +147,7 @@ //! decl_module! { //! pub struct Module for enum Call where origin: T::Origin { //! /// Reward a validator. -//! pub fn reward_myself(origin) -> Result { +//! pub fn reward_myself(origin) -> dispatch::Result { //! let reported = ensure_signed(origin)?; //! >::reward_by_ids(vec![(reported, 10)]); //! Ok(()) diff --git a/substrate/frame/sudo/src/lib.rs b/substrate/frame/sudo/src/lib.rs index 13daa23971..95ff953904 100644 --- a/substrate/frame/sudo/src/lib.rs +++ b/substrate/frame/sudo/src/lib.rs @@ -51,14 +51,14 @@ //! This is an example of a module that exposes a privileged function: //! //! ``` -//! use support::{decl_module, dispatch::Result}; +//! use support::{decl_module, dispatch}; //! use system::ensure_root; //! //! pub trait Trait: system::Trait {} //! //! decl_module! { //! pub struct Module for enum Call where origin: T::Origin { -//! pub fn privileged_function(origin) -> Result { +//! pub fn privileged_function(origin) -> dispatch::Result { //! ensure_root(origin)?; //! //! // do something... diff --git a/substrate/frame/support/procedural/src/construct_runtime/parse.rs b/substrate/frame/support/procedural/src/construct_runtime/parse.rs index b3f602824c..a5338bb8af 100644 --- a/substrate/frame/support/procedural/src/construct_runtime/parse.rs +++ b/substrate/frame/support/procedural/src/construct_runtime/parse.rs @@ -238,7 +238,7 @@ impl ModuleDeclaration { fn default_modules(span: Span) -> Vec { let mut res: Vec<_> = ["Module", "Call", "Storage"] - .into_iter() + .iter() .map(|name| ModulePart::with_name(name, span)) .collect(); res.extend( diff --git a/substrate/frame/support/src/dispatch.rs b/substrate/frame/support/src/dispatch.rs index 8432dd2cec..ca535a6a3b 100644 --- a/substrate/frame/support/src/dispatch.rs +++ b/substrate/frame/support/src/dispatch.rs @@ -61,21 +61,21 @@ impl Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {} /// ``` /// # #[macro_use] /// # extern crate frame_support; -/// # use frame_support::dispatch::Result; +/// # use frame_support::dispatch; /// # use frame_system::{self as system, Trait, ensure_signed}; /// decl_module! { /// pub struct Module for enum Call where origin: T::Origin { /// /// // Private functions are dispatchable, but not available to other /// // SRML modules. -/// fn my_function(origin, var: u64) -> Result { +/// fn my_function(origin, var: u64) -> dispatch::Result { /// // Your implementation /// Ok(()) /// } /// /// // Public functions are both dispatchable and available to other /// // SRML modules. -/// pub fn my_public_function(origin) -> Result { +/// pub fn my_public_function(origin) -> dispatch::Result { /// // Your implementation /// Ok(()) /// } @@ -101,12 +101,12 @@ impl Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {} /// ``` /// # #[macro_use] /// # extern crate frame_support; -/// # use frame_support::dispatch::Result; +/// # use frame_support::dispatch; /// # use frame_system::{self as system, Trait, ensure_signed}; /// decl_module! { /// pub struct Module for enum Call where origin: T::Origin { /// -/// fn my_long_function(origin) -> Result { +/// fn my_long_function(origin) -> dispatch::Result { /// // Your implementation /// Ok(()) /// } @@ -126,11 +126,11 @@ impl Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {} /// ``` /// # #[macro_use] /// # extern crate frame_support; -/// # use frame_support::dispatch::Result; +/// # use frame_support::dispatch; /// # use frame_system::{self as system, Trait, ensure_signed, ensure_root}; /// decl_module! { /// pub struct Module for enum Call where origin: T::Origin { -/// fn my_privileged_function(origin) -> Result { +/// fn my_privileged_function(origin) -> dispatch::Result { /// ensure_root(origin)?; /// // Your implementation /// Ok(()) @@ -150,7 +150,7 @@ impl Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {} /// ``` /// # #[macro_use] /// # extern crate frame_support; -/// # use frame_support::dispatch::Result; +/// # use frame_support::dispatch; /// # use frame_system::{self as system, ensure_signed}; /// # pub struct DefaultInstance; /// # pub trait Instance {} @@ -178,7 +178,7 @@ impl Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {} /// ``` /// # #[macro_use] /// # extern crate frame_support; -/// # use frame_support::dispatch::Result; +/// # use frame_support::dispatch; /// # use frame_system::{self as system, ensure_signed}; /// pub trait Trait: system::Trait where Self::AccountId: From {} /// diff --git a/substrate/frame/support/src/storage/generator/double_map.rs b/substrate/frame/support/src/storage/generator/double_map.rs index fd938001ae..5edd8ee90f 100644 --- a/substrate/frame/support/src/storage/generator/double_map.rs +++ b/substrate/frame/support/src/storage/generator/double_map.rs @@ -218,7 +218,7 @@ where .unwrap_or_else(|| { match G::from_query_to_optional_value(G::from_optional_value_to_query(None)) { Some(value) => value.encode(), - None => vec![], + None => Vec::new(), } }); diff --git a/substrate/frame/support/src/storage/generator/map.rs b/substrate/frame/support/src/storage/generator/map.rs index fd9f1f901d..0a6cc1f9ae 100644 --- a/substrate/frame/support/src/storage/generator/map.rs +++ b/substrate/frame/support/src/storage/generator/map.rs @@ -143,7 +143,7 @@ impl> storage::StorageMap .unwrap_or_else(|| { match G::from_query_to_optional_value(G::from_optional_value_to_query(None)) { Some(value) => value.encode(), - None => vec![], + None => Vec::new(), } }); diff --git a/substrate/frame/support/src/storage/generator/value.rs b/substrate/frame/support/src/storage/generator/value.rs index cc45439f5b..f259b795ce 100644 --- a/substrate/frame/support/src/storage/generator/value.rs +++ b/substrate/frame/support/src/storage/generator/value.rs @@ -127,7 +127,7 @@ impl> storage::StorageValue for G { .unwrap_or_else(|| { match G::from_query_to_optional_value(G::from_optional_value_to_query(None)) { Some(value) => value.encode(), - None => vec![], + None => Vec::new(), } }); diff --git a/substrate/frame/support/test/tests/reserved_keyword/on_initialize.rs b/substrate/frame/support/test/tests/reserved_keyword/on_initialize.rs index f9604c9487..80ee52a982 100644 --- a/substrate/frame/support/test/tests/reserved_keyword/on_initialize.rs +++ b/substrate/frame/support/test/tests/reserved_keyword/on_initialize.rs @@ -2,7 +2,7 @@ macro_rules! reserved { ($($reserved:ident)*) => { $( mod $reserved { - pub use support::dispatch::Result; + pub use support::dispatch; pub trait Trait { type Origin; @@ -10,16 +10,16 @@ macro_rules! reserved { } pub mod system { - use support::dispatch::Result; + use support::dispatch; - pub fn ensure_root(_: R) -> Result { + pub fn ensure_root(_: R) -> dispatch::Result { Ok(()) } } support::decl_module! { pub struct Module for enum Call where origin: T::Origin { - fn $reserved(_origin) -> Result { unreachable!() } + fn $reserved(_origin) -> dispatch::Result { unreachable!() } } } } diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index cec92d7f82..b05326a5cf 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -68,14 +68,14 @@ //! ### Example - Get extrinsic count and parent hash for the current block //! //! ``` -//! use support::{decl_module, dispatch::Result}; +//! use support::{decl_module, dispatch}; //! use frame_system::{self as system, ensure_signed}; //! //! pub trait Trait: system::Trait {} //! //! decl_module! { //! pub struct Module for enum Call where origin: T::Origin { -//! pub fn system_module_example(origin) -> Result { +//! pub fn system_module_example(origin) -> dispatch::Result { //! let _sender = ensure_signed(origin)?; //! let _extrinsic_count = >::extrinsic_count(); //! let _parent_hash = >::parent_hash(); diff --git a/substrate/frame/timestamp/src/lib.rs b/substrate/frame/timestamp/src/lib.rs index 0c415dbe9a..065901ea54 100644 --- a/substrate/frame/timestamp/src/lib.rs +++ b/substrate/frame/timestamp/src/lib.rs @@ -61,7 +61,7 @@ //! ### Get current timestamp //! //! ``` -//! use support::{decl_module, dispatch::Result}; +//! use support::{decl_module, dispatch}; //! # use pallet_timestamp as timestamp; //! use system::ensure_signed; //! @@ -69,7 +69,7 @@ //! //! decl_module! { //! pub struct Module for enum Call where origin: T::Origin { -//! pub fn get_time(origin) -> Result { +//! pub fn get_time(origin) -> dispatch::Result { //! let _sender = ensure_signed(origin)?; //! let _now = >::get(); //! Ok(()) diff --git a/substrate/primitives/consensus/aura/src/inherents.rs b/substrate/primitives/consensus/aura/src/inherents.rs index 5899e7b272..9a7c7c0c5b 100644 --- a/substrate/primitives/consensus/aura/src/inherents.rs +++ b/substrate/primitives/consensus/aura/src/inherents.rs @@ -16,10 +16,7 @@ /// Contains the inherents for the AURA module -use sp_timestamp::TimestampInherentData; use inherents::{InherentIdentifier, InherentData, Error}; -use sp_std::result::Result; -use codec::Decode; #[cfg(feature = "std")] use inherents::{InherentDataProviders, ProvideInherentData}; @@ -86,12 +83,16 @@ impl ProvideInherentData for InherentDataProvider { &self, inherent_data: &mut InherentData, ) ->Result<(), Error> { + use sp_timestamp::TimestampInherentData; + let timestamp = inherent_data.timestamp_inherent_data()?; let slot_num = timestamp / self.slot_duration; inherent_data.put_data(INHERENT_IDENTIFIER, &slot_num) } fn error_to_string(&self, error: &[u8]) -> Option { + use codec::Decode; + inherents::Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() } } diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index 3d020bcde0..91fd19291f 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -18,7 +18,9 @@ //! Cryptographic utilities. // end::description[] -use sp_std::{vec::Vec, hash::Hash}; +use sp_std::hash::Hash; +#[cfg(feature = "full_crypto")] +use sp_std::vec::Vec; #[cfg(feature = "std")] use sp_std::convert::TryInto; use sp_std::convert::TryFrom; diff --git a/substrate/primitives/sr-io/src/lib.rs b/substrate/primitives/sr-io/src/lib.rs index b232bfd914..ef4334808a 100644 --- a/substrate/primitives/sr-io/src/lib.rs +++ b/substrate/primitives/sr-io/src/lib.rs @@ -770,6 +770,7 @@ mod allocator_impl { } } +/// A default panic handler for WASM environment. #[cfg(all(not(feature = "disable_panic_handler"), not(feature = "std")))] #[panic_handler] #[no_mangle] @@ -781,9 +782,10 @@ pub fn panic(info: &core::panic::PanicInfo) -> ! { } } +/// A default OOM handler for WASM environment. #[cfg(all(not(feature = "disable_oom"), not(feature = "std")))] #[alloc_error_handler] -pub extern fn oom(_: core::alloc::Layout) -> ! { +pub fn oom(_: core::alloc::Layout) -> ! { unsafe { logging::log(LogLevel::Error, "runtime", b"Runtime memory exhausted. Aborting"); core::intrinsics::abort();