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 crate::*;
use anyhow::Result; use anyhow::Result;
use sp_core::{sr25519::Pair, H256};
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner}; 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 /// list technical committee members
pub async fn technical_committee_members(data: &Data) -> Result<()> { pub async fn technical_committee_members(data: &Data) -> Result<()> {
let client = data.client(); let client = data.client();
...@@ -67,7 +115,7 @@ pub async fn technical_committee_proposals(client: &Client) -> Result<()> { ...@@ -67,7 +115,7 @@ pub async fn technical_committee_proposals(client: &Client) -> Result<()> {
.iter( .iter(
runtime::storage() runtime::storage()
.technical_committee() .technical_committee()
.proposal_of(H256::default()), .proposal_of(Hash::default()),
10, 10,
Some(parent_hash), Some(parent_hash),
) )
...@@ -83,19 +131,19 @@ pub async fn technical_committee_proposals(client: &Client) -> Result<()> { ...@@ -83,19 +131,19 @@ pub async fn technical_committee_proposals(client: &Client) -> Result<()> {
/// submit vote to technical committee /// submit vote to technical committee
pub async fn technical_committee_vote( pub async fn technical_committee_vote(
pair: Pair, data: &Data,
client: &Client, proposal_hash: Hash,
proposal_hash: H256,
proposal_index: u32, proposal_index: u32,
vote: bool, vote: bool,
) -> Result<(), subxt::Error> { ) -> Result<(), subxt::Error> {
let progress = client let progress = data
.client()
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
&runtime::tx() &runtime::tx()
.technical_committee() .technical_committee()
.vote(proposal_hash, proposal_index, vote), .vote(proposal_hash, proposal_index, vote),
&PairSigner::new(pair), &PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(), BaseExtrinsicParamsBuilder::new(),
) )
.await?; .await?;
......
...@@ -11,7 +11,7 @@ use codec::Encode; ...@@ -11,7 +11,7 @@ use codec::Encode;
use data::*; use data::*;
use keys::*; use keys::*;
use serde::Deserialize; use serde::Deserialize;
use sp_core::{sr25519::Pair, Pair as _, H256}; use sp_core::{sr25519::Pair, Pair as _};
use subxt::blocks::ExtrinsicEvents; use subxt::blocks::ExtrinsicEvents;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner, TxStatus}; use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner, TxStatus};
...@@ -174,19 +174,6 @@ pub enum Subcommand { ...@@ -174,19 +174,6 @@ pub enum Subcommand {
SpamRoll { SpamRoll {
actual_repart: usize, 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 { Transfer {
/// Amount to transfer /// Amount to transfer
amount: u64, amount: u64,
...@@ -214,6 +201,9 @@ pub enum Subcommand { ...@@ -214,6 +201,9 @@ pub enum Subcommand {
/// Smith subcommands /// Smith subcommands
#[clap(subcommand)] #[clap(subcommand)]
Smith(commands::smith::Subcommand), Smith(commands::smith::Subcommand),
/// Tech subcommands
#[clap(subcommand)]
Tech(commands::collective::Subcommand),
/// Universal Dividend subcommands /// Universal Dividend subcommands
#[clap(subcommand)] #[clap(subcommand)]
Ud(commands::ud::Subcommand), Ud(commands::ud::Subcommand),
...@@ -287,37 +277,6 @@ async fn main() -> Result<(), GcliError> { ...@@ -287,37 +277,6 @@ async fn main() -> Result<(), GcliError> {
) )
.await? .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 { Subcommand::Transfer {
amount, amount,
dest, dest,
...@@ -375,6 +334,7 @@ async fn main() -> Result<(), GcliError> { ...@@ -375,6 +334,7 @@ async fn main() -> Result<(), GcliError> {
} }
Subcommand::Identity(subcommand) => commands::identity::handle_command(data, subcommand).await?, Subcommand::Identity(subcommand) => commands::identity::handle_command(data, subcommand).await?,
Subcommand::Smith(subcommand) => commands::smith::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::Ud(subcommand) => commands::ud::handle_command(data, subcommand).await?,
Subcommand::Oneshot(subcommand) => { Subcommand::Oneshot(subcommand) => {
commands::oneshot::handle_command(data, subcommand).await? 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