Skip to content

Commit 958e09e

Browse files
authored
"OR gate" for EnsureOrigin (#6237)
* 'OR gate' for EnsureOrigin. * Formatting. * More formatting. * Add docstring; Update 'Success' type. * Bump runtime impl_version. * Fix successful_origin. * Add either into std feature list. * Update docs.
1 parent 0bb8ec6 commit 958e09e

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use frame_support::{
7878
traits::{Currency, ReservableCurrency, OnUnbalanced, Get, BalanceStatus, EnsureOrigin},
7979
weights::Weight,
8080
};
81-
use frame_system::{self as system, ensure_signed, ensure_root};
81+
use frame_system::{self as system, ensure_signed};
8282

8383
mod benchmarking;
8484

@@ -635,9 +635,7 @@ decl_module! {
635635
/// # </weight>
636636
#[weight = weight_for::add_registrar::<T>(T::MaxRegistrars::get().into()) ]
637637
fn add_registrar(origin, account: T::AccountId) -> DispatchResultWithPostInfo {
638-
T::RegistrarOrigin::try_origin(origin)
639-
.map(|_| ())
640-
.or_else(ensure_root)?;
638+
T::RegistrarOrigin::ensure_origin(origin)?;
641639

642640
let (i, registrar_count) = <Registrars<T>>::try_mutate(
643641
|registrars| -> Result<(RegistrarIndex, usize), DispatchError> {
@@ -1108,9 +1106,7 @@ decl_module! {
11081106
T::MaxAdditionalFields::get().into(), // X
11091107
)]
11101108
fn kill_identity(origin, target: <T::Lookup as StaticLookup>::Source) -> DispatchResultWithPostInfo {
1111-
T::ForceOrigin::try_origin(origin)
1112-
.map(|_| ())
1113-
.or_else(ensure_root)?;
1109+
T::ForceOrigin::ensure_origin(origin)?;
11141110

11151111
// Figure out who we're meant to be clearing.
11161112
let target = T::Lookup::lookup(target)?;
@@ -1435,7 +1431,7 @@ mod tests {
14351431
new_test_ext().execute_with(|| {
14361432
assert_ok!(Identity::set_identity(Origin::signed(10), ten()));
14371433
assert_ok!(Identity::set_subs(Origin::signed(10), vec![(20, Data::Raw(vec![40; 1]))]));
1438-
assert_ok!(Identity::kill_identity(Origin::ROOT, 10));
1434+
assert_ok!(Identity::kill_identity(Origin::signed(2), 10));
14391435
assert_eq!(Balances::free_balance(10), 80);
14401436
assert!(Identity::super_of(20).is_none());
14411437
});

0 commit comments

Comments
 (0)