mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 08:11:04 +00:00
add EnsureWithSuccess (#12775)
* add EnsureWithSuccess * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * add docs Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -44,7 +44,7 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::{
|
||||
limits::{BlockLength, BlockWeights},
|
||||
EnsureRoot, EnsureRootWithSuccess, EnsureSigned,
|
||||
EnsureRoot, EnsureRootWithSuccess, EnsureSigned, EnsureWithSuccess,
|
||||
};
|
||||
pub use node_primitives::{AccountId, Signature};
|
||||
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
|
||||
@@ -1076,6 +1076,7 @@ parameter_types! {
|
||||
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
|
||||
pub const MaximumReasonLength: u32 = 300;
|
||||
pub const MaxApprovals: u32 = 100;
|
||||
pub const MaxBalance: Balance = Balance::max_value();
|
||||
}
|
||||
|
||||
impl pallet_treasury::Config for Runtime {
|
||||
@@ -1100,7 +1101,7 @@ impl pallet_treasury::Config for Runtime {
|
||||
type SpendFunds = Bounties;
|
||||
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
|
||||
type MaxApprovals = MaxApprovals;
|
||||
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<u128>;
|
||||
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
||||
@@ -775,6 +775,7 @@ impl From<sp_version::RuntimeVersion> for LastRuntimeUpgradeInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure the origin is Root.
|
||||
pub struct EnsureRoot<AccountId>(sp_std::marker::PhantomData<AccountId>);
|
||||
impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId>
|
||||
EnsureOrigin<O> for EnsureRoot<AccountId>
|
||||
@@ -793,6 +794,7 @@ impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, Acco
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure the origin is Root and return the provided `Success` value.
|
||||
pub struct EnsureRootWithSuccess<AccountId, Success>(
|
||||
sp_std::marker::PhantomData<(AccountId, Success)>,
|
||||
);
|
||||
@@ -816,6 +818,31 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/// 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)>,
|
||||
);
|
||||
|
||||
impl<
|
||||
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
|
||||
Ensure: EnsureOrigin<O>,
|
||||
AccountId,
|
||||
Success: TypedGet,
|
||||
> EnsureOrigin<O> for EnsureWithSuccess<Ensure, AccountId, Success>
|
||||
{
|
||||
type Success = Success::Type;
|
||||
|
||||
fn try_origin(o: O) -> Result<Self::Success, O> {
|
||||
Ensure::try_origin(o).map(|_| Success::get())
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin() -> Result<O, ()> {
|
||||
Ensure::try_successful_origin()
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure the origin is any `Signed` origin.
|
||||
pub struct EnsureSigned<AccountId>(sp_std::marker::PhantomData<AccountId>);
|
||||
impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, AccountId: Decode>
|
||||
EnsureOrigin<O> for EnsureSigned<AccountId>
|
||||
@@ -836,6 +863,7 @@ impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, Acco
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure the origin is `Signed` origin from the given `AccountId`.
|
||||
pub struct EnsureSignedBy<Who, AccountId>(sp_std::marker::PhantomData<(Who, AccountId)>);
|
||||
impl<
|
||||
O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>,
|
||||
@@ -864,6 +892,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/// 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>
|
||||
EnsureOrigin<O> for EnsureNone<AccountId>
|
||||
@@ -882,6 +911,7 @@ impl<O: Into<Result<RawOrigin<AccountId>, O>> + From<RawOrigin<AccountId>>, Acco
|
||||
}
|
||||
}
|
||||
|
||||
/// Always fail.
|
||||
pub struct EnsureNever<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<O, T> EnsureOrigin<O> for EnsureNever<T> {
|
||||
type Success = T;
|
||||
|
||||
Reference in New Issue
Block a user