Struct serp_example_ocw::Module[][src]

pub struct Module<T: Trait>(_);

A public part of the pallet.

Implementations

impl<T: Trait + 'static> Module<T>[src]

pub fn prices() -> Vec<u32>[src]

A vector of recently submitted prices.

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

pub fn next_unsigned_at() -> T::BlockNumber[src]

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.

impl<T: Trait> Module<T>[src]

Can also be called using Call.

pub fn submit_price(origin: T::Origin, price: u32) -> DispatchResult[src]

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.

NOTE: Calling this function will bypass origin filters.

pub fn submit_price_unsigned(
    origin: T::Origin,
    _block_number: T::BlockNumber,
    price: u32
) -> DispatchResult
[src]

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.

NOTE: Calling this function will bypass origin filters.

pub fn submit_price_unsigned_with_signed_payload(
    origin: T::Origin,
    price_payload: PricePayload<T::Public, T::BlockNumber>,
    _signature: T::Signature
) -> DispatchResult
[src]

NOTE: Calling this function will bypass origin filters.

Trait Implementations

impl<T: Trait> Callable<T> for Module<T>[src]

type Call = Call<T>

impl<T: Clone + Trait> Clone for Module<T>[src]

impl<T: Copy + Trait> Copy for Module<T>[src]

impl<T: Trait> Debug for Module<T> where
    T: Debug
[src]

impl<T: Eq + Trait> Eq for Module<T>[src]

impl<T: Trait> IntegrityTest for Module<T>[src]

impl<T: Trait> ModuleErrorMetadata for Module<T>[src]

impl<T: Trait + Trait> OffchainWorker<<T as Trait>::BlockNumber> for Module<T>[src]

impl<T: Trait + Trait> OnFinalize<<T as Trait>::BlockNumber> for Module<T>[src]

impl<T: Trait + Trait> OnInitialize<<T as Trait>::BlockNumber> for Module<T>[src]

impl<T: Trait> OnRuntimeUpgrade for Module<T>[src]

impl<T: PartialEq + Trait> PartialEq<Module<T>> for Module<T>[src]

impl<T: Trait> StructuralEq for Module<T>[src]

impl<T: Trait> StructuralPartialEq for Module<T>[src]

impl<T: Trait> ValidateUnsigned for Module<T>[src]

type Call = Call<T>

The call to validate

fn validate_unsigned(
    _source: TransactionSource,
    call: &Self::Call
) -> TransactionValidity
[src]

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.

Auto Trait Implementations

impl<T> RefUnwindSafe for Module<T> where
    T: RefUnwindSafe

impl<T> Send for Module<T> where
    T: Send

impl<T> Sync for Module<T> where
    T: Sync

impl<T> Unpin for Module<T> where
    T: Unpin

impl<T> UnwindSafe for Module<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CheckedConversion for T[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IsType<T> for T[src]

impl<T, Outer> IsWrappedBy<Outer> for T where
    T: From<Outer>,
    Outer: AsRef<T> + AsMut<T> + From<T>, 
[src]

pub fn from_ref(outer: &Outer) -> &T[src]

Get a reference to the inner from the outer.

pub fn from_mut(outer: &mut Outer) -> &mut T[src]

Get a mutable reference to the inner from the outer.

impl<T> MaybeDebug for T where
    T: Debug

impl<T> MaybeDebug for T where
    T: Debug

impl<T> MaybeRefUnwindSafe for T where
    T: RefUnwindSafe

impl<T> Member for T where
    T: 'static + Send + Sync + Debug + Eq + PartialEq<T> + Clone
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SaturatedConversion for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<S, T> UncheckedInto<T> for S where
    T: UncheckedFrom<S>, 
[src]

impl<T, S> UniqueSaturatedInto<T> for S where
    T: Bounded,
    S: TryInto<T>, 

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,