referrerpolicy=no-referrer-when-downgrade

Trait polkadot_sdk_frame::traits::QueryPreimage

pub trait QueryPreimage {
    type H: Hash;

    // Required methods
    fn len(hash: &<Self::H as Hasher>::Out) -> Option<u32>;
    fn fetch(
        hash: &<Self::H as Hasher>::Out,
        len: Option<u32>,
    ) -> Result<Cow<'static, [u8]>, DispatchError>;
    fn is_requested(hash: &<Self::H as Hasher>::Out) -> bool;
    fn request(hash: &<Self::H as Hasher>::Out);
    fn unrequest(hash: &<Self::H as Hasher>::Out);

    // Provided methods
    fn hold<T>(bounded: &Bounded<T, Self::H>) { ... }
    fn drop<T>(bounded: &Bounded<T, Self::H>) { ... }
    fn have<T>(bounded: &Bounded<T, Self::H>) -> bool { ... }
    fn pick<T>(hash: <Self::H as Hasher>::Out, len: u32) -> Bounded<T, Self::H> { ... }
    fn peek<T>(
        bounded: &Bounded<T, Self::H>,
    ) -> Result<(T, Option<u32>), DispatchError>
       where T: Decode { ... }
    fn realize<T>(
        bounded: &Bounded<T, Self::H>,
    ) -> Result<(T, Option<u32>), DispatchError>
       where T: Decode { ... }
}
Expand description

A interface for looking up preimages from their hash on chain.

Required Associated Types§

type H: Hash

The hasher used in the runtime.

Required Methods§

fn len(hash: &<Self::H as Hasher>::Out) -> Option<u32>

Returns whether a preimage exists for a given hash and if so its length.

fn fetch( hash: &<Self::H as Hasher>::Out, len: Option<u32>, ) -> Result<Cow<'static, [u8]>, DispatchError>

Returns the preimage for a given hash. If given, len must be the size of the preimage.

fn is_requested(hash: &<Self::H as Hasher>::Out) -> bool

Returns whether a preimage request exists for a given hash.

fn request(hash: &<Self::H as Hasher>::Out)

Request that someone report a preimage. Providers use this to optimise the economics for preimage reporting.

fn unrequest(hash: &<Self::H as Hasher>::Out)

Cancel a previous preimage request.

Provided Methods§

fn hold<T>(bounded: &Bounded<T, Self::H>)

Request that the data required for decoding the given bounded value is made available.

fn drop<T>(bounded: &Bounded<T, Self::H>)

No longer request that the data required for decoding the given bounded value is made available.

fn have<T>(bounded: &Bounded<T, Self::H>) -> bool

Check to see if all data required for the given bounded value is available for its decoding.

fn pick<T>(hash: <Self::H as Hasher>::Out, len: u32) -> Bounded<T, Self::H>

Create a Bounded instance based on the hash and len of the encoded value.

It also directly requests the given hash using Self::request.

This may not be peek-able or realize-able.

fn peek<T>( bounded: &Bounded<T, Self::H>, ) -> Result<(T, Option<u32>), DispatchError>
where T: Decode,

Convert the given bounded instance back into its original instance, also returning the exact size of its encoded form if it needed to be looked-up from a stored preimage).

NOTE: This does not remove any data needed for realization. If you will no longer use the bounded, call realize instead or call drop afterwards.

fn realize<T>( bounded: &Bounded<T, Self::H>, ) -> Result<(T, Option<u32>), DispatchError>
where T: Decode,

Convert the given bounded value back into its original instance. If successful, drop any data backing it. This will not break the realisability of independently created instances of Bounded which happen to have identical data.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl QueryPreimage for ()

§

type H = BlakeTwo256

§

fn len(_: &H256) -> Option<u32>

§

fn fetch(_: &H256, _: Option<u32>) -> Result<Cow<'static, [u8]>, DispatchError>

§

fn is_requested(_: &H256) -> bool

§

fn request(_: &H256)

§

fn unrequest(_: &H256)

Implementors§