From a14024bbd39a9d72b2bf5f2282ca28217365ea95 Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Wed, 17 Jan 2024 11:16:11 +0100
Subject: [PATCH] add distance evaluation request

---
 src/commands/distance.rs | 24 +++++++++++++++++-------
 src/commands/identity.rs | 20 ++++----------------
 src/display.rs           |  4 ++--
 3 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/src/commands/distance.rs b/src/commands/distance.rs
index fb80955..ba13b09 100644
--- a/src/commands/distance.rs
+++ b/src/commands/distance.rs
@@ -2,14 +2,24 @@ use crate::*;
 
 /// request distance evaluation
 pub async fn request_distance_evaluation(data: &Data) -> Result<(), subxt::Error> {
-	let progress = submit_call(
+	submit_call_and_look_event::<
+		runtime::distance::events::EvaluationRequested,
+		Payload<runtime::distance::calls::types::RequestDistanceEvaluation>,
+	>(
 		data,
 		&runtime::tx().distance().request_distance_evaluation(),
 	)
-	.await?;
-	if data.args.no_wait {
-		return Ok(());
-	}
-	let _ = track_progress(progress).await?;
-	Ok(())
+	.await
+}
+
+/// request distance evaluation for someone else (must be unvalidated)
+pub async fn request_distance_evaluation_for(data: &Data, target: IdtyId) -> Result<(), subxt::Error> {
+	submit_call_and_look_event::<
+		runtime::distance::events::EvaluationRequested,
+		Payload<runtime::distance::calls::types::RequestDistanceEvaluationFor>,
+	>(
+		data,
+		&runtime::tx().distance().request_distance_evaluation_for(target),
+	)
+	.await
 }
diff --git a/src/commands/identity.rs b/src/commands/identity.rs
index 9543c57..ccf51a7 100644
--- a/src/commands/identity.rs
+++ b/src/commands/identity.rs
@@ -34,9 +34,8 @@ pub enum Subcommand {
 	/// Request distance evaluation
 	/// make sure that it's ok otherwise currency is slashed
 	RequestDistanceEvaluation,
-	/// Renew membership  
-	/// When membership comes to and end, it should be renewed for the identity to stay member
-	RenewMembership,
+	/// Request distance evaluation for unvalidated identity
+	RequestDistanceEvaluationFor { target: IdtyId },
 	/// Certify an identity
 	Certify { target: IdtyId },
 	/// Revoke an identity immediately
@@ -94,8 +93,8 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
 		Subcommand::RequestDistanceEvaluation => {
 			commands::distance::request_distance_evaluation(&data).await?;
 		}
-		Subcommand::RenewMembership => {
-			renew_membership(&data).await?;
+		Subcommand::RequestDistanceEvaluationFor {target} => {
+			commands::distance::request_distance_evaluation_for(&data, target).await?;
 		}
 		Subcommand::Certify { target } => {
 			data = data.fetch_idty_index().await?;
@@ -276,17 +275,6 @@ pub async fn confirm_identity(data: &Data, name: String) -> Result<(), subxt::Er
 	.await
 }
 
-/// renew membership
-pub async fn renew_membership(data: &Data) -> Result<(), subxt::Error> {
-	submit_call_and_look_event::<
-		runtime::membership::events::MembershipRenewed,
-		Payload<runtime::distance::calls::types::RequestDistanceEvaluation>,
-	>(
-		data,
-		&runtime::tx().distance().request_distance_evaluation(),
-	)
-	.await
-}
 
 /// generate revokation document and submit it immediately
 pub async fn revoke_identity(data: &Data) -> Result<(), subxt::Error> {
diff --git a/src/display.rs b/src/display.rs
index bcfb3e9..dfffcc0 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -55,9 +55,9 @@ impl DisplayEvent for runtime::identity::events::IdtyChangedOwnerKey {
 		format!("identity changed owner key {:?}", self)
 	}
 }
-impl DisplayEvent for runtime::membership::events::MembershipRenewed {
+impl DisplayEvent for runtime::distance::events::EvaluationRequested {
 	fn display(&self, _data: &Data) -> String {
-		format!("membership renewed {:?}", self)
+		format!("evaluation requested {:?}", self)
 	}
 }
 impl DisplayEvent for runtime::identity::events::IdtyRemoved {
-- 
GitLab