mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 08:57:56 +00:00
Helper macro for Morph impls (#11570)
* Helper macro for Morph impls * No need to deprecate for now * Improved macro * Doc tests * Grumbles
This commit is contained in:
@@ -18,15 +18,12 @@
|
||||
//! Traits for dealing with dispatching calls and the origin from which they are dispatched.
|
||||
|
||||
use crate::dispatch::{DispatchResultWithPostInfo, Parameter, RawOrigin};
|
||||
use sp_arithmetic::traits::{CheckedSub, Zero};
|
||||
use sp_runtime::{
|
||||
traits::{BadOrigin, Member, Morph, TryMorph},
|
||||
Either,
|
||||
};
|
||||
use sp_std::marker::PhantomData;
|
||||
|
||||
use super::TypedGet;
|
||||
|
||||
/// Some sort of check on the origin is performed by this object.
|
||||
pub trait EnsureOrigin<OuterOrigin> {
|
||||
/// A return type.
|
||||
@@ -226,27 +223,6 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/// Mutator which reduces a scalar by a particular amount.
|
||||
pub struct ReduceBy<N>(PhantomData<N>);
|
||||
impl<N: TypedGet> TryMorph<N::Type> for ReduceBy<N>
|
||||
where
|
||||
N::Type: CheckedSub,
|
||||
{
|
||||
type Outcome = N::Type;
|
||||
fn try_morph(r: N::Type) -> Result<N::Type, ()> {
|
||||
r.checked_sub(&N::get()).ok_or(())
|
||||
}
|
||||
}
|
||||
impl<N: TypedGet> Morph<N::Type> for ReduceBy<N>
|
||||
where
|
||||
N::Type: CheckedSub + Zero,
|
||||
{
|
||||
type Outcome = N::Type;
|
||||
fn morph(r: N::Type) -> N::Type {
|
||||
r.checked_sub(&N::get()).unwrap_or(Zero::zero())
|
||||
}
|
||||
}
|
||||
|
||||
/// Type that can be dispatched with an origin but without checking the origin filter.
|
||||
///
|
||||
/// Implemented for pallet dispatchable type by `decl_module` and for runtime dispatchable by
|
||||
|
||||
Reference in New Issue
Block a user