Skip to content

Commit

Permalink
Format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
icodezjb committed Jan 1, 2024
1 parent 9aeab7e commit 1609eaf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 20 additions & 18 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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 {
Expand All @@ -94,22 +96,23 @@ 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<C: SubstrateCli>(&self, cli: &C) -> Result<()> {
let runner = cli.create_runner(self)?;
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<chainx_runtime::Block, Epoch> =
Expand All @@ -131,7 +134,7 @@ pub struct FixEpochOverrideommand {
pub pruning_params: PruningParams,

#[clap(long)]
pub bytes: String
pub bytes: String,
}

impl FixEpochOverrideommand {
Expand All @@ -140,24 +143,23 @@ 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");
let epoch: EpochChangesFor<chainx_runtime::Block, Epoch> =
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
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

0 comments on commit 1609eaf

Please sign in to comment.