referrerpolicy=no-referrer-when-downgrade

Trait polkadot_sdk_frame::traits::tasks::Task

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§

type Enumeration: Iterator

An Iterator over tasks of this type used as the return type for enumerate.

Required Methods§

fn iter() -> Self::Enumeration

Inspects the pallet’s state and enumerates tasks of this type.

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.

fn run(&self) -> Result<(), DispatchError>

Performs the work for this particular Task variant.

fn weight(&self) -> Weight

Returns the weight of executing this Task.

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl Task for ()

§

type Enumeration = IntoIter<()>

§

fn iter() -> <() as Task>::Enumeration

§

fn is_valid(&self) -> bool

§

fn run(&self) -> Result<(), DispatchError>

§

fn weight(&self) -> Weight

§

fn task_index(&self) -> u32

Implementors§