Skip to content

Commit

Permalink
feat(da): add NamespaceCommand for deriving DA namespace from genesis…
Browse files Browse the repository at this point in the history
… file (#3003)

This commit introduces the `NamespaceCommand` which allows users to derive the DA namespace from a genesis file. The command is now part of the DA command module, enhancing the functionality provided by the CLI.
  • Loading branch information
popcnt1 authored Dec 2, 2024
1 parent 8a38288 commit 38c0da2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/rooch/src/commands/da/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

pub mod namespace;
pub mod unpack;
23 changes: 23 additions & 0 deletions crates/rooch/src/commands/da/commands/namespace.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
3 changes: 3 additions & 0 deletions crates/rooch/src/commands/da/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,7 @@ impl CommandAction<String> 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()),
}
}
}
Expand All @@ -31,4 +33,5 @@ impl CommandAction<String> for DA {
#[clap(name = "da")]
pub enum DACommand {
Unpack(UnpackCommand),
Namespace(NamespaceCommand),
}

0 comments on commit 38c0da2

Please sign in to comment.