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

add renew cert and change arg to name (clients/rust/gcli-v2s!21)

* revert use try_get_idty_index_by_name

review txels

* add renew cert and change arg to name
parent 685c1f7e
No related branches found
No related tags found
No related merge requests found
use crate::*; use crate::*;
/// submit a certification and track progress /// submit a certification and track progress
pub async fn certify(data: &Data, receiver: IdtyId) -> Result<(), anyhow::Error> { pub async fn certify(data: &Data, target: IdtyId) -> Result<(), subxt::Error> {
let progress = submit_call(data, &runtime::tx().certification().add_cert(receiver)).await?; submit_call_and_look_event::<
if data.args.no_wait { runtime::certification::events::CertAdded,
return Ok(()); Payload<runtime::certification::calls::types::AddCert>,
} >(data, &runtime::tx().certification().add_cert(target))
let events = track_progress(progress).await?; .await
// look for the expected event }
look_event::<runtime::certification::events::CertAdded>(data, &events)?;
look_event::<runtime::certification::events::CertRenewed>(data, &events)?; /// renew certification
Ok(()) pub async fn renew(data: &Data, target: IdtyId) -> Result<(), subxt::Error> {
submit_call_and_look_event::<
runtime::certification::events::CertRenewed,
Payload<runtime::certification::calls::types::RenewCert>,
>(data, &runtime::tx().certification().renew_cert(target))
.await
} }
...@@ -37,9 +37,13 @@ pub enum Subcommand { ...@@ -37,9 +37,13 @@ pub enum Subcommand {
/// make sure that it's ok otherwise currency is slashed /// make sure that it's ok otherwise currency is slashed
RequestDistanceEvaluation, RequestDistanceEvaluation,
/// Request distance evaluation for unvalidated identity /// Request distance evaluation for unvalidated identity
RequestDistanceEvaluationFor { target: IdtyId }, RequestDistanceEvaluationFor { target: String },
/// Certify an identity /// Certify an identity
Certify { target: IdtyId }, #[clap(alias = "cert")]
Certify { target: String },
/// Renew a certification
#[clap(alias = "renew")]
RenewCert { target: String },
/// Revoke an identity immediately /// Revoke an identity immediately
Revoke, Revoke,
/// Generate a revocation document for the provided account /// Generate a revocation document for the provided account
...@@ -95,13 +99,24 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -95,13 +99,24 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
commands::distance::request_distance_evaluation(&data).await?; commands::distance::request_distance_evaluation(&data).await?;
} }
Subcommand::RequestDistanceEvaluationFor { target } => { Subcommand::RequestDistanceEvaluationFor { target } => {
let target = try_get_idty_index_by_name(&data, &target).await?;
commands::distance::request_distance_evaluation_for(&data, target).await?; commands::distance::request_distance_evaluation_for(&data, target).await?;
} }
Subcommand::Certify { target } => { Subcommand::Certify { target } => {
data = data.fetch_idty_index().await?; let targetid = try_get_idty_index_by_name(&data, &target).await?;
// TODO fetch target username / key / index // ask user to confirm certification
// and ask user to confirm certification if let Ok(true) = inquire::Confirm::new(&format!(
commands::certification::certify(&data, target).await?; "Are you sure you want to certify {target} ({targetid})?"
))
.with_default(false)
.prompt()
{
commands::certification::certify(&data, targetid).await?;
};
}
Subcommand::RenewCert { target } => {
let target = try_get_idty_index_by_name(&data, &target).await?;
commands::certification::renew(&data, target).await?;
} }
Subcommand::Revoke => { Subcommand::Revoke => {
data = data.fetch_idty_index().await?; data = data.fetch_idty_index().await?;
...@@ -374,6 +389,12 @@ pub async fn get_idty_index_by_name( ...@@ -374,6 +389,12 @@ pub async fn get_idty_index_by_name(
.await .await
} }
pub async fn try_get_idty_index_by_name(data: &Data, name: &str) -> Result<IdtyId, GcliError> {
get_idty_index_by_name(data.client(), name)
.await?
.ok_or_else(|| GcliError::Input(format!("no identity with name {name}")))
}
/// get identityt value by index /// get identityt value by index
pub async fn get_identity_by_index( pub async fn get_identity_by_index(
client: &Client, client: &Client,
......
use crate::*; use crate::*;
use commands::identity::try_get_idty_index_by_name;
#[cfg(feature = "gdev")] #[cfg(feature = "gdev")]
use runtime::runtime_types::gdev_runtime::opaque::SessionKeys as RuntimeSessionKeys; use runtime::runtime_types::gdev_runtime::opaque::SessionKeys as RuntimeSessionKeys;
use std::ops::Deref; use std::ops::Deref;
...@@ -57,11 +58,12 @@ pub enum Subcommand { ...@@ -57,11 +58,12 @@ pub enum Subcommand {
/// List online authorities /// List online authorities
ShowOnline, ShowOnline,
/// Invite identity to become smith /// Invite identity to become smith
Invite { target: IdtyId }, Invite { target: String },
/// Accept invitation /// Accept invitation
Accept, Accept,
/// Certify smith /// Certify smith
Certify { target: IdtyId }, #[clap(alias = "cert")]
Certify { target: String },
} }
/// handle smith commands /// handle smith commands
...@@ -91,9 +93,15 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -91,9 +93,15 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
commands::expire::monitor_expirations(&data, blocks, sessions).await? commands::expire::monitor_expirations(&data, blocks, sessions).await?
} }
Subcommand::ShowOnline => online(&data).await?, Subcommand::ShowOnline => online(&data).await?,
Subcommand::Invite { target } => invite_smith(&data, target).await?, Subcommand::Invite { target } => {
let target = try_get_idty_index_by_name(&data, &target).await?;
invite_smith(&data, target).await?
}
Subcommand::Accept => accept_invitation(&data).await?, Subcommand::Accept => accept_invitation(&data).await?,
Subcommand::Certify { target } => certify_smith(&data, target).await?, Subcommand::Certify { target } => {
let target = try_get_idty_index_by_name(&data, &target).await?;
certify_smith(&data, target).await?
}
}; };
Ok(()) Ok(())
......
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