Skip to content

Commit

Permalink
[aptos] Make a directory for key generation if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
davidiw authored and aptos-bot committed May 11, 2022
1 parent 84db3d0 commit 25b1a95
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 0 additions & 2 deletions crates/aptos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,12 @@ To generate this using the `aptos` CLI:
1. Generate your validator's keys:
```
mkdir bobs
cargo run --package aptos -- genesis generate-keys --output-dir bobs
```
2. Generate your `ValidatorConfiguration`:
```
mkdir my_config
cargo run --package aptos -- \\
genesis set-validator-configuration \\
--keys-dir bobs \\
Expand Down
6 changes: 3 additions & 3 deletions crates/aptos/src/genesis/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ impl Client {
pub fn put<T: Serialize + ?Sized>(&self, name: &str, input: &T) -> CliTypedResult<()> {
match self {
Client::Local(local_repository_path) => {
self.create_dir(local_repository_path.to_str().unwrap())?;

let path = local_repository_path.join(format!("{}.yaml", name));
write_to_file(
path.as_path(),
Expand All @@ -178,9 +180,7 @@ impl Client {
match self {
Client::Local(local_repository_path) => {
let path = local_repository_path.join(name);
if path.exists() && path.is_dir() {
// Do nothing
} else {
if !path.exists() || !path.is_dir() {
std::fs::create_dir(path.as_path())
.map_err(|e| CliError::IO(path.display().to_string(), e))?
};
Expand Down
6 changes: 6 additions & 0 deletions crates/aptos/src/genesis/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ impl CliCommand<PathBuf> for GenerateKeys {
consensus_key,
network_key,
};

if !self.output_dir.exists() || !self.output_dir.is_dir() {
std::fs::create_dir(&self.output_dir)
.map_err(|e| CliError::IO(self.output_dir.to_str().unwrap().to_string(), e))?
};

write_to_file(
keys_file.as_path(),
"private_keys.yaml",
Expand Down

0 comments on commit 25b1a95

Please sign in to comment.