From c397f84b7d50796634ba6de0136296c9adbca67a Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Sun, 18 Jun 2023 12:34:59 +0200
Subject: [PATCH] add certify command

---
 src/commands.rs               |  1 +
 src/commands/account.rs       |  2 +-
 src/commands/certification.rs | 31 +++++++++++++++++++++++++++++++
 src/commands/identity.rs      |  8 ++++++++
 4 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 src/commands/certification.rs

diff --git a/src/commands.rs b/src/commands.rs
index 1384ca8..b69cbaf 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -1,5 +1,6 @@
 pub mod account;
 pub mod blockchain;
+pub mod certification;
 pub mod collective;
 pub mod expire;
 pub mod identity;
diff --git a/src/commands/account.rs b/src/commands/account.rs
index 15650a8..e1f6d8d 100644
--- a/src/commands/account.rs
+++ b/src/commands/account.rs
@@ -32,7 +32,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
 	match command {
 		Subcommand::Balance => {
 			data = data.fetch_system_properties().await?;
-			commands::account::get_balance(data).await?
+			get_balance(data).await?
 		}
 		Subcommand::Transfer {
 			amount,
diff --git a/src/commands/certification.rs b/src/commands/certification.rs
new file mode 100644
index 0000000..0651cc6
--- /dev/null
+++ b/src/commands/certification.rs
@@ -0,0 +1,31 @@
+use crate::*;
+
+/// submit a certification and track progress
+pub async fn certify(data: &Data, receiver: u32) -> Result<(), anyhow::Error> {
+	let progress = data
+		.client()
+		.tx()
+		.sign_and_submit_then_watch(
+			&runtime::tx()
+				.cert()
+				.add_cert(data.idty_index(), receiver),
+			&PairSigner::new(data.keypair()),
+			BaseExtrinsicParamsBuilder::new(),
+		)
+		.await?;
+
+	let events = track_progress(progress).await?;
+
+	// look for the expected event
+	let new_cert_event = events.find_first::<runtime::cert::events::NewCert>()?;
+	let renew_cert_event = events.find_first::<runtime::cert::events::RenewedCert>()?;
+
+	if let Some(event) = new_cert_event {
+		println!("{event:?}");
+	}
+	if let Some(event) = renew_cert_event {
+		println!("{event:?}");
+	}
+
+	Ok(())
+}
diff --git a/src/commands/identity.rs b/src/commands/identity.rs
index 098d3d1..9c7c1fb 100644
--- a/src/commands/identity.rs
+++ b/src/commands/identity.rs
@@ -30,6 +30,8 @@ pub enum Subcommand {
 	///
 	/// To be called by the certified not-yet-member account, to become member.
 	Confirm { name: String },
+	/// Certify an identity
+	Certify { target: u32 },
 	/// Revoke an identity immediately
 	Revoke,
 	/// Generate a revocation document for the provided account
@@ -61,6 +63,12 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
 		Subcommand::Confirm { name } => {
 			commands::identity::confirm_identity(data.keypair(), data.client(), name).await?;
 		}
+		Subcommand::Certify { target } => {
+			data = data.fetch_idty_index().await?;
+			// TODO fetch target username / key / index
+			// and ask user to confirm certification
+			commands::certification::certify(&data, target).await?;
+		}
 		Subcommand::Revoke => {
 			data = data.fetch_idty_index().await?;
 			commands::identity::revoke_identity(data).await?;
-- 
GitLab