mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
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.
This commit is contained in:
committed by
Bastian Köcher
parent
057e298b1f
commit
1f84d6d41d
@@ -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)?;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T: Trait> 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;
|
||||
|
||||
@@ -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<T::Header>) -> DispatchResult {
|
||||
fn set_uncles(origin, new_uncles: Vec<T::Header>) -> dispatch::Result {
|
||||
ensure_none(origin)?;
|
||||
ensure!(new_uncles.len() <= MAX_UNCLES, "Too many uncles");
|
||||
|
||||
@@ -220,7 +219,7 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_and_import_uncles(new_uncles: Vec<T::Header>) -> DispatchResult {
|
||||
fn verify_and_import_uncles(new_uncles: Vec<T::Header>) -> dispatch::Result {
|
||||
let now = <system::Module<T>>::block_number();
|
||||
|
||||
let mut uncles = <Self as Store>::Uncles::get();
|
||||
|
||||
@@ -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<T: Trait> Module<T> {
|
||||
// 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 !<VoteOf<T>>::exists((ref_index, &who)) {
|
||||
<VotersFor<T>>::append_or_insert(ref_index, &[&who][..]);
|
||||
@@ -927,7 +927,7 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
/// 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, _)) = <Preimages<T>>::take(&proposal_hash) {
|
||||
if let Ok(proposal) = T::Proposal::decode(&mut &encoded_proposal[..]) {
|
||||
let _ = T::Currency::unreserve(&who, amount);
|
||||
@@ -949,7 +949,7 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
/// 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<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
/// 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)) = <NextExternal<T>>::take() {
|
||||
LastTabledWasExternal::put(true);
|
||||
Self::deposit_event(RawEvent::ExternalTabled);
|
||||
@@ -975,7 +975,7 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
/// 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<T: Trait> Module<T> {
|
||||
now: T::BlockNumber,
|
||||
index: ReferendumIndex,
|
||||
info: ReferendumInfo<T::BlockNumber, T::Hash>
|
||||
) -> 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<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
/// 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),
|
||||
|
||||
@@ -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<T>) -> Result {
|
||||
fn deposit_balance(origin, value: BalanceOf<T>) -> 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<T>) -> Result {
|
||||
fn withdraw_balance(origin, value: BalanceOf<T>) -> dispatch::Result {
|
||||
let sender = ensure_signed(origin)?;
|
||||
let address = T::ConvertAccountId::convert_account_id(&sender);
|
||||
let bvalue = U256::from(UniqueSaturatedInto::<u128>::unique_saturated_into(value));
|
||||
@@ -195,7 +195,9 @@ decl_module! {
|
||||
}
|
||||
|
||||
#[weight = WeightForCallCreate::<T::FeeCalculator>::default()]
|
||||
fn call(origin, target: H160, input: Vec<u8>, value: U256, gas_limit: u32) -> Result {
|
||||
fn call(origin, target: H160, input: Vec<u8>, 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::<T::FeeCalculator>::default()]
|
||||
fn create(origin, init: Vec<u8>, value: U256, gas_limit: u32) -> Result {
|
||||
fn create(origin, init: Vec<u8>, 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();
|
||||
|
||||
@@ -115,15 +115,15 @@
|
||||
//!
|
||||
//! ```
|
||||
//! use support::{
|
||||
//! dispatch,
|
||||
//! traits::{Currency, ExistenceRequirement, WithdrawReason},
|
||||
//! dispatch::Result,
|
||||
//! };
|
||||
//! # pub trait Trait: system::Trait {
|
||||
//! # type Currency: Currency<Self::AccountId>;
|
||||
//! # }
|
||||
//! type AssetOf<T> = <<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
|
||||
//!
|
||||
//! fn charge_fee<T: Trait>(transactor: &T::AccountId, amount: AssetOf<T>) -> Result {
|
||||
//! fn charge_fee<T: Trait>(transactor: &T::AccountId, amount: AssetOf<T>) -> dispatch::Result {
|
||||
//! // ...
|
||||
//! T::Currency::withdraw(
|
||||
//! transactor,
|
||||
@@ -135,7 +135,7 @@
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn refund_fee<T: Trait>(transactor: &T::AccountId, amount: AssetOf<T>) -> Result {
|
||||
//! fn refund_fee<T: Trait>(transactor: &T::AccountId, amount: AssetOf<T>) -> 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<T::Balance, T::AccountId>) -> Result {
|
||||
fn create(origin, options: AssetOptions<T::Balance, T::AccountId>) -> 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<T::AccountId>
|
||||
) -> Result {
|
||||
) -> dispatch::Result {
|
||||
let origin = ensure_signed(origin)?;
|
||||
|
||||
let permissions: PermissionVersions<T::AccountId> = 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<T::Balance, T::AccountId>) -> Result {
|
||||
fn create_reserved(
|
||||
origin,
|
||||
asset_id: T::AssetId,
|
||||
options: AssetOptions<T::Balance, T::AccountId>
|
||||
) -> dispatch::Result {
|
||||
ensure_root(origin)?;
|
||||
Self::create_asset(Some(asset_id), None, options)
|
||||
}
|
||||
@@ -536,7 +543,7 @@ impl<T: Trait> Module<T> {
|
||||
asset_id: Option<T::AssetId>,
|
||||
from_account: Option<T::AccountId>,
|
||||
options: AssetOptions<T::Balance, T::AccountId>,
|
||||
) -> Result {
|
||||
) -> dispatch::Result {
|
||||
let asset_id = if let Some(asset_id) = asset_id {
|
||||
ensure!(!<TotalIssuance<T>>::exists(&asset_id), "Asset id already taken.");
|
||||
ensure!(asset_id < Self::next_asset_id(), "Asset id not available.");
|
||||
@@ -569,7 +576,7 @@ impl<T: Trait> Module<T> {
|
||||
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<T: Trait> Module<T> {
|
||||
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<T: Trait> Module<T> {
|
||||
///
|
||||
/// 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<T: Trait> Module<T> {
|
||||
_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 {
|
||||
<Module<T>>::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 {
|
||||
<Module<T>>::ensure_can_withdraw(&U::asset_id(), who, amount, reasons, new_balance)
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T: Trait> Module<T> {
|
||||
|
||||
/// 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 = <State<T>>::get() {
|
||||
let scheduled_at = <system::Module<T>>::block_number();
|
||||
<State<T>>::put(StoredState::PendingPause {
|
||||
@@ -280,7 +280,7 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
|
||||
/// 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 = <State<T>>::get() {
|
||||
let scheduled_at = <system::Module<T>>::block_number();
|
||||
<State<T>>::put(StoredState::PendingResume {
|
||||
@@ -313,7 +313,7 @@ impl<T: Trait> Module<T> {
|
||||
next_authorities: AuthorityList,
|
||||
in_blocks: T::BlockNumber,
|
||||
forced: Option<T::BlockNumber>,
|
||||
) -> Result {
|
||||
) -> dispatch::Result {
|
||||
if !<PendingChange<T>>::exists() {
|
||||
let scheduled_at = <system::Module<T>>::block_number();
|
||||
|
||||
|
||||
@@ -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<T: Trait> 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 = <im_online::Module<T>>::is_online(authority_index);
|
||||
//! Ok(())
|
||||
|
||||
@@ -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<T: Trait> 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 = <pallet_randomness_collective_flip::Module<T>>::random_seed();
|
||||
//! Ok(())
|
||||
//! }
|
||||
|
||||
@@ -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<T: Trait> for enum Call where origin: T::Origin {
|
||||
//! pub fn candidate(origin) -> Result {
|
||||
//! pub fn candidate(origin) -> dispatch::Result {
|
||||
//! let who = ensure_signed(origin)?;
|
||||
//!
|
||||
//! let _ = <scored_pool::Module<T>>::submit_candidacy(
|
||||
|
||||
@@ -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>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(150_000)]
|
||||
fn set_keys(origin, keys: T::Keys, proof: Vec<u8>) -> Result {
|
||||
fn set_keys(origin, keys: T::Keys, proof: Vec<u8>) -> dispatch::Result {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
ensure!(keys.ownership_proof_is_valid(&proof), "invalid ownership proof");
|
||||
@@ -631,7 +631,7 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
// 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() {
|
||||
|
||||
@@ -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<T: Trait> 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)?;
|
||||
//! <staking::Module<T>>::reward_by_ids(vec![(reported, 10)]);
|
||||
//! Ok(())
|
||||
|
||||
@@ -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<T: Trait> 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...
|
||||
|
||||
@@ -238,7 +238,7 @@ impl ModuleDeclaration {
|
||||
|
||||
fn default_modules(span: Span) -> Vec<ModulePart> {
|
||||
let mut res: Vec<_> = ["Module", "Call", "Storage"]
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|name| ModulePart::with_name(name, span))
|
||||
.collect();
|
||||
res.extend(
|
||||
|
||||
@@ -61,21 +61,21 @@ impl<T> 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<T: Trait> 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<T> 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<T: Trait> 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<T> 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<T: Trait> 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<T> 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<T> 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<u32> {}
|
||||
///
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ impl<K: FullEncode, V: FullCodec, G: StorageMap<K, V>> storage::StorageMap<K, V>
|
||||
.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(),
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ impl<T: FullCodec, G: StorageValue<T>> storage::StorageValue<T> 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(),
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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>(_: R) -> Result {
|
||||
pub fn ensure_root<R>(_: R) -> dispatch::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
support::decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn $reserved(_origin) -> Result { unreachable!() }
|
||||
fn $reserved(_origin) -> dispatch::Result { unreachable!() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T: Trait> 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 = <system::Module<T>>::extrinsic_count();
|
||||
//! let _parent_hash = <system::Module<T>>::parent_hash();
|
||||
|
||||
@@ -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<T: Trait> 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 = <timestamp::Module<T>>::get();
|
||||
//! Ok(())
|
||||
|
||||
@@ -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<String> {
|
||||
use codec::Decode;
|
||||
|
||||
inherents::Error::decode(&mut &error[..]).map(|e| e.into_string()).ok()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user