mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 07:31:02 +00:00
Simplify operational extrinsics (#810)
* Simplify operational extrinsics * Remove old extrinsics from finality verifier
This commit is contained in:
committed by
Bastian Köcher
parent
8f11732bb9
commit
47aa6634a2
@@ -222,26 +222,19 @@ pub mod pallet {
|
|||||||
Ok(().into())
|
Ok(().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Halt all pallet operations. Operations may be resumed using `resume_operations` call.
|
/// Halt or resume all pallet operations.
|
||||||
///
|
///
|
||||||
/// May only be called either by root, or by `ModuleOwner`.
|
/// May only be called either by root, or by `ModuleOwner`.
|
||||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||||
pub fn halt_operations(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
pub fn set_operational(origin: OriginFor<T>, operational: bool) -> DispatchResultWithPostInfo {
|
||||||
ensure_owner_or_root::<T>(origin)?;
|
ensure_owner_or_root::<T>(origin)?;
|
||||||
<IsHalted<T>>::put(true);
|
<IsHalted<T>>::put(operational);
|
||||||
log::warn!("Stopping pallet operations.");
|
|
||||||
|
|
||||||
Ok(().into())
|
if operational {
|
||||||
}
|
log::info!("Resuming pallet operations.");
|
||||||
|
} else {
|
||||||
/// Resume all pallet operations. May be called even if pallet is halted.
|
log::warn!("Stopping pallet operations.");
|
||||||
///
|
}
|
||||||
/// May only be called either by root, or by `ModuleOwner`.
|
|
||||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
|
||||||
pub fn resume_operations(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
|
||||||
ensure_owner_or_root::<T>(origin)?;
|
|
||||||
<IsHalted<T>>::put(false);
|
|
||||||
log::info!("Resuming pallet operations.");
|
|
||||||
|
|
||||||
Ok(().into())
|
Ok(().into())
|
||||||
}
|
}
|
||||||
@@ -655,29 +648,29 @@ mod tests {
|
|||||||
|
|
||||||
assert_ok!(Module::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
assert_ok!(Module::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::halt_operations(Origin::signed(2)),
|
Module::<TestRuntime>::set_operational(Origin::signed(2), false),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::root()));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
|
||||||
|
|
||||||
assert_ok!(Module::<TestRuntime>::set_owner(Origin::signed(1), None));
|
assert_ok!(Module::<TestRuntime>::set_owner(Origin::signed(1), None));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
|
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::resume_operations(Origin::signed(2)),
|
Module::<TestRuntime>::set_operational(Origin::signed(2), true),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::root()));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pallet_may_be_halted_by_root() {
|
fn pallet_may_be_halted_by_root() {
|
||||||
run_test(|| {
|
run_test(|| {
|
||||||
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::root()));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
|
||||||
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::root()));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,21 +679,21 @@ mod tests {
|
|||||||
run_test(|| {
|
run_test(|| {
|
||||||
ModuleOwner::<TestRuntime>::put(2);
|
ModuleOwner::<TestRuntime>::put(2);
|
||||||
|
|
||||||
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::signed(2)));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||||
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::signed(2)));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), true));
|
||||||
|
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::halt_operations(Origin::signed(1)),
|
Module::<TestRuntime>::set_operational(Origin::signed(1), false),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
|
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::signed(2)));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
|
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -264,24 +264,19 @@ decl_module! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Halt all pallet operations. Operations may be resumed using `resume_operations` call.
|
/// Halt or resume all pallet operations.
|
||||||
///
|
///
|
||||||
/// May only be called either by root, or by `ModuleOwner`.
|
/// May only be called either by root, or by `ModuleOwner`.
|
||||||
#[weight = (T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational)]
|
#[weight = (T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational)]
|
||||||
pub fn halt_operations(origin) {
|
pub fn set_operational(origin, operational: bool) {
|
||||||
ensure_owner_or_root::<T, I>(origin)?;
|
ensure_owner_or_root::<T, I>(origin)?;
|
||||||
IsHalted::<I>::put(true);
|
<IsHalted<I>>::put(operational);
|
||||||
log::warn!("Stopping pallet operations.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resume all pallet operations. May be called even if pallet is halted.
|
if operational {
|
||||||
///
|
log::info!("Resuming pallet operations.");
|
||||||
/// May only be called either by root, or by `ModuleOwner`.
|
} else {
|
||||||
#[weight = (T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational)]
|
log::warn!("Stopping pallet operations.");
|
||||||
pub fn resume_operations(origin) {
|
}
|
||||||
ensure_owner_or_root::<T, I>(origin)?;
|
|
||||||
IsHalted::<I>::put(false);
|
|
||||||
log::info!("Resuming pallet operations.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update pallet parameter.
|
/// Update pallet parameter.
|
||||||
@@ -915,29 +910,29 @@ mod tests {
|
|||||||
|
|
||||||
assert_ok!(Module::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
assert_ok!(Module::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::halt_operations(Origin::signed(2)),
|
Module::<TestRuntime>::set_operational(Origin::signed(2), false),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::root()));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
|
||||||
|
|
||||||
assert_ok!(Module::<TestRuntime>::set_owner(Origin::signed(1), None));
|
assert_ok!(Module::<TestRuntime>::set_owner(Origin::signed(1), None));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
|
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::resume_operations(Origin::signed(2)),
|
Module::<TestRuntime>::set_operational(Origin::signed(2), true),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::root()));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pallet_may_be_halted_by_root() {
|
fn pallet_may_be_halted_by_root() {
|
||||||
run_test(|| {
|
run_test(|| {
|
||||||
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::root()));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), false));
|
||||||
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::root()));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::root(), true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -946,21 +941,21 @@ mod tests {
|
|||||||
run_test(|| {
|
run_test(|| {
|
||||||
ModuleOwner::<TestRuntime>::put(2);
|
ModuleOwner::<TestRuntime>::put(2);
|
||||||
|
|
||||||
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::signed(2)));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||||
assert_ok!(Module::<TestRuntime>::resume_operations(Origin::signed(2)));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), true));
|
||||||
|
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::halt_operations(Origin::signed(1)),
|
Module::<TestRuntime>::set_operational(Origin::signed(1), false),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
|
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ok!(Module::<TestRuntime>::halt_operations(Origin::signed(2)));
|
assert_ok!(Module::<TestRuntime>::set_operational(Origin::signed(2), false));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Module::<TestRuntime>::resume_operations(Origin::signed(1)),
|
Module::<TestRuntime>::set_operational(Origin::signed(1), true),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user