Skip to content

Commit

Permalink
[aptos-cli] Genesis argument name cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored and aptos-bot committed May 5, 2022
1 parent ac2c10e commit 39852b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion crates/aptos/src/genesis/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Layout {
/// ChainId for the target network
pub chain_id: ChainId,
/// Modules folder
pub modules_folder: String,
pub modules_dir: String,
}

impl Layout {
Expand Down
25 changes: 13 additions & 12 deletions crates/aptos/src/genesis/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct SetupGit {
git_options: GitOptions,
/// Path to `Layout` which defines where all the files are
#[clap(long, parse(from_os_str))]
layout_path: PathBuf,
layout_file: PathBuf,
}

#[async_trait]
Expand All @@ -36,14 +36,14 @@ impl CliCommand<()> for SetupGit {
}

async fn execute(self) -> CliTypedResult<()> {
let layout = Layout::from_disk(&self.layout_path)?;
let layout = Layout::from_disk(&self.layout_file)?;

// Upload layout file to ensure we can read later
let client = self.git_options.get_client()?;
client.put(LAYOUT_NAME, &layout)?;

// Make a place for the modules to be uploaded
client.create_dir(&layout.modules_folder)?;
client.create_dir(&layout.modules_dir)?;

Ok(())
}
Expand Down Expand Up @@ -81,27 +81,27 @@ pub struct GitOptions {
github_branch: String,
/// Path to Github API token. Token must have repo:* permissions
#[clap(long, parse(from_os_str))]
github_token_path: Option<PathBuf>,
/// Path to local git repo.
github_token_file: Option<PathBuf>,
/// Path to local git repository
#[clap(long, parse(from_os_str))]
local_repository_path: Option<PathBuf>,
local_repository_dir: Option<PathBuf>,
}

impl GitOptions {
pub fn get_client(self) -> CliTypedResult<GitClient> {
if self.github_repository.is_none()
&& self.github_token_path.is_none()
&& self.local_repository_path.is_some()
&& self.github_token_file.is_none()
&& self.local_repository_dir.is_some()
{
Ok(GitClient::local(self.local_repository_path.unwrap()))
Ok(GitClient::local(self.local_repository_dir.unwrap()))
} else if self.github_repository.is_some()
&& self.github_token_path.is_some()
&& self.local_repository_path.is_none()
&& self.github_token_file.is_some()
&& self.local_repository_dir.is_none()
{
GitClient::github(
self.github_repository.unwrap(),
self.github_branch,
self.github_token_path.unwrap(),
self.github_token_file.unwrap(),
)
} else {
Err(CliError::CommandArgumentError("Must provide either only --local-repository-path or both --github-repository and --github-token-path".to_string()))
Expand Down Expand Up @@ -143,6 +143,7 @@ impl GitClient {
let path = local_repository_path.join(format!("{}.yml", name));
let mut file = std::fs::File::open(path.as_path())
.map_err(|e| CliError::IO(path.display().to_string(), e))?;

let mut contents = String::new();
file.read_to_string(&mut contents)
.map_err(|e| CliError::IO(path.display().to_string(), e))?;
Expand Down
18 changes: 9 additions & 9 deletions crates/aptos/src/genesis/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const NETWORK_KEY_FILE: &str = "network.key";
pub struct GenerateKeys {
/// Output path for the three keys
#[clap(long, parse(from_os_str), default_value = ".")]
output_path: PathBuf,
output_dir: PathBuf,
}

#[async_trait]
Expand All @@ -34,9 +34,9 @@ impl CliCommand<Vec<PathBuf>> for GenerateKeys {
}

async fn execute(self) -> CliTypedResult<Vec<PathBuf>> {
let account_key_path = self.output_path.join(ACCOUNT_KEY_FILE);
let consensus_key_path = self.output_path.join(CONSENSUS_KEY_FILE);
let network_key_path = self.output_path.join(NETWORK_KEY_FILE);
let account_key_path = self.output_dir.join(ACCOUNT_KEY_FILE);
let consensus_key_path = self.output_dir.join(CONSENSUS_KEY_FILE);
let network_key_path = self.output_dir.join(NETWORK_KEY_FILE);
let _ = key::GenerateKey::generate_ed25519(EncodingType::Hex, &account_key_path).await?;
let _ = key::GenerateKey::generate_ed25519(EncodingType::Hex, &consensus_key_path).await?;
let _ = key::GenerateKey::generate_x25519(EncodingType::Hex, &network_key_path).await?;
Expand All @@ -52,9 +52,9 @@ pub struct SetValidatorConfiguration {
username: String,
#[clap(flatten)]
git_options: GitOptions,
/// Path to credentials
/// Path to folder with account.key, consensus.key, and network.key
#[clap(long, parse(from_os_str), default_value = ".")]
credentials_path: PathBuf,
keys_dir: PathBuf,
/// Host and port pair for the validator e.g. 127.0.0.1:6180
#[clap(long)]
validator_host: HostAndPort,
Expand All @@ -70,9 +70,9 @@ impl CliCommand<()> for SetValidatorConfiguration {
}

async fn execute(self) -> CliTypedResult<()> {
let account_key_path = self.credentials_path.join(ACCOUNT_KEY_FILE);
let consensus_key_path = self.credentials_path.join(CONSENSUS_KEY_FILE);
let network_key_path = self.credentials_path.join(NETWORK_KEY_FILE);
let account_key_path = self.keys_dir.join(ACCOUNT_KEY_FILE);
let consensus_key_path = self.keys_dir.join(CONSENSUS_KEY_FILE);
let network_key_path = self.keys_dir.join(NETWORK_KEY_FILE);
let account_key: Ed25519PrivateKey =
EncodingType::Hex.load_key(ACCOUNT_KEY_FILE, &account_key_path)?;
let consensus_key: Ed25519PrivateKey =
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos/src/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn fetch_genesis_info(git_options: GitOptions) -> CliTypedResult<GenesisInfo
validators.push(client.get::<ValidatorConfiguration>(user)?.into());
}

let modules = client.get_modules(&layout.modules_folder)?;
let modules = client.get_modules(&layout.modules_dir)?;

Ok(GenesisInfo {
chain_id: layout.chain_id,
Expand Down

0 comments on commit 39852b1

Please sign in to comment.