mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 05:47:58 +00:00
ac3f14d23b
`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>
46 lines
1.5 KiB
TOML
46 lines
1.5 KiB
TOML
[package]
|
|
name = "pallet-examples"
|
|
version = "4.0.0-dev"
|
|
authors.workspace = true
|
|
edition.workspace = true
|
|
license = "Apache-2.0"
|
|
homepage = "https://substrate.io"
|
|
repository.workspace = true
|
|
description = "The single package with examples of various types of FRAME pallets"
|
|
publish = false
|
|
|
|
[package.metadata.docs.rs]
|
|
targets = ["x86_64-unknown-linux-gnu"]
|
|
|
|
[dependencies]
|
|
pallet-default-config-example = { path = "default-config", default-features = false }
|
|
pallet-dev-mode = { path = "dev-mode", default-features = false }
|
|
pallet-example-basic = { path = "basic", default-features = false }
|
|
pallet-example-frame-crate = { path = "frame-crate", default-features = false }
|
|
pallet-example-kitchensink = { path = "kitchensink", default-features = false }
|
|
pallet-example-offchain-worker = { path = "offchain-worker", default-features = false }
|
|
pallet-example-split = { path = "split", default-features = false }
|
|
pallet-example-tasks = { path = "tasks", default-features = false }
|
|
|
|
[features]
|
|
default = ["std"]
|
|
std = [
|
|
"pallet-default-config-example/std",
|
|
"pallet-dev-mode/std",
|
|
"pallet-example-basic/std",
|
|
"pallet-example-frame-crate/std",
|
|
"pallet-example-kitchensink/std",
|
|
"pallet-example-offchain-worker/std",
|
|
"pallet-example-split/std",
|
|
"pallet-example-tasks/std",
|
|
]
|
|
try-runtime = [
|
|
"pallet-default-config-example/try-runtime",
|
|
"pallet-dev-mode/try-runtime",
|
|
"pallet-example-basic/try-runtime",
|
|
"pallet-example-kitchensink/try-runtime",
|
|
"pallet-example-offchain-worker/try-runtime",
|
|
"pallet-example-split/try-runtime",
|
|
"pallet-example-tasks/try-runtime",
|
|
]
|