diff --git a/substrate/frame/nomination-pools/src/lib.rs b/substrate/frame/nomination-pools/src/lib.rs index 017eac8ee2aebb2acf65634cb90958815fbbc7ae..0fff470eec43be64d07b4effdf23b973d9d03f63 100644 --- a/substrate/frame/nomination-pools/src/lib.rs +++ b/substrate/frame/nomination-pools/src/lib.rs @@ -1854,22 +1854,17 @@ pub mod pallet { nominator: Option<T::AccountId>, state_toggler: Option<T::AccountId>, ) -> DispatchResult { - let o1 = origin; - let o2 = o1.clone(); - - let mut bonded_pool = BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?; - let is_pool_root = || -> Result<(), sp_runtime::DispatchError> { - let who = ensure_signed(o1)?; - ensure!(bonded_pool.can_update_roles(&who), Error::<T>::DoesNotHavePermission); - Ok(()) - }; - let is_root = || -> Result<(), sp_runtime::DispatchError> { - ensure_root(o2)?; - Ok(()) + let mut bonded_pool = match ensure_root(origin.clone()) { + Ok(()) => BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?, + Err(frame_support::error::BadOrigin) => { + let who = ensure_signed(origin)?; + let bonded_pool = + BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?; + ensure!(bonded_pool.can_update_roles(&who), Error::<T>::DoesNotHavePermission); + bonded_pool + }, }; - let _ = is_root().or_else(|_| is_pool_root())?; - match root { None => (), Some(v) => bonded_pool.roles.root = v,