use avail_rust_client::{prelude::*, subscription::BlockHeaderSub};
#[tokio::main]
pub async fn main() -> Result<(), Error> {
let client = Client::new(TURING_ENDPOINT).await?;
let mut sub = BlockHeaderSub::new(client.clone());
let next_header = sub.next().await?.expect("Should be there");
let prev_header = sub.prev().await?.expect("Should be there");
println!("Finalized Next: Block Height: {}, Block Hash: {:?}", next_header.number, next_header.hash());
println!("Finalized Previous: Block Height: {}, Block Hash: {:?}", prev_header.number, prev_header.hash());
let mut sub = BlockHeaderSub::new(client.clone());
sub.use_best_block(true);
let next_header = sub.next().await?.expect("Should be there");
let prev_header = sub.prev().await?.expect("Should be there");
println!("Best Next: Block Height: {}, Block Hash: {:?}", next_header.number, next_header.hash());
println!("Best Previous: Block Height: {}, Block Hash: {:?}", prev_header.number, prev_header.hash());
let mut sub = BlockHeaderSub::new(client.clone());
sub.set_block_height(2000000);
let next_header = sub.next().await?.expect("Should be there");
let prev_header = sub.prev().await?.expect("Should be there");
println!("Historical Next: Block Height: {}, Block Hash: {:?}", next_header.number, next_header.hash());
println!("Historical Previous: Block Height: {}, Block Hash: {:?}", prev_header.number, prev_header.hash());
Ok(())
}