From 80e03002215e003de90543ad431a580bea684118 Mon Sep 17 00:00:00 2001 From: Jeongseup Date: Wed, 30 Aug 2023 00:21:32 +0900 Subject: [PATCH] Add dump_genesis command for making dummy genesis files --- cli/src/cli.rs | 2 ++ cli/src/main.rs | 1 + simperby/src/lib.rs | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 3e1f9537..88900c72 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 + DumpGenesis, // ----- 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..42d5af69 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::DumpGenesis, _, _, _) => 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..7783c529 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,16 @@ 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?;