mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
examples: Fetch chianHead body
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -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?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user