Skip to content

Commit

Permalink
Add dump_genesis command for making dummy genesis files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongseup committed Aug 29, 2023
1 parent fa59a75 commit 80e0300
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async fn run(
server_config: Option<ServerConfig>,
) -> 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 }, _, _, _) => {
Expand Down
11 changes: 11 additions & 0 deletions simperby/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?;
Expand Down

0 comments on commit 80e0300

Please sign in to comment.