From 8a835b7a8e4cd569004e34df21b092f484176a85 Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Mon, 19 Jun 2023 16:34:15 +0200
Subject: [PATCH] add smith membership renewal

---
 src/commands/smith.rs | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/commands/smith.rs b/src/commands/smith.rs
index da1a75b..ab78151 100644
--- a/src/commands/smith.rs
+++ b/src/commands/smith.rs
@@ -16,6 +16,8 @@ pub enum Subcommand {
 	Cert { to: u32 },
 	/// Claim smith membership
 	Claim,
+	/// Renew smith membership
+	Renew,
 	/// go online
 	GoOnline,
 	/// go offline
@@ -48,6 +50,9 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
 		Subcommand::Claim => {
 			claim_smith_membership(&data).await?;
 		}
+		Subcommand::Renew => {
+			renew_smith_membership(&data).await?;
+		}
 		Subcommand::GoOnline => {
 			go_online(&data).await?;
 		}
@@ -187,7 +192,7 @@ pub async fn go_online(data: &Data) -> Result<(), GcliError> {
 	Ok(())
 }
 
-/// submit go_offline
+/// claim smith membership
 pub async fn claim_smith_membership(data: &Data) -> Result<(), subxt::Error> {
 	let progress = data
 		.client()
@@ -210,6 +215,29 @@ pub async fn claim_smith_membership(data: &Data) -> Result<(), subxt::Error> {
 	Ok(())
 }
 
+/// renew smith membership
+pub async fn renew_smith_membership(data: &Data) -> Result<(), subxt::Error> {
+	let progress = data
+		.client()
+		.tx()
+		.sign_and_submit_then_watch(
+			&runtime::tx().smith_membership().renew_membership(), 
+			&PairSigner::new(data.keypair()),
+			BaseExtrinsicParamsBuilder::new(),
+		)
+		.await?;
+
+	if data.args.no_wait {
+		return Ok(());
+	}
+	let events = track_progress(progress).await?;
+	if let Some(e) = events.find_first::<runtime::smith_membership::events::MembershipRenewed>()? {
+		println!("{e:?}");
+	}
+
+	Ok(())
+}
+
 /// submit go_offline
 pub async fn go_offline(data: &Data) -> Result<(), subxt::Error> {
 	let progress = data
-- 
GitLab