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 { ...@@ -71,7 +71,6 @@ pub enum Subcommand {
pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> { pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> {
let mut data = data.build_client().await?; let mut data = data.build_client().await?;
match command { match command {
// TODO remove indexer where not necessary when BlakeConcat will be there
Subcommand::Show => { Subcommand::Show => {
data = data.build_indexer().await?; data = data.build_indexer().await?;
get_identity(&data, Some(data.address()), None, None).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 ...@@ -150,41 +149,30 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
/// get identity /// get identity
pub async fn get_identity( pub async fn get_identity(
data: &Data, data: &Data,
mut account_id: Option<AccountId>, account_id: Option<AccountId>,
mut identity_id: Option<IdtyId>, identity_id: Option<IdtyId>,
mut username: Option<String>, username: Option<String>,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
let client = data.client(); let client = data.client();
let indexer = data.indexer.clone(); let indexer = data.indexer.clone();
// fetch reachable information using Duniter only (no indexer) // 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 // idty_id → account_id
(None, Some(identity_id), None) => { (None, Some(idty), None) => (idty, get_identity_by_index(client, idty).await?),
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"));
}
}
// account_id → idty_id // account_id → idty_id
(Some(account_id), None, None) => { (Some(account_id), None, None) => {
identity_id = get_idty_index_by_account_id(client, account_id).await?; let idty = get_idty_index_by_account_id(client, account_id)
if identity_id.is_none() { .await?
return Err(anyhow!("no identity for this identity index")); .ok_or_else(|| anyhow!("no identity for this account id"))?;
} (idty, get_identity_by_index(client, idty).await?)
} }
// username → idty_id and account_id // username → idty_id and account_id
(None, None, Some(username)) => { (None, None, Some(username)) => {
identity_id = get_idty_index_by_name(client, username).await?; let idty = get_idty_index_by_name(client, username)
if let Some(identity_id) = identity_id {
account_id = get_identity_by_index(client, identity_id)
.await? .await?
.map(|idty| idty.owner_key); .ok_or_else(|| anyhow!("no identity found for this username"))?;
} else { (idty, get_identity_by_index(client, idty).await?)
return Err(anyhow!("no identity found for this username"));
}
} }
_ => { _ => {
return Err(anyhow!( return Err(anyhow!(
...@@ -192,28 +180,25 @@ pub async fn get_identity( ...@@ -192,28 +180,25 @@ pub async fn get_identity(
)); ));
} }
}; };
let value = value.ok_or_else(|| anyhow!("no identity value"))?;
// print result // print result
// 1. identity index // 1. identity index
println!( println!("Identity index: {idty}",);
"Identity index: {}",
identity_id.map_or(String::new(), |identity_id| format!("{identity_id}"))
);
// 2. username (indexer needed if not provided) // 2. username (indexer needed if not provided)
if let (Some(indexer), Some(identity_id), None) = (&indexer, identity_id, &username) { let username = username.unwrap_or(if let Some(indexer) = &indexer {
username = indexer.username_by_index(identity_id).await?; indexer
} .username_by_index(idty)
println!( .await?
"Username: {}", .ok_or_else(|| anyhow!("indexer does not have username for this index"))?
username.unwrap_or("<no indexer>".to_string()) } else {
); "<no indexer>".to_string()
});
println!("Username: {username}",);
// 3. address // 3. address
println!( println!("Address: {}", AccountId::to_string(&value.owner_key));
"Address: {}", // 4. status
account_id println!("Status: {:?}", value.status);
.as_ref()
.map_or(String::new(), AccountId::to_string)
);
Ok(()) Ok(())
} }
......
...@@ -50,7 +50,11 @@ pub async fn runtime_info(data: Data) { ...@@ -50,7 +50,11 @@ pub async fn runtime_info(data: Data) {
); );
println!( println!(
"min received cert to issue cert: {}", "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!( println!(
"certification validity: {} blocks", "certification validity: {} blocks",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment