Trait cnidarium::StateRead

source ·
pub trait StateRead: Send + Sync {
    type GetRawFut: Future<Output = Result<Option<Vec<u8>>>> + Send + 'static;
    type PrefixRawStream: Stream<Item = Result<(String, Vec<u8>)>> + Send + 'static;
    type PrefixKeysStream: Stream<Item = Result<String>> + Send + 'static;
    type NonconsensusPrefixRawStream: Stream<Item = Result<(Vec<u8>, Vec<u8>)>> + Send + 'static;
    type NonconsensusRangeRawStream: Stream<Item = Result<(Vec<u8>, Vec<u8>)>> + Send + 'static;

    // Required methods
    fn get_raw(&self, key: &str) -> Self::GetRawFut;
    fn nonverifiable_get_raw(&self, key: &[u8]) -> Self::GetRawFut;
    fn object_get<T: Any + Send + Sync + Clone>(
        &self,
        key: &'static str
    ) -> Option<T>;
    fn object_type(&self, key: &'static str) -> Option<TypeId>;
    fn prefix_raw(&self, prefix: &str) -> Self::PrefixRawStream;
    fn prefix_keys(&self, prefix: &str) -> Self::PrefixKeysStream;
    fn nonverifiable_prefix_raw(
        &self,
        prefix: &[u8]
    ) -> Self::NonconsensusPrefixRawStream;
    fn nonverifiable_range_raw(
        &self,
        prefix: Option<&[u8]>,
        range: impl RangeBounds<Vec<u8>>
    ) -> Result<Self::NonconsensusRangeRawStream>;
}
Expand description

Read access to chain state.

Required Associated Types§

source

type GetRawFut: Future<Output = Result<Option<Vec<u8>>>> + Send + 'static

source

type PrefixRawStream: Stream<Item = Result<(String, Vec<u8>)>> + Send + 'static

source

type PrefixKeysStream: Stream<Item = Result<String>> + Send + 'static

source

type NonconsensusPrefixRawStream: Stream<Item = Result<(Vec<u8>, Vec<u8>)>> + Send + 'static

source

type NonconsensusRangeRawStream: Stream<Item = Result<(Vec<u8>, Vec<u8>)>> + Send + 'static

Required Methods§

source

fn get_raw(&self, key: &str) -> Self::GetRawFut

Gets a value from the verifiable key-value store as raw bytes.

Users should generally prefer to use get or get_proto from an extension trait.

source

fn nonverifiable_get_raw(&self, key: &[u8]) -> Self::GetRawFut

Gets a byte value from the non-verifiable key-value store.

This is intended for application-specific indexes of the verifiable consensus state, rather than for use as a primary data storage method.

source

fn object_get<T: Any + Send + Sync + Clone>( &self, key: &'static str ) -> Option<T>

Gets an object from the ephemeral key-object store.

This is intended to allow application components to build up batched data transactionally, ensuring that a transaction’s contributions to some batched data are only included if the entire transaction executed successfully. This data is not persisted to the Storage during commit.

§Returns
  • Some(&T) if a value of type T was present at key.
  • None if key was not present, or if key was present but the value was not of type T.
§Panics

If there is a value at key but it is not of the type requested.

source

fn object_type(&self, key: &'static str) -> Option<TypeId>

Gets the [TypeId] of the object stored at key in the ephemeral key-object store, if any is present.

source

fn prefix_raw(&self, prefix: &str) -> Self::PrefixRawStream

Retrieve all values for keys matching a prefix from the verifiable key-value store, as raw bytes.

Users should generally prefer to use prefix or prefix_proto from an extension trait.

source

fn prefix_keys(&self, prefix: &str) -> Self::PrefixKeysStream

Retrieve all keys (but not values) matching a prefix from the verifiable key-value store.

source

fn nonverifiable_prefix_raw( &self, prefix: &[u8] ) -> Self::NonconsensusPrefixRawStream

Retrieve all values for keys matching a prefix from the non-verifiable key-value store, as raw bytes.

Users should generally prefer to use wrapper methods in an extension trait.

source

fn nonverifiable_range_raw( &self, prefix: Option<&[u8]>, range: impl RangeBounds<Vec<u8>> ) -> Result<Self::NonconsensusRangeRawStream>

Retrieve all values for keys in a range from the non-verifiable key-value store, as raw bytes. This method does not support inclusive ranges, and will return an error if passed one.

Users should generally prefer to use wrapper methods in an extension trait.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl StateRead for ()

§

type GetRawFut = Ready<Result<Option<Vec<u8>>, Error>>

§

type PrefixRawStream = Iter<Empty<Result<(String, Vec<u8>), Error>>>

§

type PrefixKeysStream = Iter<Empty<Result<String, Error>>>

§

type NonconsensusPrefixRawStream = Iter<Empty<Result<(Vec<u8>, Vec<u8>), Error>>>

§

type NonconsensusRangeRawStream = Iter<Empty<Result<(Vec<u8>, Vec<u8>), Error>>>

source§

fn get_raw(&self, _key: &str) -> Self::GetRawFut

source§

fn nonverifiable_get_raw(&self, _key: &[u8]) -> Self::GetRawFut

source§

fn object_get<T: Any + Send + Sync + Clone>( &self, _key: &'static str ) -> Option<T>

source§

fn object_type(&self, _key: &'static str) -> Option<TypeId>

source§

fn prefix_raw(&self, _prefix: &str) -> Self::PrefixRawStream

source§

fn prefix_keys(&self, _prefix: &str) -> Self::PrefixKeysStream

source§

fn nonverifiable_prefix_raw( &self, _prefix: &[u8] ) -> Self::NonconsensusPrefixRawStream

source§

fn nonverifiable_range_raw( &self, _prefix: Option<&[u8]>, _range: impl RangeBounds<Vec<u8>> ) -> Result<Self::NonconsensusRangeRawStream>

source§

impl<'a, S: StateRead + Send + Sync> StateRead for &'a S

source§

impl<'a, S: StateRead + Send + Sync> StateRead for &'a mut S

source§

impl<S: StateRead + Send + Sync> StateRead for Arc<S>

Implementors§