From 1609eaf9c804c97bc95c5a763d10b5372f43611c Mon Sep 17 00:00:00 2001 From: icodezjb Date: Mon, 1 Jan 2024 17:50:47 +0800 Subject: [PATCH] Format codes --- cli/src/cli.rs | 38 ++++++++++++++++++++------------------ cli/src/command.rs | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 5315d073f..55e5e80d4 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -1,9 +1,11 @@ // Copyright 2019-2023 ChainX Project Authors. Licensed under GPL-3.0. -use sc_cli::{CliConfiguration, KeySubcommand, SharedParams, PruningParams, SignCmd, VanityCmd, VerifyCmd, Result, SubstrateCli}; +use sc_cli::{ + CliConfiguration, KeySubcommand, PruningParams, Result, SharedParams, SignCmd, SubstrateCli, + VanityCmd, VerifyCmd, +}; use sc_client_api::AuxStore; - use chainx_service::new_partial; #[derive(Debug, clap::Parser)] @@ -64,13 +66,13 @@ pub enum Subcommand { Revert(sc_cli::RevertCmd), #[clap(subcommand)] - FixBabeEpoch(FixEpochSubCommand) + FixBabeEpoch(FixEpochSubCommand), } #[derive(Debug, clap::Subcommand)] pub enum FixEpochSubCommand { Dump(FixEpochDumpCommand), - Override(FixEpochOverrideommand) + Override(FixEpochOverrideommand), } impl FixEpochSubCommand { @@ -94,9 +96,9 @@ pub struct FixEpochDumpCommand { pub pruning_params: PruningParams, } const BABE_EPOCH_CHANGES_KEY: &[u8] = b"babe_epoch_changes"; -use sc_consensus_babe::{Epoch}; +use codec::{Decode, Encode}; +use sc_consensus_babe::Epoch; use sc_consensus_epochs::EpochChangesFor; -use codec::{Encode, Decode}; impl FixEpochDumpCommand { pub fn run(&self, cli: &C) -> Result<()> { @@ -104,12 +106,13 @@ impl FixEpochDumpCommand { runner.sync_run(|mut config| { let components = new_partial::< chainx_runtime::RuntimeApi, - chainx_executor::ChainXExecutor - >( - &mut config, - )?; + chainx_executor::ChainXExecutor, + >(&mut config)?; let client = components.client; - let bytes = client.get_aux(BABE_EPOCH_CHANGES_KEY).expect("Access DB should success").expect("value must exist"); + let bytes = client + .get_aux(BABE_EPOCH_CHANGES_KEY) + .expect("Access DB should success") + .expect("value must exist"); let hex_str = hex::encode(&bytes); println!("{}", hex_str); let epoch: EpochChangesFor = @@ -131,7 +134,7 @@ pub struct FixEpochOverrideommand { pub pruning_params: PruningParams, #[clap(long)] - pub bytes: String + pub bytes: String, } impl FixEpochOverrideommand { @@ -140,10 +143,8 @@ impl FixEpochOverrideommand { runner.sync_run(|mut config| { let components = new_partial::< chainx_runtime::RuntimeApi, - chainx_executor::ChainXExecutor - >( - &mut config, - )?; + chainx_executor::ChainXExecutor, + >(&mut config)?; let client = components.client; let bytes = hex::decode(&self.bytes).expect("require hex string without 0x"); @@ -151,13 +152,14 @@ impl FixEpochOverrideommand { Decode::decode(&mut &bytes[..]).expect("Decode must success"); println!("epoch: {:?}", epoch); - client.insert_aux(&[(BABE_EPOCH_CHANGES_KEY, &epoch.encode()[..])], &[]).expect("Insert to db must success"); + client + .insert_aux(&[(BABE_EPOCH_CHANGES_KEY, &epoch.encode()[..])], &[]) + .expect("Insert to db must success"); Ok(()) }) } } - impl CliConfiguration for FixEpochDumpCommand { fn shared_params(&self) -> &SharedParams { &self.shared_params diff --git a/cli/src/command.rs b/cli/src/command.rs index f55ca8306..a206bd379 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -417,6 +417,6 @@ pub fn run() -> sc_cli::Result<()> { Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \ You can enable it with `--features try-runtime`." .into()), - Some(Subcommand::FixBabeEpoch(cmd)) => cmd.run(&cli) + Some(Subcommand::FixBabeEpoch(cmd)) => cmd.run(&cli), } }