-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [cli] implement genesis cmd * nursery support custom chain
- Loading branch information
Showing
17 changed files
with
196 additions
and
117 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use clap::Parser; | ||
use rooch_config::{RoochOpt, R_OPT_NET_HELP}; | ||
use rooch_db::RoochDB; | ||
use rooch_genesis::RoochGenesis; | ||
use rooch_types::{error::RoochResult, rooch_network::RoochChainID}; | ||
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(long)] | ||
/// The genesis config file path for custom chain network. | ||
/// If the file path equals to builtin chain network name(local/dev/test/main), will use builtin genesis config. | ||
pub genesis_config: Option<String>, | ||
} | ||
|
||
impl InitCommand { | ||
pub async fn execute(self) -> RoochResult<()> { | ||
let opt = | ||
RoochOpt::new_with_default(self.base_data_dir, self.chain_id, self.genesis_config)?; | ||
let store_config = opt.store_config(); | ||
let rooch_db = RoochDB::init(store_config)?; | ||
let network = opt.network(); | ||
let genesis = RoochGenesis::build(network)?; | ||
let root = genesis.init_genesis(&rooch_db)?; | ||
println!( | ||
"Genesis statedb initialized at {:?} successfully, state_root: {:?}", | ||
opt.base().data_dir(), | ||
root.state_root() | ||
); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod init; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) RoochNetwork | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use self::commands::init::InitCommand; | ||
use crate::cli_types::CommandAction; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use rooch_types::error::RoochResult; | ||
|
||
pub mod commands; | ||
|
||
/// Statedb Commands | ||
#[derive(Parser)] | ||
pub struct Genesis { | ||
#[clap(subcommand)] | ||
cmd: GenesisCommand, | ||
} | ||
|
||
#[async_trait] | ||
impl CommandAction<String> for Genesis { | ||
async fn execute(self) -> RoochResult<String> { | ||
match self.cmd { | ||
GenesisCommand::Init(init) => init.execute().await.map(|_| "".to_string()), | ||
} | ||
} | ||
} | ||
|
||
#[derive(clap::Subcommand)] | ||
#[clap(name = "genesis")] | ||
pub enum GenesisCommand { | ||
Init(InitCommand), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.