Struct pallet_example_offchain_worker::pallet::Pallet[][src]

pub struct Pallet<T>(_);
Expand description

The pallet implementing the on-chain logic.

Implementations

A public part of the pallet.

Submit new price to the list.

This method is a public function of the module and can be called from within a transaction. It appends given price to current list of prices. In our example the offchain worker will create, sign & submit a transaction that calls this function passing the price.

The transaction needs to be signed (see ensure_signed) check, so that the caller pays a fee to execute it. This makes sure that it’s not easy (or rather cheap) to attack the chain by submitting excesive transactions, but note that it doesn’t ensure the price oracle is actually working and receives (and provides) meaningful data. This example is not focused on correctness of the oracle itself, but rather its purpose is to showcase offchain worker capabilities.

Submit new price to the list via unsigned transaction.

Works exactly like the submit_price function, but since we allow sending the transaction without a signature, and hence without paying any fees, we need a way to make sure that only some transactions are accepted. This function can be called only once every T::UnsignedInterval blocks. Transactions that call that function are de-duplicated on the pool level via validate_unsigned implementation and also are rendered invalid if the function has already been called in current “session”.

It’s important to specify weight for unsigned calls as well, because even though they don’t charge fees, we still don’t want a single block to contain unlimited number of such transactions.

This example is not focused on correctness of the oracle itself, but rather its purpose is to showcase offchain worker capabilities.

A vector of recently submitted prices.

This is used to calculate average price, should have bounded size.

Defines the block when next unsigned transaction will be accepted.

To prevent spam of unsigned (and unpayed!) transactions on the network, we only allow one transaction every T::UnsignedInterval blocks. This storage entry defines when new transaction is going to be accepted.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the current storage version as supported by the pallet.

Returns the on-chain storage version of the pallet as stored in the storage.

Offchain Worker entry point.

By implementing fn offchain_worker you declare a new offchain worker. This function will be called when the node is fully synced and a new best block is succesfuly imported. Note that it’s not guaranteed for offchain workers to run on EVERY block, there might be cases where some blocks are skipped, or for some the worker runs twice (re-orgs), so the code should be able to handle that. You can use Local Storage API to coordinate runs of the worker.

The block is being finalized. Implement to have something happen.

This will be run when the block is being finalized (before on_finalize). Implement to have something happen using the remaining weight. Will not fire if the remaining weight is 0. Return the weight used, the hook will subtract it from current weight used and pass the result to the next on_idle hook if it exists. Read more

The block is being initialized. Implement to have something happen. Read more

Perform a module upgrade. Read more

Execute some pre-checks prior to a runtime upgrade. Read more

Execute some post-checks after a runtime upgrade. Read more

Run integrity test. Read more

Run integrity test. Read more

This function is being called after every block import (when fully synced). Read more

The block is being finalized. Implement to have something happen. Read more

Something that should happen at genesis.

The block is being finalized. Implement to have something happen in case there is leftover weight. Check the passed remaining_weight to make sure it is high enough to allow for your pallet’s extra computation. Read more

The block is being initialized. Implement to have something happen. Read more

Perform a module upgrade. Read more

Execute some pre-checks prior to a runtime upgrade. Read more

Execute some post-checks after a runtime upgrade. Read more

Index of the pallet as configured in the runtime.

Name of the pallet as configured in the runtime.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Validate unsigned call to this module.

By default unsigned transactions are disallowed, but implementing the validator here we make sure that some particular calls (the ones produced by offchain worker) are being whitelisted and marked as valid.

The call to validate

Validate the call right before dispatch. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert from a value of T into an equivalent instance of Option<Self>. Read more

Consume self to return Some equivalent value of Option<T>. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Cast reference.

Cast reference.

Cast mutable reference.

Cast mutable reference.

Get a reference to the inner from the outer.

Get a mutable reference to the inner from the outer.

Generate a storage key unique to this runtime upgrade. Read more

Get temporary storage data written by Self::set_temp_storage. Read more

Write some temporary data to a specific storage that can be read (potentially in post-upgrade hook) via Self::get_temp_storage. Read more

Should always be Self

Convert from a value of T into an equivalent instance of Self. Read more

Consume self to return an equivalent value of T. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The counterpart to unchecked_from.

Consume self to return an equivalent value of T.