Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

add EnsureWithSuccess #12775

Merged
merged 4 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand All @@ -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! {
Expand Down
21 changes: 21 additions & 0 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,27 @@ impl<
}
}

pub struct EnsureWithSuccess<Ensure, AccountId, Success>(
sp_std::marker::PhantomData<(Ensure, AccountId, Success)>,
);
xlc marked this conversation as resolved.
Show resolved Hide resolved
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;
xlc marked this conversation as resolved.
Show resolved Hide resolved
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()
}
}

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>
Expand Down