blocks: Fetch chainHead storage

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-11-30 12:44:47 +00:00
parent 9ef0a70742
commit a635f3bebf
3 changed files with 93 additions and 6 deletions
+15 -6
View File
@@ -29,14 +29,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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?;
while let Some(block) = follow_sub.next().await {
let block = block?;
let body = event.body().await?;
println!("[hash={:?}] body={:?}", event.hash(), body);
let body = block.body().await?;
println!("[hash={:?}] body={:?}", block.hash(), body);
let header = event.header().await?;
println!("[hash={:?}] header={:?}", event.hash(), header);
let header = block.header().await?;
println!("[hash={:?}] header={:?}", block.hash(), header);
let active_era_addr = polkadot::storage().staking().active_era();
let era = block.storage(&active_era_addr).await?.unwrap();
println!(
"[hash={:?}] storage index: {:?}, start: {:?}",
block.hash(),
era.index,
era.start
);
}
// Subscribe to the `chainHead_follow` method.