From 6a5cb229af71510e3dc055da3ae1d77fdde2aab2 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 25 Nov 2022 19:13:17 +0000 Subject: [PATCH] examples: Fetch chianHead body Signed-off-by: Alexandru Vasile --- examples/examples/chainhead_subscription.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/examples/chainhead_subscription.rs b/examples/examples/chainhead_subscription.rs index d7cf02d9dd..37a0bc458d 100644 --- a/examples/examples/chainhead_subscription.rs +++ b/examples/examples/chainhead_subscription.rs @@ -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> { // Create a client to use: let api = OnlineClient::::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?;