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.
pub fn submit_price_unsigned(
origin: OriginFor<T>,
_block_number: T::BlockNumber,
price: u32
) -> DispatchResultWithPostInfo
pub fn submit_price_unsigned(
origin: OriginFor<T>,
_block_number: T::BlockNumber,
price: u32
) -> DispatchResultWithPostInfo
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.
pub fn submit_price_unsigned_with_signed_payload(
origin: OriginFor<T>,
price_payload: PricePayload<T::Public, T::BlockNumber>,
_signature: T::Signature
) -> DispatchResultWithPostInfo
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 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
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.
Validate the call right before dispatch. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Pallet<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Pallet<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
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
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
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
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
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
impl<T> PalletVersionToStorageVersionHelper for T where
T: GetStorageVersion + PalletInfoAccess,
impl<T> PalletVersionToStorageVersionHelper for T where
T: GetStorageVersion + PalletInfoAccess,
type Output = T
type Output = T
Should always be Self
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
pub fn vzip(self) -> V
impl<T> MaybeDebug for T where
T: Debug,
impl<T> MaybeDebug for T where
T: Debug,