use avail_rust_client::prelude::*;
use avail_rust_core::avail::data_availability::storage::AppKeys;
pub struct SetIdSession;
impl StorageMap for SetIdSession {
type KEY = u64;
type VALUE = u32;
const KEY_HASHER: StorageHasher = StorageHasher::Twox64Concat;
const PALLET_NAME: &str = "Grandpa";
const STORAGE_NAME: &str = "SetIdSession";
}
#[tokio::main]
pub async fn main() -> Result<(), Error> {
let client = Client::new(TURING_ENDPOINT).await?;
let rpc_client = &client.rpc_client;
let key = "Hello World".as_bytes().to_vec();
let app_key = AppKeys::fetch(rpc_client, &key, None).await?.expect("Should be there");
println!("AppKey Owner: {}, AppKey Id: {}", app_key.owner, app_key.id);
println!("");
let block_hash = client.finalized().block_hash().await?;
let mut iter = AppKeys::iter(rpc_client.clone(), block_hash);
for _ in 0..2 {
let app_key = iter.next().await?.expect("Should be there");
println!("AppKey Owner: {}, AppKey Id: {}", app_key.owner, app_key.id);
let (key, app_key) = iter.next_key_value().await?.expect("Should be there");
println!(
"AppKey Key: {}, AppKey Owner: {}, AppKey Id: {}",
String::from_utf8(key).expect("Should work"),
app_key.owner,
app_key.id
)
}
println!("");
let block_hash = client.chain().block_hash(Some(2504346)).await;
let block_hash = block_hash?.expect("Should be there");
let session_index = SetIdSession::fetch(rpc_client, &615, Some(block_hash))
.await?
.expect("Should be there");
println!("Session Index: {:?}", session_index);
println!("");
let mut iter = SetIdSession::iter(rpc_client.clone(), block_hash);
for _ in 0..2 {
let session_index = iter.next().await?.expect("Should be there");
println!("Session Index: {}", session_index);
let (set_id, session_index) = iter.next_key_value().await?.expect("Should be there");
println!("Set Id: {}, Session Index: {}", set_id, session_index)
}
Ok(())
}