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

manage error when no indexer

closes #35
parent 260a225a
No related branches found
No related tags found
No related merge requests found
Pipeline #38203 passed
......@@ -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);
......
......@@ -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();
......
......@@ -250,14 +250,15 @@ pub async fn get_identity(
let indexer = data.indexer.clone();
// get idty_id
let index =
match (identity_id, &account_id, &pseudo) {
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}'")))?,
.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?
......@@ -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?;
......
......@@ -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 {
......
mod queries;
pub mod queries;
use crate::*;
use comfy_table::*;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment