-
Notifications
You must be signed in to change notification settings - Fork 38
Pallet-scheduler Chain extension #148
base: polkadot-v0.9.39
Are you sure you want to change the base?
Conversation
Minimum allowed line rate is |
pub struct SchedulerExtension<T, W>(PhantomData<(T, W)>); | ||
|
||
impl<T, W> Default for SchedulerExtension<T, W> { | ||
fn default() -> Self { | ||
SchedulerExtension(PhantomData) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct SchedulerExtension<T, W>(PhantomData<(T, W)>); | |
impl<T, W> Default for SchedulerExtension<T, W> { | |
fn default() -> Self { | |
SchedulerExtension(PhantomData) | |
} | |
} | |
#[derive(DefaultNoBound)] | |
pub struct SchedulerExtension<T, W>(PhantomData<(T, W)>); |
No need to manually impl Default
, use use frame_support::DefaultNoBound;
enum SchedulerFunc { | ||
Schedule, | ||
Cancel, | ||
} | ||
|
||
impl TryFrom<u16> for SchedulerFunc { | ||
type Error = DispatchError; | ||
|
||
fn try_from(value: u16) -> Result<Self, Self::Error> { | ||
match value { | ||
1 => Ok(SchedulerFunc::Schedule), | ||
2 => Ok(SchedulerFunc::Cancel), | ||
_ => Err(DispatchError::Other( | ||
"PalletSchedulerExtension: Unimplemented func_id", | ||
)), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum SchedulerFunc { | |
Schedule, | |
Cancel, | |
} | |
impl TryFrom<u16> for SchedulerFunc { | |
type Error = DispatchError; | |
fn try_from(value: u16) -> Result<Self, Self::Error> { | |
match value { | |
1 => Ok(SchedulerFunc::Schedule), | |
2 => Ok(SchedulerFunc::Cancel), | |
_ => Err(DispatchError::Other( | |
"PalletSchedulerExtension: Unimplemented func_id", | |
)), | |
} | |
} | |
} | |
#[repr(u16)] | |
#[derive(TryFromPrimitive)] | |
enum SchedulerFunc { | |
Schedule = 1, | |
Cancel = 2, | |
} |
Using num_enum
will make this less error prone, right now enum values are not mapping 1 to 1 with TryFrom
implementation which is not ideal.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] | ||
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | ||
pub enum Origin { | ||
Caller, | ||
Address, | ||
} | ||
|
||
impl Default for Origin { | ||
fn default() -> Self { | ||
Self::Address | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] | |
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | |
pub enum Origin { | |
Caller, | |
Address, | |
} | |
impl Default for Origin { | |
fn default() -> Self { | |
Self::Address | |
} | |
} | |
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)] | |
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] | |
pub enum Origin { | |
Caller, | |
#[default] | |
Address, | |
} |
A General comment on the CE code structure we follow currently. We have If above assumption is correct then why is there a need to copy past the types to contract helpers in |
Because of the features hell that it will require: |
I understand, we don't want mutually exclusive features to make sure From my understanding, in the We have few options to fix this,
|
Here is the example for 1st approach, (code from XCM CE) |
@ashutoshvarma @Dinonard I think we can close this |
Pull Request Summary
Added two calls for pallet-scheduler chain extension:
Schedule
It schedule a call to another smart contract. It can be periodic or not. Origin is set as contract address
Cancel
The caller can cancel its call (only smart-contracts can be caller)
Also added tests for it.
Check list