From e23868d8359a0748f2f2f64d664bfe076b649dc4 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Wed, 17 Jan 2024 11:24:29 +0100 Subject: [PATCH] add new smith commands --- src/commands/smith.rs | 45 +++++++++++++++++++++++++++++++++++++++++-- src/display.rs | 15 +++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/commands/smith.rs b/src/commands/smith.rs index 2009d3c..6077cbd 100644 --- a/src/commands/smith.rs +++ b/src/commands/smith.rs @@ -56,6 +56,12 @@ pub enum Subcommand { }, /// List online authorities ShowOnline, + /// Invite identity to become smith + Invite{target: IdtyId}, + /// Accept invitation + Accept, + /// Certify smith + Certify{target: IdtyId}, } /// handle smith commands @@ -81,13 +87,21 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE set_session_keys(&data, session_keys).await?; } Subcommand::ShowExpire { blocks, sessions } => { - data = data.build_client().await?.build_indexer().await?; + data = data.build_indexer().await?; commands::expire::monitor_expirations(&data, blocks, sessions).await? } Subcommand::ShowOnline => { - data = data.build_client().await?; online(&data).await? } + Subcommand::Invite { target } => { + invite_smith(&data, target).await? + } + Subcommand::Accept => { + accept_invitation(&data).await? + } + Subcommand::Certify { target } => { + certify_smith(&data, target).await? + } }; Ok(()) @@ -254,3 +268,30 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> { Ok(()) } + +/// invite identity to join smith +pub async fn invite_smith(data: &Data, target: IdtyId) -> Result<(), subxt::Error> { + submit_call_and_look_event::< + runtime::smith_members::events::InvitationSent, + Payload<runtime::smith_members::calls::types::InviteSmith>, + >(data, &runtime::tx().smith_members().invite_smith(target)) + .await +} + +/// accept invitation +pub async fn accept_invitation(data: &Data) -> Result<(), subxt::Error> { + submit_call_and_look_event::< + runtime::smith_members::events::InvitationAccepted, + Payload<runtime::smith_members::calls::types::AcceptInvitation>, + >(data, &runtime::tx().smith_members().accept_invitation()) + .await +} + +/// invite identity to join smith +pub async fn certify_smith(data: &Data, target: IdtyId) -> Result<(), subxt::Error> { + submit_call_and_look_event::< + runtime::smith_members::events::CertificationReceived, + Payload<runtime::smith_members::calls::types::CertifySmith>, + >(data, &runtime::tx().smith_members().certify_smith(target)) + .await +} diff --git a/src/display.rs b/src/display.rs index dfffcc0..d00036a 100644 --- a/src/display.rs +++ b/src/display.rs @@ -60,6 +60,21 @@ impl DisplayEvent for runtime::distance::events::EvaluationRequested { format!("evaluation requested {:?}", self) } } +impl DisplayEvent for runtime::smith_members::events::InvitationSent { + fn display(&self, _data: &Data) -> String { + format!("sent smith invitation {:?}", self) + } +} +impl DisplayEvent for runtime::smith_members::events::InvitationAccepted { + fn display(&self, _data: &Data) -> String { + format!("accepted smith invitation {:?}", self) + } +} +impl DisplayEvent for runtime::smith_members::events::CertificationReceived { + fn display(&self, _data: &Data) -> String { + format!("new smith certification {:?}", self) + } +} impl DisplayEvent for runtime::identity::events::IdtyRemoved { fn display(&self, _data: &Data) -> String { format!("identity removed {:?}", self) -- GitLab