Newer
Older
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
pub async fn technical_committee_members(data: &Data) -> Result<()> {
let client = data.client();
let indexer = data.indexer.clone();
for account_id in client
.storage()
.fetch(
Some(parent_hash),
)
.await?
.unwrap_or_default()
{
println!(
"{}",
if let Some(indexer) = &indexer {
indexer
.username_by_pubkey(&account_id.to_string())
.await
.ok()
.flatten()
} else {
client
.storage()
.fetch(
Some(parent_hash),
)
.await
.ok()
.flatten()
.map(|identity_id| format!("{identity_id}"))
}
.unwrap_or_else(|| account_id.to_string(),)
);
}
// TODO:
// * better formatting (format pubkeys to SS58 and add usernames)
// * display proposals indices
pub async fn technical_committee_proposals(client: &Client) -> Result<()> {
let mut proposals_iter = client
.storage()
.iter(
.technical_committee()
.proposal_of(H256::default()),
10,
Some(parent_hash),
)
.await?;
while let Some((proposal_hash, proposal)) = proposals_iter.next().await? {
println!("{}", hex::encode(&proposal_hash.0[32..64]));
println!("{proposal:#?}");
println!();
}
pub async fn technical_committee_vote(
proposal_hash: H256,
proposal_index: u32,
vote: bool,
) -> Result<(), subxt::Error> {
let progress = client
.technical_committee()
.vote(proposal_hash, proposal_index, vote),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
.await?;
let events = track_progress(progress).await?;
if let Some(e) = events.find_first::<runtime::technical_committee::events::Voted>()? {
println!("{e:?}");
}
Ok(())