examples: Fetch chianHead body

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-11-25 19:13:17 +00:00
parent 76aa08b1dc
commit 6a5cb229af
@@ -15,6 +15,8 @@ use subxt::{
PolkadotConfig,
};
use futures::StreamExt;
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
pub mod polkadot {}
@@ -25,6 +27,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client to use:
let api = OnlineClient::<PolkadotConfig>::new().await?;
let mut follow_sub = api.blocks().subscribe_chainhead_finalized(false).await?;
// Handle all subscriptions from the `chainHead_follow`.
while let Some(event) = follow_sub.next().await {
let event = event?;
let body = event.body().await?;
println!("[hash={:?}] body={:?}", event.hash(), body);
}
// Subscribe to the `chainHead_follow` method.
let mut follow_sub = api.rpc().subscribe_chainhead_follow(false).await?;