Trait frame_support::traits::tasks::Task
source · pub trait Task: Sized + FullCodec + TypeInfo + Clone + Debug + PartialEq + Eq {
type Enumeration: Iterator;
// Required methods
fn iter() -> Self::Enumeration;
fn is_valid(&self) -> bool;
fn run(&self) -> Result<(), DispatchError>;
fn weight(&self) -> Weight;
fn task_index(&self) -> u32;
}
Expand description
A general-purpose trait which defines a type of service work (i.e., work to performed by an off-chain worker) including methods for enumerating, validating, indexing, and running tasks of this type.
Required Associated Types§
sourcetype Enumeration: Iterator
type Enumeration: Iterator
An Iterator
over tasks of this type used as the return type for enumerate
.
Required Methods§
sourcefn iter() -> Self::Enumeration
fn iter() -> Self::Enumeration
Inspects the pallet’s state and enumerates tasks of this type.
sourcefn is_valid(&self) -> bool
fn is_valid(&self) -> bool
Checks if a particular instance of this Task
variant is a valid piece of work.
This is used to validate tasks for unsigned execution. Hence, it MUST be cheap with minimal to no storage reads. Else, it can make the blockchain vulnerable to DoS attacks.
sourcefn run(&self) -> Result<(), DispatchError>
fn run(&self) -> Result<(), DispatchError>
Performs the work for this particular Task
variant.
sourcefn task_index(&self) -> u32
fn task_index(&self) -> u32
A unique value representing this Task
within the current pallet. Analogous to
call_index
, but for tasks.’
This value should be unique within the current pallet and can overlap with task indices in other pallets.