diff --git a/subxt/src/blocks/block_types.rs b/subxt/src/blocks/block_types.rs index 14087c217f..ecd9e8d085 100644 --- a/subxt/src/blocks/block_types.rs +++ b/subxt/src/blocks/block_types.rs @@ -184,6 +184,15 @@ where Ok(Some(storage)) } + /// Execute a runtime API call at this block. + pub async fn call( + &self, + function: String, + call_parameters: Option<&[u8]>, + ) -> Result, ChainHeadError> { + self.fetch_call(function, call_parameters).await + } + /// Wrapper to fetch the block's body from the `chainHead_body` subscription. async fn fetch_body( &self, @@ -261,6 +270,36 @@ where "Failed to fetch the block storage".into(), )) } + + /// Execute a runtime API call at this block. + async fn fetch_call( + &self, + function: String, + call_parameters: Option<&[u8]>, + ) -> Result, ChainHeadError> { + let call_parameters = call_parameters.unwrap_or(Default::default()); + + let mut sub = self + .client + .rpc() + .subscribe_chainhead_call( + self.subscription_id.clone(), + self.hash, + function, + call_parameters, + ) + .await?; + + if let Some(event) = sub.next().await { + let event = event?; + + let bytes = Vec::::try_from(event)?; + } + + Err(ChainHeadError::Other( + "Failed to execute the runtime API call".into(), + )) + } } /// A representation of a block.