Skip to content

Commit

Permalink
implement genesis cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar committed Apr 30, 2024
1 parent b710b27 commit 14e60c4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
33 changes: 33 additions & 0 deletions crates/rooch/src/commands/genesis/commands/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::{cli_types::WalletContextOptions, commands::statedb::commands::init_statedb};
use clap::Parser;
use rooch_genesis::RoochGenesis;
use rooch_types::{chain_id::RoochChainID, error::RoochResult};
use std::path::PathBuf;

/// Init genesis statedb
#[derive(Debug, Parser)]
pub struct InitCommand {
#[clap(long = "data-dir", short = 'd')]
/// Path to data dir, this dir is base dir, the final data_dir is base_dir/chain_network_name
pub base_data_dir: Option<PathBuf>,

/// If local chainid, start the service with a temporary data store.
/// All data will be deleted when the service is stopped.
#[clap(long, short = 'n', help = R_OPT_NET_HELP)]
pub chain_id: Option<RoochChainID>,

#[clap(flatten)]
pub context_options: WalletContextOptions,
}

impl InitCommand {
pub async fn execute(self) -> RoochResult<()> {
let mut _context = self.context_options.build()?;
let (root, statedb) = init_statedb(self.base_data_dir.clone(), self.chain_id.clone())?;
//RoochGenesis::build(genesis_ctx, bitcoin_genesis_ctx)
todo!()
}
}
5 changes: 5 additions & 0 deletions crates/rooch/src/commands/genesis/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

pub mod init;
pub mod rebase;
33 changes: 33 additions & 0 deletions crates/rooch/src/commands/genesis/commands/rebase.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::{cli_types::WalletContextOptions, commands::statedb::commands::init_statedb};
use clap::Parser;
use rooch_genesis::RoochGenesis;
use rooch_types::{chain_id::RoochChainID, error::RoochResult};
use std::path::PathBuf;

/// Rebase the genesis
#[derive(Debug, Parser)]
pub struct RebaseCommand {
#[clap(long = "data-dir", short = 'd')]
/// Path to data dir, this dir is base dir, the final data_dir is base_dir/chain_network_name
pub base_data_dir: Option<PathBuf>,

/// If local chainid, start the service with a temporary data store.
/// All data will be deleted when the service is stopped.
#[clap(long, short = 'n', help = R_OPT_NET_HELP)]
pub chain_id: Option<RoochChainID>,

#[clap(flatten)]
pub context_options: WalletContextOptions,
}

impl RebaseCommand {
pub async fn execute(self) -> RoochResult<()> {
let mut _context = self.context_options.build()?;
let (root, statedb) = init_statedb(self.base_data_dir.clone(), self.chain_id.clone())?;
//RoochGenesis::build(genesis_ctx, bitcoin_genesis_ctx)
todo!()
}
}
24 changes: 24 additions & 0 deletions crates/rooch/src/commands/genesis/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use self::commands::init::InitCommand;
use self::commands::rebase::RebaseCommand;
use crate::cli_types::CommandAction;
use async_trait::async_trait;
use clap::Parser;

pub mod commands;

/// Statedb Commands
#[derive(Parser)]
pub struct Genesis {
#[clap(subcommand)]
cmd: GenesisCommand,
}

#[derive(clap::Subcommand)]
#[clap(name = "genesis")]
pub enum GenesisCommand {
Init(InitCommand),
Rebase(RebaseCommand),
}
1 change: 1 addition & 0 deletions crates/rooch/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod abi;
pub mod account;
pub mod env;
pub mod event;
pub mod genesis;
pub mod init;
pub mod move_cli;
pub mod object;
Expand Down

0 comments on commit 14e60c4

Please sign in to comment.