pub struct StorageQuery<V> { /* private fields */ }
Expand description
A typed query on chain state usable from an RPC client.
pub type Loc = (i64, i64, i64);
pub type Block = u8;
// Note that all fields are marked pub.
pub use self::pallet_test::*;
#[frame_support::pallet]
mod pallet_test {
use super::*;
use frame_support::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::storage]
pub type LastActionId<T> = StorageValue<_, u64, ValueQuery>;
#[pallet::storage]
pub type Voxels<T> = StorageMap<_, Blake2_128Concat, Loc, Block>;
#[pallet::storage]
pub type Actions<T> = StorageMap<_, Blake2_128Concat, u64, Loc>;
#[pallet::storage]
pub type Prefab<T> = StorageDoubleMap<
_,
Blake2_128Concat, u128,
Blake2_128Concat, (i8, i8, i8), Block
>;
}
#[tokio::main]
async fn main() -> Result<(), RpcError> {
let cl = WsClientBuilder::default().build("ws://[::1]:9944").await?;
let q = StorageQuery::value::<LastActionId<TestRuntime>>();
let hash = None::<Hash>;
let _: Option<u64> = q.get(&cl, hash).await?;
let q = StorageQuery::map::<Voxels<TestRuntime>, _>((0, 0, 0));
let _: Option<Block> = q.get(&cl, hash).await?;
let q = StorageQuery::map::<Actions<TestRuntime>, _>(12);
let _: Option<Loc> = q.get(&cl, hash).await?;
let q = StorageQuery::double_map::<Prefab<TestRuntime>, _, _>(3, (0, 0, 0));
let _: Option<Block> = q.get(&cl, hash).await?;
Ok(())
}
Implementations§
source§impl<V: FullCodec> StorageQuery<V>
impl<V: FullCodec> StorageQuery<V>
sourcepub fn map<St: StorageMap<K, V>, K: FullEncode>(key: K) -> Self
pub fn map<St: StorageMap<K, V>, K: FullEncode>(key: K) -> Self
Create a storage query for a value in a StorageMap.
sourcepub fn double_map<St: StorageDoubleMap<K1, K2, V>, K1: FullEncode, K2: FullEncode>(
key1: K1,
key2: K2
) -> Self
pub fn double_map<St: StorageDoubleMap<K1, K2, V>, K1: FullEncode, K2: FullEncode>( key1: K1, key2: K2 ) -> Self
Create a storage query for a value in a StorageDoubleMap.
sourcepub async fn get<Hash, StateClient>(
self,
state_client: &StateClient,
block_index: Option<Hash>
) -> Result<Option<V>, RpcError>where
Hash: Send + Sync + 'static + DeserializeOwned + Serialize,
StateClient: StateApiClient<Hash> + Sync,
pub async fn get<Hash, StateClient>(
self,
state_client: &StateClient,
block_index: Option<Hash>
) -> Result<Option<V>, RpcError>where
Hash: Send + Sync + 'static + DeserializeOwned + Serialize,
StateClient: StateApiClient<Hash> + Sync,
Send this query over RPC, await the typed result.
Hash should be <YourRuntime as frame::Config>::Hash
.
§Arguments
state_client represents a connection to the RPC server.
block_index indicates the block for which state will be queried. A value of None indicates the latest block.
Trait Implementations§
source§impl<V: Clone> Clone for StorageQuery<V>
impl<V: Clone> Clone for StorageQuery<V>
source§fn clone(&self) -> StorageQuery<V>
fn clone(&self) -> StorageQuery<V>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<V: Debug> Debug for StorageQuery<V>
impl<V: Debug> Debug for StorageQuery<V>
source§impl<V: Hash> Hash for StorageQuery<V>
impl<V: Hash> Hash for StorageQuery<V>
source§impl<V: Ord> Ord for StorageQuery<V>
impl<V: Ord> Ord for StorageQuery<V>
source§fn cmp(&self, other: &StorageQuery<V>) -> Ordering
fn cmp(&self, other: &StorageQuery<V>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<V: PartialEq> PartialEq for StorageQuery<V>
impl<V: PartialEq> PartialEq for StorageQuery<V>
source§fn eq(&self, other: &StorageQuery<V>) -> bool
fn eq(&self, other: &StorageQuery<V>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<V: PartialOrd> PartialOrd for StorageQuery<V>
impl<V: PartialOrd> PartialOrd for StorageQuery<V>
source§fn partial_cmp(&self, other: &StorageQuery<V>) -> Option<Ordering>
fn partial_cmp(&self, other: &StorageQuery<V>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<V: Eq> Eq for StorageQuery<V>
impl<V> StructuralPartialEq for StorageQuery<V>
Auto Trait Implementations§
impl<V> Freeze for StorageQuery<V>
impl<V> RefUnwindSafe for StorageQuery<V>where
V: RefUnwindSafe,
impl<V> Send for StorageQuery<V>where
V: Send,
impl<V> Sync for StorageQuery<V>where
V: Sync,
impl<V> Unpin for StorageQuery<V>where
V: Unpin,
impl<V> UnwindSafe for StorageQuery<V>where
V: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CallHasher for T
impl<T> CallHasher for T
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<T> DefensiveMax<T> for Twhere
T: PartialOrd,
impl<T> DefensiveMax<T> for Twhere
T: PartialOrd,
source§fn defensive_max(self, other: T) -> T
fn defensive_max(self, other: T) -> T
source§fn defensive_strict_max(self, other: T) -> T
fn defensive_strict_max(self, other: T) -> T
source§impl<T> DefensiveMin<T> for Twhere
T: PartialOrd,
impl<T> DefensiveMin<T> for Twhere
T: PartialOrd,
source§fn defensive_min(self, other: T) -> T
fn defensive_min(self, other: T) -> T
source§fn defensive_strict_min(self, other: T) -> T
fn defensive_strict_min(self, other: T) -> T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of
T
. Read moresource§impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
type Error = <U as TryFromKey<T>>::Error
fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>
source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
The counterpart to
unchecked_from
.source§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of
T
.