use crate::*; use anyhow::Result; use futures::join; use sp_core::sr25519::Signature; use sp_core::{sr25519::Pair, Encode, Pair as _}; pub async fn generate_revoc_doc(api: &Client, pair: &Pair) -> Result<()> { let signature = get_revoc_doc(api, pair).await?.1; println!("0x{}", hex::encode(signature)); Ok(()) } pub async fn get_revoc_doc(api: &Client, pair: &Pair) -> Result<(u32, Signature)> { let account_id: sp_core::crypto::AccountId32 = pair.public().into(); let addr_idty_index = runtime::storage().identity().identity_index_of(&account_id); let addr_block_hash = runtime::storage().system().block_hash(0); // Multiple fetches can be done in a single request. let (idty_index, genesis_hash) = join!( api.storage().fetch(&addr_idty_index, None,), api.storage().fetch(&addr_block_hash, None) ); let idty_index = idty_index?.unwrap(); let genesis_hash = genesis_hash?.unwrap(); let payload = (b"revo", genesis_hash, idty_index).encode(); let signature = pair.sign(&payload); Ok((idty_index, signature)) }