mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 01:21:01 +00:00
Revert chain command (#393)
* Revert chain command * BLOCKS -> NUM * Fixed warning
This commit is contained in:
committed by
Gav Wood
parent
e65672575f
commit
65f0c5f3af
@@ -223,6 +223,10 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
|
||||
return import_blocks(matches, worker.exit_only());
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("revert") {
|
||||
return revert_chain(matches);
|
||||
}
|
||||
|
||||
let (spec, is_global) = load_spec(&matches)?;
|
||||
let mut config = service::Configuration::default_with_spec(spec);
|
||||
|
||||
@@ -248,7 +252,7 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
|
||||
|
||||
config.pruning = match matches.value_of("pruning") {
|
||||
Some("archive") => PruningMode::ArchiveAll,
|
||||
None => PruningMode::keep_blocks(256),
|
||||
None => PruningMode::default(),
|
||||
Some(s) => PruningMode::keep_blocks(s.parse()
|
||||
.map_err(|_| error::ErrorKind::Input("Invalid pruning mode specified".to_owned()))?),
|
||||
};
|
||||
@@ -495,6 +499,25 @@ fn import_blocks<E>(matches: &clap::ArgMatches, exit: E) -> error::Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn revert_chain(matches: &clap::ArgMatches) -> error::Result<()> {
|
||||
let (spec, _) = load_spec(&matches)?;
|
||||
let base_path = base_path(matches);
|
||||
let mut config = service::Configuration::default_with_spec(spec);
|
||||
config.database_path = db_path(&base_path, config.chain_spec.id()).to_string_lossy().into();
|
||||
|
||||
let client = service::new_client(config)?;
|
||||
|
||||
let blocks = match matches.value_of("NUM") {
|
||||
Some(v) => v.parse().map_err(|_| "Invalid block count specified")?,
|
||||
None => 256,
|
||||
};
|
||||
|
||||
let reverted = client.revert(blocks)?;
|
||||
let info = client.info()?.chain;
|
||||
info!("Reverted {} blocks. Best: #{} ({})", reverted, info.best_number, info.best_hash);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_until_exit<C, W>(
|
||||
runtime: &mut Runtime,
|
||||
service: service::Service<C>,
|
||||
|
||||
Reference in New Issue
Block a user