diff --git a/crates/rooch/src/commands/da/commands/mod.rs b/crates/rooch/src/commands/da/commands/mod.rs index f521c2841d..9688e97e39 100644 --- a/crates/rooch/src/commands/da/commands/mod.rs +++ b/crates/rooch/src/commands/da/commands/mod.rs @@ -1,4 +1,5 @@ // Copyright (c) RoochNetwork // SPDX-License-Identifier: Apache-2.0 +pub mod namespace; pub mod unpack; diff --git a/crates/rooch/src/commands/da/commands/namespace.rs b/crates/rooch/src/commands/da/commands/namespace.rs new file mode 100644 index 0000000000..d22edd3115 --- /dev/null +++ b/crates/rooch/src/commands/da/commands/namespace.rs @@ -0,0 +1,23 @@ +// Copyright (c) RoochNetwork +// SPDX-License-Identifier: Apache-2.0 + +use clap::Parser; +use rooch_config::da_config::derive_genesis_namespace; +use rooch_types::error::RoochResult; +use std::path::PathBuf; + +/// Derive DA namespace from genesis file. +#[derive(Debug, Parser)] +pub struct NamespaceCommand { + #[clap(long = "genesis-file-path")] + pub genesis_file_path: PathBuf, +} + +impl NamespaceCommand { + pub fn execute(self) -> RoochResult<()> { + let genesis_bytes = std::fs::read(&self.genesis_file_path)?; + let namespace = derive_genesis_namespace(&genesis_bytes); + println!("DA genesis namespace: {}", namespace); + Ok(()) + } +} diff --git a/crates/rooch/src/commands/da/mod.rs b/crates/rooch/src/commands/da/mod.rs index 23744c7ba5..996d04918c 100644 --- a/crates/rooch/src/commands/da/mod.rs +++ b/crates/rooch/src/commands/da/mod.rs @@ -4,6 +4,7 @@ pub mod commands; use crate::cli_types::CommandAction; +use crate::commands::da::commands::namespace::NamespaceCommand; use crate::commands::da::commands::unpack::UnpackCommand; use async_trait::async_trait; use clap::Parser; @@ -23,6 +24,7 @@ impl CommandAction for DA { DACommand::Unpack(unpack) => unpack.execute().map(|resp| { serde_json::to_string_pretty(&resp).expect("Failed to serialize response") }), + DACommand::Namespace(namespace) => namespace.execute().map(|_| "".to_owned()), } } } @@ -31,4 +33,5 @@ impl CommandAction for DA { #[clap(name = "da")] pub enum DACommand { Unpack(UnpackCommand), + Namespace(NamespaceCommand), }