diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 3e1f9537..597a951a 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -76,6 +76,8 @@ pub enum SignCommands { #[derive(Debug, Subcommand)] pub enum Commands { + /// Dumps genesis block files to the path + DummyGenesis, // ----- Initialization Commands ----- // /// Create a genesis commit and initialize a Simberby repository /// from the given existing Git repository. diff --git a/cli/src/main.rs b/cli/src/main.rs index cf92a408..98f23d9f 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -21,6 +21,7 @@ async fn run( server_config: Option, ) -> eyre::Result<()> { match (args.command, config, auth, server_config) { + (Commands::DummyGenesis, _, _, _) => Client::dump_genesis(&path).await, (Commands::Genesis, _, _, _) => Client::genesis(&path).await, (Commands::Init, _, _, _) => Client::init(&path).await, (Commands::Clone { url }, _, _, _) => { diff --git a/simperby/src/lib.rs b/simperby/src/lib.rs index 837fbb88..0e49a59e 100644 --- a/simperby/src/lib.rs +++ b/simperby/src/lib.rs @@ -14,6 +14,7 @@ use simperby_repository::raw::RawRepository; use simperby_repository::*; use std::net::SocketAddrV4; use std::sync::Arc; +use tokio::fs; use tokio::sync::RwLock; pub use simperby_consensus; @@ -41,6 +42,17 @@ pub struct Client { } impl Client { + pub async fn dump_genesis(path: &str) -> Result<()> { + let (rs, keys) = test_utils::generate_standard_genesis(4); + + simperby_repository::raw::reserved_state::write_reserved_state(path, &rs) + .await + .unwrap(); + + let keys = serde_spb::to_string(&keys)?; + fs::write(format!("{}/{}", path, "keys.json"), keys).await?; + Ok(()) + } pub async fn genesis(path: &str) -> Result<()> { let repository = RawRepository::open(path).await?; DistributedRepository::genesis(repository).await?;