Add methods to get header and storage change set (#65)

This commit is contained in:
Yuanchao Sun
2020-01-21 17:43:10 +08:00
committed by Andrew Jones
parent 253a7d8b0b
commit 3618b03dee
2 changed files with 40 additions and 0 deletions
+21
View File
@@ -118,6 +118,17 @@ where
}
}
/// Query historical storage entries
pub async fn query_storage(
&self,
keys: Vec<StorageKey>,
from: T::Hash,
to: Option<T::Hash>,
) -> Result<Vec<StorageChangeSet<<T as System>::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<T::Hash, Error> {
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<T::Hash>,
) -> Result<Option<T::Header>, 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,