use crate::error;
use crate::params::{GenericNumber, PruningParams, SharedParams};
use crate::CliConfiguration;
use tc_service::chain_ops::revert_chain;
use tp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::fmt::Debug;
use std::str::FromStr;
use std::sync::Arc;
use structopt::StructOpt;
use tc_client_api::{Backend, UsageProvider};
#[derive(Debug, StructOpt)]
pub struct RevertCmd {
#[structopt(default_value = "256")]
pub num: GenericNumber,
#[allow(missing_docs)]
#[structopt(flatten)]
pub shared_params: SharedParams,
#[allow(missing_docs)]
#[structopt(flatten)]
pub pruning_params: PruningParams,
}
impl RevertCmd {
pub async fn run<B, BA, C>(
&self,
client: Arc<C>,
backend: Arc<BA>,
) -> error::Result<()>
where
B: BlockT,
BA: Backend<B>,
C: UsageProvider<B>,
<<<B as BlockT>::Header as HeaderT>::Number as FromStr>::Err: Debug,
{
let blocks = self.num.parse()?;
revert_chain(client, backend, blocks)?;
Ok(())
}
}
impl CliConfiguration for RevertCmd {
fn shared_params(&self) -> &SharedParams {
&self.shared_params
}
fn pruning_params(&self) -> Option<&PruningParams> {
Some(&self.pruning_params)
}
}