diff --git a/src/lib.rs b/src/lib.rs index 39582d4c61..26ec6988b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -210,6 +210,25 @@ impl Client { Ok(result.unwrap_or_default()) } + /// Query historical storage entries + pub async fn query_storage( + &self, + keys: Vec, + from: T::Hash, + to: Option, + ) -> Result::Hash>>, Error> { + self.rpc.query_storage(keys, from, to).await + } + + /// Get a header + pub async fn header(&self, hash: Option) -> Result, Error> + where + H: Into + 'static, + { + let header = self.rpc.header(hash.map(|h| h.into())).await?; + Ok(header) + } + /// Get a block hash. By default returns the latest block hash pub async fn block_hash( &self, diff --git a/src/rpc.rs b/src/rpc.rs index 35cf258ad3..78d7b3721a 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -118,6 +118,17 @@ where } } + /// Query historical storage entries + pub async fn query_storage( + &self, + keys: Vec, + from: T::Hash, + to: Option, + ) -> Result::Hash>>, Error> { + let params = Params::Array(vec![to_json_value(keys)?, to_json_value(from)?, to_json_value(to)?]); + self.client.request("state_queryStorage", params).await.map_err(Into::into) + } + /// Fetch the genesis hash pub async fn genesis_hash(&self) -> Result { let block_zero = Some(ListOrValue::Value(NumberOrHex::Number( @@ -145,6 +156,16 @@ where Ok(metadata) } + /// Get a header + pub async fn header( + &self, + hash: Option, + ) -> Result, Error> { + let params = Params::Array(vec![to_json_value(hash)?]); + let header = self.client.request("chain_getHeader", params).await?; + Ok(header) + } + /// Get a block hash, returns hash of latest block by default pub async fn block_hash( &self,