diff --git a/subxt/src/runtime_api/runtime_client.rs b/subxt/src/runtime_api/runtime_client.rs index c48737e648..a785a4259f 100644 --- a/subxt/src/runtime_api/runtime_client.rs +++ b/subxt/src/runtime_api/runtime_client.rs @@ -31,23 +31,25 @@ where T: Config, Client: OnlineClientT, { - /// Obtain a runtime API at some block hash. - pub fn at( + /// Obtain a runtime API interface at some block hash. + pub fn at(&self, block_hash: T::Hash) -> RuntimeApi { + RuntimeApi::new(self.client.clone(), block_hash) + } + + /// Obtain a runtime API interface at the latest block hash. + pub fn at_latest( &self, - block_hash: Option, ) -> impl Future, Error>> + Send + 'static { // Clone and pass the client in like this so that we can explicitly // return a Future that's Send + 'static, rather than tied to &self. let client = self.client.clone(); async move { - // If block hash is not provided, get the hash - // for the latest block and use that. - let block_hash = match block_hash { - Some(hash) => hash, - None => client.rpc().block_hash(None).await?.expect( - "substrate RPC returns the best block when no block number is provided; qed", - ), - }; + // get the hash for the latest block and use that. + let block_hash = client + .rpc() + .block_hash(None) + .await? + .expect("didn't pass a block number; qed"); Ok(RuntimeApi::new(client, block_hash)) }