Insipx/add block method (#18)

* Fix compile errors

* Fix tests, close #13 BTW

* add block method

* add block_hash method

* add tests for block and block_hash
This commit is contained in:
Andrew Plaza
2019-09-12 21:34:24 +02:00
committed by Andrew Jones
parent 650c6d3bb0
commit e9070e2786
2 changed files with 42 additions and 1 deletions
+12 -1
View File
@@ -51,7 +51,8 @@ use substrate_rpc_api::{
state::StateClient,
};
type ChainBlock<T> = SignedBlock<Block<<T as System>::Header, OpaqueExtrinsic>>;
pub type ChainBlock<T> = SignedBlock<Block<<T as System>::Header, OpaqueExtrinsic>>;
pub type BlockNumber<T> = NumberOrHex<<T as System>::BlockNumber>;
/// Client for substrate rpc interfaces
pub struct Rpc<T: System> {
@@ -107,6 +108,16 @@ impl<T: System> Rpc<T> {
})
}
/// Get a block hash, returns hash of latest block by default
pub fn block_hash(&self, hash: Option<BlockNumber<T>>) -> impl Future<Item = Option<T::Hash>, Error = Error> {
self.chain.block_hash(hash).map_err(Into::into)
}
/// Get a Block
pub fn block(&self, hash: Option<T::Hash>) -> impl Future<Item = Option<ChainBlock<T>>, Error = Error> {
self.chain.block(hash).map_err(Into::into)
}
/// Fetch the runtime version
pub fn runtime_version(&self, at: Option<T::Hash>) -> impl Future<Item = RuntimeVersion, Error = Error> {
self.state.runtime_version(at).map_err(Into::into)