Skip to content
Snippets Groups Projects

update to runtime 800

Merged Hugo Trentesaux requested to merge hugo-dev into master
2 unresolved threads
2 files
+ 33
44
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 27
42
@@ -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(())
}
Loading