Skip to content
Snippets Groups Projects
Commit 43af6d37 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

refac identity to display status

parent 04869cd2
No related branches found
No related tags found
1 merge request!15update to runtime 800
This commit is part of merge request !15. Comments created here will be created in the context of that merge request.
......@@ -71,7 +71,6 @@ pub enum Subcommand {
pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> {
let mut data = data.build_client().await?;
match command {
// TODO remove indexer where not necessary when BlakeConcat will be there
Subcommand::Show => {
data = data.build_indexer().await?;
get_identity(&data, Some(data.address()), None, None).await?
......@@ -150,41 +149,30 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
/// get identity
pub async fn get_identity(
data: &Data,
mut account_id: Option<AccountId>,
mut identity_id: Option<IdtyId>,
mut username: Option<String>,
account_id: Option<AccountId>,
identity_id: Option<IdtyId>,
username: Option<String>,
) -> Result<(), anyhow::Error> {
let client = data.client();
let indexer = data.indexer.clone();
// fetch reachable information using Duniter only (no indexer)
match (&account_id, identity_id, &username) {
let (idty, value) = match (&account_id, identity_id, &username) {
// idty_id → account_id
(None, Some(identity_id), None) => {
account_id = get_identity_by_index(client, identity_id)
.await?
.map(|idty| idty.owner_key);
if account_id.is_none() {
return Err(anyhow!("no identity for this account id"));
}
}
(None, Some(idty), None) => (idty, get_identity_by_index(client, idty).await?),
// account_id → idty_id
(Some(account_id), None, None) => {
identity_id = get_idty_index_by_account_id(client, account_id).await?;
if identity_id.is_none() {
return Err(anyhow!("no identity for this identity index"));
}
let idty = get_idty_index_by_account_id(client, account_id)
.await?
.ok_or_else(|| anyhow!("no identity for this account id"))?;
(idty, get_identity_by_index(client, idty).await?)
}
// username → idty_id and account_id
(None, None, Some(username)) => {
identity_id = get_idty_index_by_name(client, username).await?;
if let Some(identity_id) = identity_id {
account_id = get_identity_by_index(client, identity_id)
.await?
.map(|idty| idty.owner_key);
} else {
return Err(anyhow!("no identity found for this username"));
}
let idty = get_idty_index_by_name(client, username)
.await?
.ok_or_else(|| anyhow!("no identity found for this username"))?;
(idty, get_identity_by_index(client, idty).await?)
}
_ => {
return Err(anyhow!(
......@@ -192,28 +180,25 @@ pub async fn get_identity(
));
}
};
let value = value.ok_or_else(|| anyhow!("no identity value"))?;
// print result
// 1. identity index
println!(
"Identity index: {}",
identity_id.map_or(String::new(), |identity_id| format!("{identity_id}"))
);
println!("Identity index: {idty}",);
// 2. username (indexer needed if not provided)
if let (Some(indexer), Some(identity_id), None) = (&indexer, identity_id, &username) {
username = indexer.username_by_index(identity_id).await?;
}
println!(
"Username: {}",
username.unwrap_or("<no indexer>".to_string())
);
let username = username.unwrap_or(if let Some(indexer) = &indexer {
indexer
.username_by_index(idty)
.await?
.ok_or_else(|| anyhow!("indexer does not have username for this index"))?
} else {
"<no indexer>".to_string()
});
println!("Username: {username}",);
// 3. address
println!(
"Address: {}",
account_id
.as_ref()
.map_or(String::new(), AccountId::to_string)
);
println!("Address: {}", AccountId::to_string(&value.owner_key));
// 4. status
println!("Status: {:?}", value.status);
Ok(())
}
......
......@@ -50,7 +50,11 @@ pub async fn runtime_info(data: Data) {
);
println!(
"min received cert to issue cert: {}",
getu32(consts.certification().min_received_cert_to_be_able_to_issue_cert())
getu32(
consts
.certification()
.min_received_cert_to_be_able_to_issue_cert()
)
);
println!(
"certification validity: {} blocks",
......@@ -153,4 +157,4 @@ pub async fn runtime_info(data: Data) {
);
// todo treasury, technical committee, transaction payment, authority members
// consts.system().ss58_prefix()
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment