Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dump_genesis command in cli #511

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dummy? Dump? Please match the word

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)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unnecessary newlines here

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
Loading