From 03def0546ae20fe9781224035f5c8984caab11fb Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Wed, 29 Nov 2023 20:22:36 +0100 Subject: [PATCH] add tech propose --- src/commands/collective.rs | 32 +++++++++++++++++++++----------- src/display.rs | 5 +++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/commands/collective.rs b/src/commands/collective.rs index 80da16a..9717d66 100644 --- a/src/commands/collective.rs +++ b/src/commands/collective.rs @@ -8,6 +8,8 @@ pub enum Subcommand { #[default] /// List members of the technical committee Members, + /// Propose a hex encoded call + Propose { hex: String }, /// List proposals to the technical committee Proposals, /// Vote a proposal to the technical committee @@ -23,24 +25,18 @@ pub enum Subcommand { /// handle technical committee commands pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliError> { - let mut data = data.build_client().await?.build_indexer().await?; + let data = data.build_client().await?; match command { - Subcommand::Members => { - data = data.build_client().await?; - commands::collective::technical_committee_members(&data).await? - } - Subcommand::Proposals => { - data = data.build_client().await?; - commands::collective::technical_committee_proposals(data.client()).await? - } + Subcommand::Members => technical_committee_members(&data).await?, + Subcommand::Propose { hex } => technical_committee_propose(&data, &hex).await?, + Subcommand::Proposals => technical_committee_proposals(data.client()).await?, Subcommand::Vote { hash, index, vote } => { - data = data.build_client().await?; let vote = match vote { 0 => false, 1 => true, _ => panic!("Vote must be written 0 if you disagree, or 1 if you agree."), }; - commands::collective::technical_committee_vote( + technical_committee_vote( &data, hash, //Hash::from_str(&hash).expect("Invalid hash formatting"), index, vote, ) @@ -141,3 +137,17 @@ pub async fn technical_committee_vote( ) .await } + +/// propose call given as hexadecimal +/// can be generated with `subxt explore` for example +pub async fn technical_committee_propose(data: &Data, proposal: &str) -> Result<(), subxt::Error> { + let raw_call = hex::decode(proposal).expect("invalid hex"); + let call = codec::decode_from_bytes(raw_call.into()).expect("invalid call"); + let payload = runtime::tx().technical_committee().propose(5, call, 100); + + submit_call_and_look_event::< + runtime::technical_committee::events::Proposed, + Payload<runtime::technical_committee::calls::types::Propose>, + >(data, &payload) + .await +} diff --git a/src/display.rs b/src/display.rs index 7f68d8d..3320ab4 100644 --- a/src/display.rs +++ b/src/display.rs @@ -150,3 +150,8 @@ impl DisplayEvent for runtime::sudo::events::Sudid { format!("SUDO call succeeded {:?}", self) } } +impl DisplayEvent for runtime::technical_committee::events::Proposed { + fn display(&self, _data: &Data) -> String { + format!("proposed {:?}", self) + } +} -- GitLab