EnsureOrigin is a frame abstraction - it should be in frame_support (#5521)

* EnsureOrigin is a frame abstraction - it should be in frame_support

* Fixes
This commit is contained in:
Gavin Wood
2020-04-04 12:58:05 +02:00
committed by GitHub
parent f0375a858f
commit 7c0fa83720
14 changed files with 48 additions and 45 deletions
+22 -3
View File
@@ -22,9 +22,10 @@ use sp_std::{prelude::*, result, marker::PhantomData, ops::Div, fmt::Debug};
use codec::{FullCodec, Codec, Encode, Decode, EncodeLike};
use sp_core::u32_trait::Value as U32;
use sp_runtime::{
RuntimeDebug,
ConsensusEngineId, DispatchResult, DispatchError,
traits::{MaybeSerializeDeserialize, AtLeast32Bit, Saturating, TrailingZeroInput, Bounded, Zero},
RuntimeDebug, ConsensusEngineId, DispatchResult, DispatchError, traits::{
MaybeSerializeDeserialize, AtLeast32Bit, Saturating, TrailingZeroInput, Bounded, Zero,
BadOrigin
},
};
use crate::dispatch::Parameter;
use crate::storage::StorageMap;
@@ -1237,6 +1238,24 @@ pub mod schedule {
}
}
/// Some sort of check on the origin is performed by this object.
pub trait EnsureOrigin<OuterOrigin> {
/// A return type.
type Success;
/// Perform the origin check.
fn ensure_origin(o: OuterOrigin) -> result::Result<Self::Success, BadOrigin> {
Self::try_origin(o).map_err(|_| BadOrigin)
}
/// Perform the origin check.
fn try_origin(o: OuterOrigin) -> result::Result<Self::Success, OuterOrigin>;
/// Returns an outer origin capable of passing `try_origin` check.
///
/// ** Should be used for benchmarking only!!! **
#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> OuterOrigin;
}
#[cfg(test)]
mod tests {
use super::*;