Frame: Give Referendum SubmitOrigin argument (#14326)

* Referedum's SubmitOrigin should have an arg

* Fixes

* Nits and two extra utils

* Fixes

* Fixes
This commit is contained in:
Gavin Wood
2023-06-12 09:10:19 +01:00
committed by GitHub
parent 62f37e105c
commit 9716c8a1cb
14 changed files with 462 additions and 88 deletions
+43 -6
View File
@@ -89,10 +89,11 @@ use frame_support::{
extract_actual_pays_fee, extract_actual_weight, DispatchClass, DispatchInfo,
DispatchResult, DispatchResultWithPostInfo, PerDispatchClass,
},
impl_ensure_origin_with_arg_ignoring_arg,
storage::{self, StorageStreamIter},
traits::{
ConstU32, Contains, EnsureOrigin, Get, HandleLifetime, OnKilledAccount, OnNewAccount,
OriginTrait, PalletInfo, SortedMembers, StoredMap, TypedGet,
ConstU32, Contains, EnsureOrigin, EnsureOriginWithArg, Get, HandleLifetime,
OnKilledAccount, OnNewAccount, OriginTrait, PalletInfo, SortedMembers, StoredMap, TypedGet,
},
Parameter,
};
@@ -265,7 +266,7 @@ pub mod pallet {
type RuntimeOrigin: Into<Result<RawOrigin<Self::AccountId>, Self::RuntimeOrigin>>
+ From<RawOrigin<Self::AccountId>>
+ Clone
+ OriginTrait<Call = Self::RuntimeCall>;
+ OriginTrait<Call = Self::RuntimeCall, AccountId = Self::AccountId>;
/// The aggregated `RuntimeCall` type.
#[pallet::no_default]
@@ -823,6 +824,12 @@ impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, Acco
}
}
impl_ensure_origin_with_arg_ignoring_arg! {
impl< { O: .., AccountId: Decode, T } >
EnsureOriginWithArg<O, T> for EnsureRoot<AccountId>
{}
}
/// Ensure the origin is Root and return the provided `Success` value.
pub struct EnsureRootWithSuccess<AccountId, Success>(
sp_std::marker::PhantomData<(AccountId, Success)>,
@@ -847,6 +854,12 @@ impl<
}
}
impl_ensure_origin_with_arg_ignoring_arg! {
impl< { O: .., AccountId: Decode, Success: TypedGet, T } >
EnsureOriginWithArg<O, T> for EnsureRootWithSuccess<AccountId, Success>
{}
}
/// Ensure the origin is provided `Ensure` origin and return the provided `Success` value.
pub struct EnsureWithSuccess<Ensure, AccountId, Success>(
sp_std::marker::PhantomData<(Ensure, AccountId, Success)>,
@@ -892,6 +905,12 @@ impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, Acco
}
}
impl_ensure_origin_with_arg_ignoring_arg! {
impl< { O: .., AccountId: Decode, T } >
EnsureOriginWithArg<O, T> for EnsureSigned<AccountId>
{}
}
/// Ensure the origin is `Signed` origin from the given `AccountId`.
pub struct EnsureSignedBy<Who, AccountId>(sp_std::marker::PhantomData<(Who, AccountId)>);
impl<
@@ -918,6 +937,12 @@ impl<
}
}
impl_ensure_origin_with_arg_ignoring_arg! {
impl< { O: .., Who: SortedMembers<AccountId>, AccountId: PartialEq + Clone + Ord + Decode, T } >
EnsureOriginWithArg<O, T> for EnsureSignedBy<Who, AccountId>
{}
}
/// Ensure the origin is `None`. i.e. unsigned transaction.
pub struct EnsureNone<AccountId>(sp_std::marker::PhantomData<AccountId>);
impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId>
@@ -937,10 +962,16 @@ impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, Acco
}
}
impl_ensure_origin_with_arg_ignoring_arg! {
impl< { O: .., AccountId, T } >
EnsureOriginWithArg<O, T> for EnsureNone<AccountId>
{}
}
/// Always fail.
pub struct EnsureNever<T>(sp_std::marker::PhantomData<T>);
impl<O, T> EnsureOrigin<O> for EnsureNever<T> {
type Success = T;
pub struct EnsureNever<Success>(sp_std::marker::PhantomData<Success>);
impl<O, Success> EnsureOrigin<O> for EnsureNever<Success> {
type Success = Success;
fn try_origin(o: O) -> Result<Self::Success, O> {
Err(o)
}
@@ -951,6 +982,12 @@ impl<O, T> EnsureOrigin<O> for EnsureNever<T> {
}
}
impl_ensure_origin_with_arg_ignoring_arg! {
impl< { O, Success, T } >
EnsureOriginWithArg<O, T> for EnsureNever<Success>
{}
}
/// Ensure that the origin `o` represents a signed extrinsic (i.e. transaction).
/// Returns `Ok` with the account that signed the extrinsic or an `Err` otherwise.
pub fn ensure_signed<OuterOrigin, AccountId>(o: OuterOrigin) -> Result<AccountId, BadOrigin>