diff --git a/src/commands/collective.rs b/src/commands/collective.rs index d1e777f51fa4e474c1328198cbab670db0daaade..1481c797a8508f9f2be8b76e0ae31dd9ef558742 100644 --- a/src/commands/collective.rs +++ b/src/commands/collective.rs @@ -135,10 +135,7 @@ pub async fn technical_committee_vote( /// propose call given as hexadecimal /// can be generated with `subxt explore` for example -pub async fn technical_committee_propose( - data: &Data, - proposal: &str, -) -> Result<(), subxt::Error> { +pub async fn technical_committee_propose(data: &Data, proposal: &str) -> Result<(), subxt::Error> { let raw_call = hex::decode(proposal).expect("invalid hex"); let call = codec::decode_from_bytes(raw_call.into()).expect("invalid call"); let payload = runtime::tx().technical_committee().propose(5, call, 100); diff --git a/src/commands/expire.rs b/src/commands/expire.rs index 64aa7fc5cb4f2623bcda4f10da8122bdcd33d324..ccce31606be5d8a4b60a0de52f5fef41d519f83e 100644 --- a/src/commands/expire.rs +++ b/src/commands/expire.rs @@ -2,7 +2,11 @@ use crate::{indexer::*, *}; use futures::join; use std::collections::BTreeMap; -pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> Result<(), subxt::Error> { +pub async fn monitor_expirations( + data: &Data, + blocks: u32, + _sessions: u32, +) -> Result<(), subxt::Error> { let client = data.client(); let indexer = data.indexer.clone(); diff --git a/src/commands/identity.rs b/src/commands/identity.rs index f6aa480084d33015265ce26cd83b32e72ace32f8..e3463c751a6780d190ac16947b6125d8646596c7 100644 --- a/src/commands/identity.rs +++ b/src/commands/identity.rs @@ -250,24 +250,25 @@ pub async fn get_identity( let indexer = data.indexer.clone(); // get idty_id - let index = - match (identity_id, &account_id, &pseudo) { - // idty_id - (Some(index), None, None) => index, - // account_id → idty_id - (None, Some(account_id), None) => get_idty_index_by_account_id(client, account_id) - .await? - .ok_or_else(|| GcliError::Duniter(format!("no identity for account '{account_id}'")))?, - // pseudo → idty_id - (None, None, Some(pseudo)) => get_idty_index_by_name(client, pseudo) - .await? - .ok_or_else(|| GcliError::Indexer(format!("no identity for name '{pseudo}'")))?, - _ => { - return Err(GcliError::Logic( - "One and only one argument is needed to fetch the identity.".to_string(), - )); - } - }; + let index = match (identity_id, &account_id, &pseudo) { + // idty_id + (Some(index), None, None) => index, + // account_id → idty_id + (None, Some(account_id), None) => get_idty_index_by_account_id(client, account_id) + .await? + .ok_or_else(|| { + GcliError::Duniter(format!("no identity for account '{account_id}'")) + })?, + // pseudo → idty_id + (None, None, Some(pseudo)) => get_idty_index_by_name(client, pseudo) + .await? + .ok_or_else(|| GcliError::Indexer(format!("no identity for name '{pseudo}'")))?, + _ => { + return Err(GcliError::Logic( + "One and only one argument is needed to fetch the identity.".to_string(), + )); + } + }; // idty_id → value let value = get_identity_by_index(client, index) .await? @@ -275,10 +276,11 @@ pub async fn get_identity( // pseudo let pseudo = pseudo.unwrap_or(if let Some(indexer) = &indexer { - indexer - .username_by_index(index) - .await - .ok_or_else(|| GcliError::Indexer(format!("indexer does not have username for this index {index}")))? + indexer.username_by_index(index).await.ok_or_else(|| { + GcliError::Indexer(format!( + "indexer does not have username for this index {index}" + )) + })? } else { "<no indexer>".to_string() }); @@ -298,8 +300,19 @@ pub async fn get_identity( // get certs if possible let (cert_issued, cert_received, linked_account, smith_info) = if let Some(indexer) = &indexer { - let info = indexer.identity_info(index).await.expect("no info"); - ( + let info = indexer + .identity_info(index) + .await + .ok_or_else(|| GcliError::Indexer(format!("no info for identity {index}")))?; + Ok::< + ( + Vec<String>, + Vec<String>, + Vec<AccountId>, + Option<crate::indexer::queries::identity_info::IdentityInfoIdentitySmith>, + ), + GcliError, + >(( info.cert_issued .into_iter() .map(|i| i.receiver.unwrap().name.to_string()) @@ -313,10 +326,10 @@ pub async fn get_identity( .map(|i| AccountId::from_str(&i.id).unwrap()) .collect(), info.smith, - ) + )) } else { - (vec![], vec![], vec![], None) - }; + Ok((vec![], vec![], vec![], None)) + }?; // get smith info let smith_meta = get_smith(client, index).await?; diff --git a/src/commands/smith.rs b/src/commands/smith.rs index d1814345302917804d99a67f40f4a3680a56ab66..fd3196374f5b56d7caf51498a3a1fac6c07ebb25 100644 --- a/src/commands/smith.rs +++ b/src/commands/smith.rs @@ -237,10 +237,11 @@ pub async fn online(data: &Data) -> Result<(), subxt::Error> { "{}", online_authorities .iter() - .map(|i| &names + .map(|i| names .get(i) - .expect("panic! found authorities whith no name")[..]) - .collect::<Vec<&str>>() + .map(|n| n.to_string()) + .unwrap_or(format!("{} <no name found>", i))) + .collect::<Vec<String>>() .join(", ") ); @@ -249,10 +250,11 @@ pub async fn online(data: &Data) -> Result<(), subxt::Error> { "{}", incoming_authorities .iter() - .map(|i| &names + .map(|i| names .get(i) - .expect("panic! found authorities whith no name")[..]) - .collect::<Vec<&str>>() + .map(|n| n.to_string()) + .unwrap_or(format!("{} <no name found>", i))) + .collect::<Vec<String>>() .join(", ") ); @@ -261,10 +263,11 @@ pub async fn online(data: &Data) -> Result<(), subxt::Error> { "{}", outgoing_authorities .iter() - .map(|i| &names + .map(|i| names .get(i) - .expect("panic! found authorities whith no name")[..]) - .collect::<Vec<&str>>() + .map(|n| n.to_string()) + .unwrap_or(format!("{} <no name found>", i))) + .collect::<Vec<String>>() .join(", ") ); } else { diff --git a/src/indexer.rs b/src/indexer.rs index e1922e148ba4526f10468d64480d4a39aba664d7..aa76c1f418f5a95afa642ae9a7d309c2850dba18 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -1,4 +1,4 @@ -mod queries; +pub mod queries; use crate::*; use comfy_table::*;