BREAKING: Rename Origin (#12258)

* BREAKING: Rename Origin

* more renaming

* a bit more renaming

* fix

* more fixing

* fix in frame_support

* even more fixes

* fix

* small fix

* ...

* update .stderr

* docs

* update docs

* update docs

* docs
This commit is contained in:
Sergej Sakac
2022-09-21 00:13:09 +02:00
committed by GitHub
parent 986d20b352
commit e4b6f4a66d
221 changed files with 5233 additions and 4200 deletions
@@ -31,7 +31,7 @@ use frame_system::Pallet as System;
const BLOCK_NUMBER: u32 = 2;
type SystemOrigin<T> = <T as frame_system::Config>::Origin;
type SystemOrigin<T> = <T as frame_system::Config>::RuntimeOrigin;
/// Add `n` named items to the schedule.
///
+17 -14
View File
@@ -202,17 +202,19 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The aggregated origin which the dispatch will take.
type Origin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>
type RuntimeOrigin: OriginTrait<PalletsOrigin = Self::PalletsOrigin>
+ From<Self::PalletsOrigin>
+ IsType<<Self as system::Config>::Origin>;
+ IsType<<Self as system::Config>::RuntimeOrigin>;
/// The caller origin, overarching type of all pallets origins.
type PalletsOrigin: From<system::RawOrigin<Self::AccountId>> + Codec + Clone + Eq + TypeInfo;
/// The aggregated call type.
type RuntimeCall: Parameter
+ Dispatchable<Origin = <Self as Config>::Origin, PostInfo = PostDispatchInfo>
+ GetDispatchInfo
+ Dispatchable<
RuntimeOrigin = <Self as Config>::RuntimeOrigin,
PostInfo = PostDispatchInfo,
> + GetDispatchInfo
+ From<system::Call<Self>>;
/// The maximum weight that may be scheduled per block for any dispatchables of less
@@ -221,7 +223,7 @@ pub mod pallet {
type MaximumWeight: Get<Weight>;
/// Required origin to schedule or cancel calls.
type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::Origin>;
type ScheduleOrigin: EnsureOrigin<<Self as system::Config>::RuntimeOrigin>;
/// Compare the privileges of origins.
///
@@ -354,9 +356,10 @@ pub mod pallet {
let periodic = s.maybe_periodic.is_some();
let call_weight = call.get_dispatch_info().weight;
let mut item_weight = T::WeightInfo::item(periodic, named, Some(resolved));
let origin =
<<T as Config>::Origin as From<T::PalletsOrigin>>::from(s.origin.clone())
.into();
let origin = <<T as Config>::RuntimeOrigin as From<T::PalletsOrigin>>::from(
s.origin.clone(),
)
.into();
if ensure_signed(origin).is_ok() {
// Weights of Signed dispatches expect their signing account to be whitelisted.
item_weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
@@ -431,7 +434,7 @@ pub mod pallet {
call: Box<CallOrHashOf<T>>,
) -> DispatchResult {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Config>::Origin::from(origin);
let origin = <T as Config>::RuntimeOrigin::from(origin);
Self::do_schedule(
DispatchTime::At(when),
maybe_periodic,
@@ -446,7 +449,7 @@ pub mod pallet {
#[pallet::weight(<T as Config>::WeightInfo::cancel(T::MaxScheduledPerBlock::get()))]
pub fn cancel(origin: OriginFor<T>, when: T::BlockNumber, index: u32) -> DispatchResult {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Config>::Origin::from(origin);
let origin = <T as Config>::RuntimeOrigin::from(origin);
Self::do_cancel(Some(origin.caller().clone()), (when, index))?;
Ok(())
}
@@ -462,7 +465,7 @@ pub mod pallet {
call: Box<CallOrHashOf<T>>,
) -> DispatchResult {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Config>::Origin::from(origin);
let origin = <T as Config>::RuntimeOrigin::from(origin);
Self::do_schedule_named(
id,
DispatchTime::At(when),
@@ -478,7 +481,7 @@ pub mod pallet {
#[pallet::weight(<T as Config>::WeightInfo::cancel_named(T::MaxScheduledPerBlock::get()))]
pub fn cancel_named(origin: OriginFor<T>, id: Vec<u8>) -> DispatchResult {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Config>::Origin::from(origin);
let origin = <T as Config>::RuntimeOrigin::from(origin);
Self::do_cancel_named(Some(origin.caller().clone()), id)?;
Ok(())
}
@@ -497,7 +500,7 @@ pub mod pallet {
call: Box<CallOrHashOf<T>>,
) -> DispatchResult {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Config>::Origin::from(origin);
let origin = <T as Config>::RuntimeOrigin::from(origin);
Self::do_schedule(
DispatchTime::After(after),
maybe_periodic,
@@ -523,7 +526,7 @@ pub mod pallet {
call: Box<CallOrHashOf<T>>,
) -> DispatchResult {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Config>::Origin::from(origin);
let origin = <T as Config>::RuntimeOrigin::from(origin);
Self::do_schedule_named(
id,
DispatchTime::After(after),
+3 -3
View File
@@ -70,7 +70,7 @@ pub mod logger {
#[pallet::call]
impl<T: Config> Pallet<T>
where
<T as frame_system::Config>::Origin: OriginTrait<PalletsOrigin = OriginCaller>,
<T as frame_system::Config>::RuntimeOrigin: OriginTrait<PalletsOrigin = OriginCaller>,
{
#[pallet::weight(*weight)]
pub fn log(origin: OriginFor<T>, i: u32, weight: Weight) -> DispatchResult {
@@ -125,7 +125,7 @@ impl system::Config for Test {
type BlockWeights = ();
type BlockLength = ();
type DbWeight = RocksDbWeight;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
@@ -169,7 +169,7 @@ impl pallet_preimage::Config for Test {
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type Origin = Origin;
type RuntimeOrigin = RuntimeOrigin;
type PalletsOrigin = OriginCaller;
type RuntimeCall = RuntimeCall;
type MaximumWeight = MaximumSchedulerWeight;
+16 -9
View File
@@ -52,7 +52,7 @@ fn scheduling_with_preimages_works() {
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) });
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call);
let hashed = MaybeHashed::Hash(hash);
assert_ok!(Preimage::note_preimage(Origin::signed(0), call.encode()));
assert_ok!(Preimage::note_preimage(RuntimeOrigin::signed(0), call.encode()));
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), hashed));
assert!(Preimage::preimage_requested(&hash));
run_to_block(3);
@@ -82,7 +82,7 @@ fn scheduling_with_preimage_postpones_correctly() {
assert!(logger::log().is_empty());
// Register preimage.
assert_ok!(Preimage::note_preimage(Origin::signed(0), call.encode()));
assert_ok!(Preimage::note_preimage(RuntimeOrigin::signed(0), call.encode()));
run_to_block(5);
// #5 empty since postponement is 2 blocks.
@@ -619,14 +619,21 @@ fn root_calls_works() {
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) })
.into(),
);
assert_ok!(Scheduler::schedule_named(Origin::root(), 1u32.encode(), 4, None, 127, call,));
assert_ok!(Scheduler::schedule(Origin::root(), 4, None, 127, call2));
assert_ok!(Scheduler::schedule_named(
RuntimeOrigin::root(),
1u32.encode(),
4,
None,
127,
call,
));
assert_ok!(Scheduler::schedule(RuntimeOrigin::root(), 4, None, 127, call2));
run_to_block(3);
// Scheduled calls are in the agenda.
assert_eq!(Agenda::<Test>::get(4).len(), 2);
assert!(logger::log().is_empty());
assert_ok!(Scheduler::cancel_named(Origin::root(), 1u32.encode()));
assert_ok!(Scheduler::cancel(Origin::root(), 4, 1));
assert_ok!(Scheduler::cancel_named(RuntimeOrigin::root(), 1u32.encode()));
assert_ok!(Scheduler::cancel(RuntimeOrigin::root(), 4, 1));
// Scheduled calls are made NONE, so should not effect state
run_to_block(100);
assert!(logger::log().is_empty());
@@ -651,17 +658,17 @@ fn fails_to_schedule_task_in_the_past() {
.into(),
);
assert_err!(
Scheduler::schedule_named(Origin::root(), 1u32.encode(), 2, None, 127, call1),
Scheduler::schedule_named(RuntimeOrigin::root(), 1u32.encode(), 2, None, 127, call1),
Error::<Test>::TargetBlockNumberInPast,
);
assert_err!(
Scheduler::schedule(Origin::root(), 2, None, 127, call2),
Scheduler::schedule(RuntimeOrigin::root(), 2, None, 127, call2),
Error::<Test>::TargetBlockNumberInPast,
);
assert_err!(
Scheduler::schedule(Origin::root(), 3, None, 127, call3),
Scheduler::schedule(RuntimeOrigin::root(), 3, None, 127, call3),
Error::<Test>::TargetBlockNumberInPast,
);
});