mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
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:
@@ -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>
|
||||
|
||||
@@ -746,19 +746,20 @@ fn ensure_signed_stuff_works() {
|
||||
}
|
||||
|
||||
let signed_origin = RuntimeOrigin::signed(0u64);
|
||||
assert_ok!(EnsureSigned::try_origin(signed_origin.clone()));
|
||||
assert_ok!(EnsureSignedBy::<Members, _>::try_origin(signed_origin));
|
||||
assert_ok!(<EnsureSigned<_> as EnsureOrigin<_>>::try_origin(signed_origin.clone()));
|
||||
assert_ok!(<EnsureSignedBy<Members, _> as EnsureOrigin<_>>::try_origin(signed_origin));
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
{
|
||||
let successful_origin: RuntimeOrigin = EnsureSigned::try_successful_origin()
|
||||
.expect("EnsureSigned has no successful origin required for the test");
|
||||
assert_ok!(EnsureSigned::try_origin(successful_origin));
|
||||
let successful_origin: RuntimeOrigin =
|
||||
<EnsureSigned<_> as EnsureOrigin<_>>::try_successful_origin()
|
||||
.expect("EnsureSigned has no successful origin required for the test");
|
||||
assert_ok!(<EnsureSigned<_> as EnsureOrigin<_>>::try_origin(successful_origin));
|
||||
|
||||
let successful_origin: RuntimeOrigin =
|
||||
EnsureSignedBy::<Members, _>::try_successful_origin()
|
||||
<EnsureSignedBy<Members, _> as EnsureOrigin<_>>::try_successful_origin()
|
||||
.expect("EnsureSignedBy has no successful origin required for the test");
|
||||
assert_ok!(EnsureSignedBy::<Members, _>::try_origin(successful_origin));
|
||||
assert_ok!(<EnsureSignedBy<Members, _> as EnsureOrigin<_>>::try_origin(successful_origin));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user