mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-04 19:47:23 +00:00
Tasks: general system for recognizing and executing service work (#1343)
`polkadot-sdk` version of original tasks PR located here: https://github.com/paritytech/substrate/pull/14329 Fixes #206 ## Status - [x] Generic `Task` trait - [x] `RuntimeTask` aggregated enum, compatible with `construct_runtime!` - [x] Casting between `Task` and `RuntimeTask` without needing `dyn` or `Box` - [x] Tasks Example pallet - [x] Runtime tests for Tasks example pallet - [x] Parsing for task-related macros - [x] Retrofit parsing to make macros optional - [x] Expansion for task-related macros - [x] Adds support for args in tasks - [x] Retrofit tasks example pallet to use macros instead of manual syntax - [x] Weights - [x] Cleanup - [x] UI tests - [x] Docs ## Target Syntax Adapted from https://github.com/paritytech/polkadot-sdk/issues/206#issue-1865172283 ```rust // NOTE: this enum is optional and is auto-generated by the other macros if not present #[pallet::task] pub enum Task<T: Config> { AddNumberIntoTotal { i: u32, } } /// Some running total. #[pallet::storage] pub(super) type Total<T: Config<I>, I: 'static = ()> = StorageValue<_, (u32, u32), ValueQuery>; /// Numbers to be added into the total. #[pallet::storage] pub(super) type Numbers<T: Config<I>, I: 'static = ()> = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>; #[pallet::tasks_experimental] impl<T: Config<I>, I: 'static> Pallet<T, I> { /// Add a pair of numbers into the totals and remove them. #[pallet::task_list(Numbers::<T, I>::iter_keys())] #[pallet::task_condition(|i| Numbers::<T, I>::contains_key(i))] #[pallet::task_index(0)] pub fn add_number_into_total(i: u32) -> DispatchResult { let v = Numbers::<T, I>::take(i).ok_or(Error::<T, I>::NotFound)?; Total::<T, I>::mutate(|(total_keys, total_values)| { *total_keys += i; *total_values += v; }); Ok(()) } } ``` --------- Co-authored-by: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Co-authored-by: kianenigma <kian@parity.io> Co-authored-by: Nikhil Gupta <> Co-authored-by: Gavin Wood <gavin@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: gupnik <nikhilgupta.iitk@gmail.com>
This commit is contained in:
@@ -646,7 +646,6 @@ pub fn storage_alias(attributes: TokenStream, input: TokenStream) -> TokenStream
|
||||
/// ```
|
||||
///
|
||||
/// where `TestDefaultConfig` was defined and registered as follows:
|
||||
///
|
||||
/// ```ignore
|
||||
/// pub struct TestDefaultConfig;
|
||||
///
|
||||
@@ -673,7 +672,6 @@ pub fn storage_alias(attributes: TokenStream, input: TokenStream) -> TokenStream
|
||||
/// ```
|
||||
///
|
||||
/// The above call to `derive_impl` would expand to roughly the following:
|
||||
///
|
||||
/// ```ignore
|
||||
/// impl frame_system::Config for Test {
|
||||
/// use frame_system::config_preludes::TestDefaultConfig;
|
||||
@@ -881,6 +879,7 @@ pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream {
|
||||
let item = syn::parse_macro_input!(item as TraitItemType);
|
||||
if item.ident != "RuntimeCall" &&
|
||||
item.ident != "RuntimeEvent" &&
|
||||
item.ident != "RuntimeTask" &&
|
||||
item.ident != "RuntimeOrigin" &&
|
||||
item.ident != "RuntimeHoldReason" &&
|
||||
item.ident != "RuntimeFreezeReason" &&
|
||||
@@ -888,10 +887,11 @@ pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream {
|
||||
{
|
||||
return syn::Error::new_spanned(
|
||||
item,
|
||||
"`#[inject_runtime_type]` can only be attached to `RuntimeCall`, `RuntimeEvent`, `RuntimeOrigin` or `PalletInfo`",
|
||||
"`#[inject_runtime_type]` can only be attached to `RuntimeCall`, `RuntimeEvent`, \
|
||||
`RuntimeTask`, `RuntimeOrigin` or `PalletInfo`",
|
||||
)
|
||||
.to_compile_error()
|
||||
.into();
|
||||
.into()
|
||||
}
|
||||
tokens
|
||||
}
|
||||
@@ -1518,6 +1518,56 @@ pub fn composite_enum(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pallet_macro_stub()
|
||||
}
|
||||
|
||||
///
|
||||
/// ---
|
||||
///
|
||||
/// **Rust-Analyzer users**: See the documentation of the Rust item in
|
||||
/// `frame_support::pallet_macros::tasks_experimental`.
|
||||
#[proc_macro_attribute]
|
||||
pub fn tasks_experimental(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pallet_macro_stub()
|
||||
}
|
||||
|
||||
///
|
||||
/// ---
|
||||
///
|
||||
/// **Rust-Analyzer users**: See the documentation of the Rust item in
|
||||
/// `frame_support::pallet_macros::task_list`.
|
||||
#[proc_macro_attribute]
|
||||
pub fn task_list(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pallet_macro_stub()
|
||||
}
|
||||
|
||||
///
|
||||
/// ---
|
||||
///
|
||||
/// **Rust-Analyzer users**: See the documentation of the Rust item in
|
||||
/// `frame_support::pallet_macros::task_condition`.
|
||||
#[proc_macro_attribute]
|
||||
pub fn task_condition(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pallet_macro_stub()
|
||||
}
|
||||
|
||||
///
|
||||
/// ---
|
||||
///
|
||||
/// **Rust-Analyzer users**: See the documentation of the Rust item in
|
||||
/// `frame_support::pallet_macros::task_weight`.
|
||||
#[proc_macro_attribute]
|
||||
pub fn task_weight(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pallet_macro_stub()
|
||||
}
|
||||
|
||||
///
|
||||
/// ---
|
||||
///
|
||||
/// **Rust-Analyzer users**: See the documentation of the Rust item in
|
||||
/// `frame_support::pallet_macros::task_index`.
|
||||
#[proc_macro_attribute]
|
||||
pub fn task_index(_: TokenStream, _: TokenStream) -> TokenStream {
|
||||
pallet_macro_stub()
|
||||
}
|
||||
|
||||
/// Can be attached to a module. Doing so will declare that module as importable into a pallet
|
||||
/// via [`#[import_section]`](`macro@import_section`).
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user