Skip to content
Snippets Groups Projects
Commit f3407daa authored by Hugo Trentesaux's avatar Hugo Trentesaux Committed by Hugo Trentesaux
Browse files

move tech commands to subcommand

parent 91f70433
No related branches found
No related tags found
1 merge request!7Big refacto
use crate::*;
use anyhow::Result;
use sp_core::{sr25519::Pair, H256};
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
/// define technical committee subcommands
#[derive(Clone, Default, Debug, clap::Parser)]
pub enum Subcommand {
#[default]
/// List members of the technical committee
Members,
/// List proposals to the technical committee
Proposals,
/// Vote a proposal to the technical committee
Vote {
/// Proposal hash
hash: Hash,
/// Proposal index
index: u32,
/// Vote (0=against, 1=for)
vote: u8,
},
}
/// handle technical committee commands
pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> {
let mut data = data.build_client().await?.build_indexer().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::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(
&data, hash, //Hash::from_str(&hash).expect("Invalid hash formatting"),
index, vote,
)
.await?;
}
};
Ok(())
}
/// list technical committee members
pub async fn technical_committee_members(data: &Data) -> Result<()> {
let client = data.client();
......@@ -67,7 +115,7 @@ pub async fn technical_committee_proposals(client: &Client) -> Result<()> {
.iter(
runtime::storage()
.technical_committee()
.proposal_of(H256::default()),
.proposal_of(Hash::default()),
10,
Some(parent_hash),
)
......@@ -83,19 +131,19 @@ pub async fn technical_committee_proposals(client: &Client) -> Result<()> {
/// submit vote to technical committee
pub async fn technical_committee_vote(
pair: Pair,
client: &Client,
proposal_hash: H256,
data: &Data,
proposal_hash: Hash,
proposal_index: u32,
vote: bool,
) -> Result<(), subxt::Error> {
let progress = client
let progress = data
.client()
.tx()
.sign_and_submit_then_watch(
&runtime::tx()
.technical_committee()
.vote(proposal_hash, proposal_index, vote),
&PairSigner::new(pair),
&PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(),
)
.await?;
......
......@@ -11,7 +11,7 @@ use codec::Encode;
use data::*;
use keys::*;
use serde::Deserialize;
use sp_core::{sr25519::Pair, Pair as _, H256};
use sp_core::{sr25519::Pair, Pair as _};
use subxt::blocks::ExtrinsicEvents;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner, TxStatus};
......@@ -174,19 +174,6 @@ pub enum Subcommand {
SpamRoll {
actual_repart: usize,
},
/// List members of the technical committee
TechMembers,
/// List proposals to the technical committee
TechProposals,
/// Vote a proposal to the technical committee
TechVote {
/// Proposal hash
hash: H256,
/// Proposal index
index: u32,
/// Vote (0=against, 1=for)
vote: u8,
},
Transfer {
/// Amount to transfer
amount: u64,
......@@ -214,6 +201,9 @@ pub enum Subcommand {
/// Smith subcommands
#[clap(subcommand)]
Smith(commands::smith::Subcommand),
/// Tech subcommands
#[clap(subcommand)]
Tech(commands::collective::Subcommand),
/// Universal Dividend subcommands
#[clap(subcommand)]
Ud(commands::ud::Subcommand),
......@@ -287,37 +277,6 @@ async fn main() -> Result<(), GcliError> {
)
.await?
}
Subcommand::TechMembers => {
data = data.build_client().await?;
commands::collective::technical_committee_members(&data).await?
}
Subcommand::TechProposals => {
data = data.build_client().await?;
commands::collective::technical_committee_proposals(data.client()).await?
}
Subcommand::TechVote { 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(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
data.client(),
hash, //H256::from_str(&hash).expect("Invalid hash formatting"),
index,
vote,
)
.await?;
}
Subcommand::Transfer {
amount,
dest,
......@@ -375,6 +334,7 @@ async fn main() -> Result<(), GcliError> {
}
Subcommand::Identity(subcommand) => commands::identity::handle_command(data, subcommand).await?,
Subcommand::Smith(subcommand) => commands::smith::handle_command(data, subcommand).await?,
Subcommand::Tech(subcommand) => commands::collective::handle_command(data, subcommand).await?,
Subcommand::Ud(subcommand) => commands::ud::handle_command(data, subcommand).await?,
Subcommand::Oneshot(subcommand) => {
commands::oneshot::handle_command(data, subcommand).await?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment