mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Remove u32_trait (#10850)
* Remove `u32_trait` This trait only existed because there wasn't any const generic support at time of creation. However, we now have support for it :) * FMT
This commit is contained in:
@@ -43,7 +43,6 @@
|
||||
#![recursion_limit = "128"]
|
||||
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::u32_trait::Value as U32;
|
||||
use sp_io::storage;
|
||||
use sp_runtime::{traits::Hash, RuntimeDebug};
|
||||
use sp_std::{marker::PhantomData, prelude::*, result};
|
||||
@@ -1011,43 +1010,43 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureMembers<N: U32, AccountId, I: 'static>(PhantomData<(N, AccountId, I)>);
|
||||
pub struct EnsureMembers<AccountId, I: 'static, const N: u32>(PhantomData<(AccountId, I)>);
|
||||
impl<
|
||||
O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
|
||||
N: U32,
|
||||
AccountId,
|
||||
I,
|
||||
> EnsureOrigin<O> for EnsureMembers<N, AccountId, I>
|
||||
const N: u32,
|
||||
> EnsureOrigin<O> for EnsureMembers<AccountId, I, N>
|
||||
{
|
||||
type Success = (MemberCount, MemberCount);
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
o.into().and_then(|o| match o {
|
||||
RawOrigin::Members(n, m) if n >= N::VALUE => Ok((n, m)),
|
||||
RawOrigin::Members(n, m) if n >= N => Ok((n, m)),
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn successful_origin() -> O {
|
||||
O::from(RawOrigin::Members(N::VALUE, N::VALUE))
|
||||
O::from(RawOrigin::Members(N, N))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureProportionMoreThan<N: U32, D: U32, AccountId, I: 'static>(
|
||||
PhantomData<(N, D, AccountId, I)>,
|
||||
pub struct EnsureProportionMoreThan<AccountId, I: 'static, const N: u32, const D: u32>(
|
||||
PhantomData<(AccountId, I)>,
|
||||
);
|
||||
impl<
|
||||
O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
|
||||
N: U32,
|
||||
D: U32,
|
||||
AccountId,
|
||||
I,
|
||||
> EnsureOrigin<O> for EnsureProportionMoreThan<N, D, AccountId, I>
|
||||
const N: u32,
|
||||
const D: u32,
|
||||
> EnsureOrigin<O> for EnsureProportionMoreThan<AccountId, I, N, D>
|
||||
{
|
||||
type Success = ();
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
o.into().and_then(|o| match o {
|
||||
RawOrigin::Members(n, m) if n * D::VALUE > N::VALUE * m => Ok(()),
|
||||
RawOrigin::Members(n, m) if n * D > N * m => Ok(()),
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
@@ -1058,21 +1057,21 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EnsureProportionAtLeast<N: U32, D: U32, AccountId, I: 'static>(
|
||||
PhantomData<(N, D, AccountId, I)>,
|
||||
pub struct EnsureProportionAtLeast<AccountId, I: 'static, const N: u32, const D: u32>(
|
||||
PhantomData<(AccountId, I)>,
|
||||
);
|
||||
impl<
|
||||
O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
|
||||
N: U32,
|
||||
D: U32,
|
||||
AccountId,
|
||||
I,
|
||||
> EnsureOrigin<O> for EnsureProportionAtLeast<N, D, AccountId, I>
|
||||
const N: u32,
|
||||
const D: u32,
|
||||
> EnsureOrigin<O> for EnsureProportionAtLeast<AccountId, I, N, D>
|
||||
{
|
||||
type Success = ();
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
o.into().and_then(|o| match o {
|
||||
RawOrigin::Members(n, m) if n * D::VALUE >= N::VALUE * m => Ok(()),
|
||||
RawOrigin::Members(n, m) if n * D >= N * m => Ok(()),
|
||||
r => Err(O::from(r)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -24,10 +24,7 @@ use frame_support::{
|
||||
Hashable,
|
||||
};
|
||||
use frame_system::{EventRecord, Phase};
|
||||
use sp_core::{
|
||||
u32_trait::{_3, _4},
|
||||
H256,
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
@@ -142,7 +139,7 @@ impl Config<Instance2> for Test {
|
||||
}
|
||||
impl mock_democracy::Config for Test {
|
||||
type Event = Event;
|
||||
type ExternalMajorityOrigin = EnsureProportionAtLeast<_3, _4, u64, Instance1>;
|
||||
type ExternalMajorityOrigin = EnsureProportionAtLeast<u64, Instance1, 3, 4>;
|
||||
}
|
||||
impl Config for Test {
|
||||
type Origin = Origin;
|
||||
|
||||
Reference in New Issue
Block a user