Trait frame_support::traits::QueryPreimage
source · pub trait QueryPreimage {
// Required methods
fn len(hash: &Hash) -> Option<u32>;
fn fetch(hash: &Hash, len: Option<u32>) -> FetchResult;
fn is_requested(hash: &Hash) -> bool;
fn request(hash: &Hash);
fn unrequest(hash: &Hash);
// Provided methods
fn hold<T>(bounded: &Bounded<T>) { ... }
fn drop<T>(bounded: &Bounded<T>) { ... }
fn have<T>(bounded: &Bounded<T>) -> bool { ... }
fn pick<T>(hash: Hash, len: u32) -> Bounded<T> { ... }
fn peek<T: Decode>(
bounded: &Bounded<T>
) -> Result<(T, Option<u32>), DispatchError> { ... }
fn realize<T: Decode>(
bounded: &Bounded<T>
) -> Result<(T, Option<u32>), DispatchError> { ... }
}
Expand description
A interface for looking up preimages from their hash on chain.
Required Methods§
sourcefn len(hash: &Hash) -> Option<u32>
fn len(hash: &Hash) -> Option<u32>
Returns whether a preimage exists for a given hash and if so its length.
sourcefn fetch(hash: &Hash, len: Option<u32>) -> FetchResult
fn fetch(hash: &Hash, len: Option<u32>) -> FetchResult
Returns the preimage for a given hash. If given, len
must be the size of the preimage.
sourcefn is_requested(hash: &Hash) -> bool
fn is_requested(hash: &Hash) -> bool
Returns whether a preimage request exists for a given hash.
Provided Methods§
sourcefn hold<T>(bounded: &Bounded<T>)
fn hold<T>(bounded: &Bounded<T>)
Request that the data required for decoding the given bounded
value is made available.
sourcefn drop<T>(bounded: &Bounded<T>)
fn drop<T>(bounded: &Bounded<T>)
No longer request that the data required for decoding the given bounded
value is made
available.
sourcefn have<T>(bounded: &Bounded<T>) -> bool
fn have<T>(bounded: &Bounded<T>) -> bool
Check to see if all data required for the given bounded
value is available for its
decoding.
sourcefn pick<T>(hash: Hash, len: u32) -> Bounded<T>
fn pick<T>(hash: Hash, len: u32) -> Bounded<T>
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.
sourcefn peek<T: Decode>(
bounded: &Bounded<T>
) -> Result<(T, Option<u32>), DispatchError>
fn peek<T: Decode>( bounded: &Bounded<T> ) -> Result<(T, Option<u32>), DispatchError>
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.
sourcefn realize<T: Decode>(
bounded: &Bounded<T>
) -> Result<(T, Option<u32>), DispatchError>
fn realize<T: Decode>( bounded: &Bounded<T> ) -> Result<(T, Option<u32>), DispatchError>
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.