Newer
Older
use crate::{gdev, indexer::*, Args, Client};
use anyhow::Result;
use sp_core::sr25519::Pair;
use sp_core::H256;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
pub async fn technical_committee_members(client: Client, args: &Args) -> Result<()> {
let parent_hash = client
.storage()
.fetch(&gdev::storage().system().parent_hash(), None)
.await?
.unwrap();
let gql_client = reqwest::Client::builder()
.user_agent("gcli/0.1.0")
.build()?;
let indexer = if args.no_indexer {
None
} else {
Some(Indexer {
gql_client,
gql_url: &args.indexer,
})
};
for account_id in client
.storage()
.fetch(
&gdev::storage().technical_committee().members(),
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(
&gdev::storage().identity().identity_index_of(&account_id),
Some(parent_hash),
)
.await
.ok()
.flatten()
.map(|identity_id| format!("{identity_id}"))
}
.unwrap_or_else(|| account_id.to_string(),)
);
}
Ok(())
}
// TODO:
// * better formatting (format pubkeys to SS58 and add usernames)
// * display proposals indices
pub async fn technical_committee_proposals(client: Client) -> Result<()> {
let parent_hash = client
.storage()
.fetch(&gdev::storage().system().parent_hash(), None)
.await?
.unwrap();
let mut proposals_iter = client
.storage()
.iter(
gdev::storage()
.technical_committee()
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!();
}
Ok(())
}
pub async fn technical_committee_vote(
pair: Pair,
client: Client,
proposal_hash: H256,
proposal_index: u32,
vote: bool,
) -> Result<()> {
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx()
.technical_committee()
.vote(proposal_hash, proposal_index, vote),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
.await?;
Ok(())
}