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

move smith commands to subcommand

parent 2f1fd210
No related branches found
No related tags found
1 merge request!7Big refacto
...@@ -33,6 +33,8 @@ pub enum Subcommand { ...@@ -33,6 +33,8 @@ pub enum Subcommand {
Confirm { name: String }, Confirm { name: String },
/// Revoke an identity immediately /// Revoke an identity immediately
Revoke, Revoke,
/// Generate a revocation document for the provided account
GenRevocDoc,
} }
/// handle identity commands /// handle identity commands
...@@ -65,6 +67,13 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( ...@@ -65,6 +67,13 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<(
data = data.build_keypair().fetch_idty_index().await?; data = data.build_keypair().fetch_idty_index().await?;
commands::identity::revoke_identity(data).await?; commands::identity::revoke_identity(data).await?;
} }
Subcommand::GenRevocDoc => {
data = data
.build_keypair()
.fetch_idty_index()
.await?;
commands::revocation::print_revoc_sig(&data)
}
}; };
Ok(()) Ok(())
......
use crate::*; use crate::*;
use sp_core::{crypto::AccountId32, sr25519::Pair, Pair as _};
use std::ops::Deref; use std::ops::Deref;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner}; use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
type SessionKeys = [u8; 128]; type SessionKeys = [u8; 128];
/// define smith subcommands
#[derive(Clone, Default, Debug, clap::Parser)]
pub enum Subcommand {
/// Emit a smith certification
Cert { to: u32 },
/// go online
GoOnline,
#[default]
/// go offline
GoOffline,
/// Rotate and set session keys
UpdateKeys,
/// set sudo keys
SudoSetKey {
new_key: AccountId,
},
/// List upcoming expirations that require an action
ShowExpire {
/// Show certs that expire within less than this number of blocks
#[clap(short, long, default_value_t = 100800)]
blocks: u32,
/// Show authorities that should rotate keys within less than this number of sessions
#[clap(short, long, default_value_t = 100)]
sessions: u32,
},
/// List online authorities
ShowOnline,
}
/// handle smith 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::GoOnline => {
commands::smith::go_online(&data).await?;
}
Subcommand::GoOffline => {
commands::smith::go_offline(&data).await?;
}
Subcommand::Cert { to } => {
data = data.build_keypair().fetch_idty_index().await?;
commands::smith::cert(&data, to).await?
}
Subcommand::UpdateKeys => {
commands::smith::update_session_keys(&data).await?;
}
Subcommand::SudoSetKey { new_key } => {
data = data.build_keypair().build_client().await?;
commands::sudo::set_key(data.keypair(), data.client(), new_key).await?;
}
Subcommand::ShowExpire { blocks, sessions } => {
data = data.build_client().await?;
commands::expire::monitor_expirations(&data, blocks, sessions).await?
}
Subcommand::ShowOnline => {
data = data.build_client().await?;
commands::smith::online(&data).await?
}
};
Ok(())
}
/// rotate session keys /// rotate session keys
pub async fn rotate_keys(client: &Client) -> Result<SessionKeys, anyhow::Error> { pub async fn rotate_keys(client: &Client) -> Result<SessionKeys, anyhow::Error> {
client client
...@@ -19,39 +81,37 @@ pub async fn rotate_keys(client: &Client) -> Result<SessionKeys, anyhow::Error> ...@@ -19,39 +81,37 @@ pub async fn rotate_keys(client: &Client) -> Result<SessionKeys, anyhow::Error>
/// set session keys /// set session keys
pub async fn set_session_keys( pub async fn set_session_keys(
pair: Pair, data: &Data,
client: &Client,
session_keys: SessionKeys, session_keys: SessionKeys,
) -> Result<TxProgress, subxt::Error> { ) -> Result<TxProgress, subxt::Error> {
client data.client()
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
&runtime::tx() &runtime::tx()
.authority_members() .authority_members()
.set_session_keys(session_keys), .set_session_keys(session_keys),
&PairSigner::new(pair), &PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(), BaseExtrinsicParamsBuilder::new(),
) )
.await .await
} }
/// update session keys /// update session keys
pub async fn update_session_keys(pair: Pair, client: &Client) -> Result<(), GcliError> { pub async fn update_session_keys(data: &Data) -> Result<(), GcliError> {
let session_keys = rotate_keys(client).await?; let session_keys = rotate_keys(data.client()).await?;
let progress = set_session_keys(pair, client, session_keys).await?; let progress = set_session_keys(data, session_keys).await?;
let _ = track_progress(progress).await?; // TODO let _ = track_progress(progress).await?; // TODO
Ok(()) Ok(())
} }
/// submit go_online /// submit go_online
pub async fn go_online(pair: Pair, client: &Client) -> Result<(), GcliError> { pub async fn go_online(data: &Data) -> Result<(), GcliError> {
if client if data
.client()
.storage() .storage()
.fetch( .fetch(
&runtime::storage() &runtime::storage().session().next_keys(data.address()),
.session()
.next_keys(AccountId32::from(pair.public())),
None, None,
) )
.await? .await?
...@@ -62,11 +122,11 @@ pub async fn go_online(pair: Pair, client: &Client) -> Result<(), GcliError> { ...@@ -62,11 +122,11 @@ pub async fn go_online(pair: Pair, client: &Client) -> Result<(), GcliError> {
)); ));
} }
let progress = client let progress = data.client()
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
&runtime::tx().authority_members().go_online(), &runtime::tx().authority_members().go_online(),
&PairSigner::new(pair), &PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(), BaseExtrinsicParamsBuilder::new(),
) )
.await?; .await?;
...@@ -79,12 +139,13 @@ pub async fn go_online(pair: Pair, client: &Client) -> Result<(), GcliError> { ...@@ -79,12 +139,13 @@ pub async fn go_online(pair: Pair, client: &Client) -> Result<(), GcliError> {
} }
/// submit go_offline /// submit go_offline
pub async fn go_offline(pair: Pair, client: &Client) -> Result<(), subxt::Error> { pub async fn go_offline(data: &Data) -> Result<(), subxt::Error> {
let progress = client let progress = data
.client()
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
&runtime::tx().authority_members().go_offline(), &runtime::tx().authority_members().go_offline(),
&PairSigner::new(pair), &PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(), BaseExtrinsicParamsBuilder::new(),
) )
.await?; .await?;
...@@ -178,17 +239,13 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> { ...@@ -178,17 +239,13 @@ pub async fn online(data: &Data) -> Result<(), anyhow::Error> {
} }
/// submit a certification and track progress /// submit a certification and track progress
pub async fn cert( pub async fn cert(data: &Data, receiver: u32) -> Result<(), anyhow::Error> {
client: &Client, let progress = data
pair: Pair, .client()
issuer: u32,
receiver: u32,
) -> Result<(), anyhow::Error> {
let progress = client
.tx() .tx()
.sign_and_submit_then_watch( .sign_and_submit_then_watch(
&runtime::tx().smith_cert().add_cert(issuer, receiver), &runtime::tx().smith_cert().add_cert(data.idty_index(), receiver),
&PairSigner::new(pair), &PairSigner::new(data.keypair()),
BaseExtrinsicParamsBuilder::new(), BaseExtrinsicParamsBuilder::new(),
) )
.await?; .await?;
......
...@@ -162,21 +162,6 @@ pub enum Subcommand { ...@@ -162,21 +162,6 @@ pub enum Subcommand {
Balance, Balance,
/// Show address corresponding to given arguments /// Show address corresponding to given arguments
ShowAddress, ShowAddress,
/// Generate a revocation document for the provided account
GenRevocDoc,
/// List upcoming expirations that require an action
Expire {
/// Show certs that expire within less than this number of blocks
#[clap(short, long, default_value_t = 100800)]
blocks: u32,
/// Show authorities that should rotate keys within less than this number of sessions
#[clap(short, long, default_value_t = 100)]
sessions: u32,
},
GoOffline,
GoOnline,
/// List online authorities
Online,
#[clap(hide = true)] #[clap(hide = true)]
Repart { Repart {
// Number of transactions per block to target // Number of transactions per block to target
...@@ -189,13 +174,6 @@ pub enum Subcommand { ...@@ -189,13 +174,6 @@ pub enum Subcommand {
SpamRoll { SpamRoll {
actual_repart: usize, actual_repart: usize,
}, },
SudoSetKey {
new_key: AccountId,
},
/// Emit a smith certification
SmithCert {
to: u32,
},
/// List members of the technical committee /// List members of the technical committee
TechMembers, TechMembers,
/// List proposals to the technical committee /// List proposals to the technical committee
...@@ -226,21 +204,22 @@ pub enum Subcommand { ...@@ -226,21 +204,22 @@ pub enum Subcommand {
/// List of target addresses /// List of target addresses
dests: Vec<AccountId>, dests: Vec<AccountId>,
}, },
/// Rotate and set session keys
UpdateKeys,
/// Get information about runtime /// Get information about runtime
RuntimeInfo, RuntimeInfo,
/// Check current block /// Check current block
CurrentBlock, CurrentBlock,
/// Indentity subcommands /// Identity subcommands
#[clap(subcommand)] #[clap(subcommand)]
Identity(commands::identity::Subcommand), Identity(commands::identity::Subcommand),
/// Oneshot account subcommands /// Smith subcommands
#[clap(subcommand)] #[clap(subcommand)]
Oneshot(commands::oneshot::Subcommand), Smith(commands::smith::Subcommand),
/// Universal Dividend subcommands /// Universal Dividend subcommands
#[clap(subcommand)] #[clap(subcommand)]
Ud(commands::ud::Subcommand), Ud(commands::ud::Subcommand),
/// Oneshot account subcommands
#[clap(subcommand)]
Oneshot(commands::oneshot::Subcommand),
/// Indexer subcommands /// Indexer subcommands
#[clap(subcommand)] #[clap(subcommand)]
Indexer(indexer::Subcommand), Indexer(indexer::Subcommand),
...@@ -272,53 +251,6 @@ async fn main() -> Result<(), GcliError> { ...@@ -272,53 +251,6 @@ async fn main() -> Result<(), GcliError> {
data = data.build_address(); data = data.build_address();
println!("address is: {}", data.address()); println!("address is: {}", data.address());
} }
Subcommand::Expire { blocks, sessions } => {
data = data.build_client().await?;
commands::expire::monitor_expirations(&data, blocks, sessions).await?
}
Subcommand::GenRevocDoc => {
data = data
.build_client()
.await?
.build_keypair()
.fetch_idty_index()
.await?;
commands::revocation::print_revoc_sig(&data)
}
Subcommand::GoOffline => {
data = data.build_client().await?;
commands::smith::go_offline(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
data.client(),
)
.await?;
}
Subcommand::GoOnline => {
data = data.build_client().await?;
commands::smith::go_online(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
data.client(),
)
.await?;
}
Subcommand::Online => {
data = data.build_client().await?;
commands::smith::online(&data).await?
}
Subcommand::Repart { Subcommand::Repart {
target, target,
actual_repart, actual_repart,
...@@ -355,19 +287,6 @@ async fn main() -> Result<(), GcliError> { ...@@ -355,19 +287,6 @@ async fn main() -> Result<(), GcliError> {
) )
.await? .await?
} }
Subcommand::SudoSetKey { new_key } => {
data = data.build_keypair().build_client().await?;
commands::sudo::set_key(data.keypair(), data.client(), new_key).await?;
}
Subcommand::SmithCert { to } => {
data = data
.build_client()
.await?
.build_keypair()
.fetch_idty_index()
.await?;
commands::smith::cert(data.client(), data.keypair(), data.idty_index(), to).await?
}
Subcommand::TechMembers => { Subcommand::TechMembers => {
data = data.build_client().await?; data = data.build_client().await?;
commands::collective::technical_committee_members(&data).await? commands::collective::technical_committee_members(&data).await?
...@@ -438,21 +357,6 @@ async fn main() -> Result<(), GcliError> { ...@@ -438,21 +357,6 @@ async fn main() -> Result<(), GcliError> {
) )
.await?; .await?;
} }
Subcommand::UpdateKeys => {
data = data.build_client().await?;
commands::smith::update_session_keys(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
data.client(),
)
.await?;
}
Subcommand::RuntimeInfo => { Subcommand::RuntimeInfo => {
data = data.build_client().await?.fetch_system_properties().await?; data = data.build_client().await?.fetch_system_properties().await?;
commands::runtime::runtime_info(data).await; commands::runtime::runtime_info(data).await;
...@@ -470,10 +374,11 @@ async fn main() -> Result<(), GcliError> { ...@@ -470,10 +374,11 @@ 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::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?
} }
Subcommand::Ud(subcommand) => commands::ud::handle_command(data, subcommand).await?,
Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?, Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?,
Subcommand::Config(subcommand) => conf::handle_command(data, subcommand)?, Subcommand::Config(subcommand) => conf::handle_command(data, subcommand)?,
} }
......
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