mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-22 18:28:01 +00:00
at_latest for runtime API too (#904)
This commit is contained in:
@@ -31,23 +31,25 @@ where
|
||||
T: Config,
|
||||
Client: OnlineClientT<T>,
|
||||
{
|
||||
/// 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<T, Client> {
|
||||
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<T::Hash>,
|
||||
) -> impl Future<Output = Result<RuntimeApi<T, Client>, 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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user