Skip to content

Commit

Permalink
refactor and pass by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcusack committed Apr 4, 2024
1 parent 5fd3638 commit febf952
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
24 changes: 9 additions & 15 deletions src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Genesis {
}

impl Genesis {
pub fn new(solana_root: PathBuf) -> Self {
pub fn new(solana_root: &PathBuf) -> Self {
let config_dir = solana_root.join("config-k8s");
if config_dir.exists() {
std::fs::remove_dir_all(&config_dir).unwrap();
Expand Down Expand Up @@ -46,10 +46,7 @@ impl Genesis {
return Err("Client valdiator_type in generate_accounts not allowed".into());
}

info!(
"generating {} {} accounts...",
number_of_accounts, validator_type
);
info!("generating {number_of_accounts} {validator_type} accounts...");

let mut account_types = vec!["identity", "stake-account", "vote-account"];
match validator_type {
Expand All @@ -65,29 +62,26 @@ impl Genesis {
.key_generator
.gen_n_keypairs(total_accounts_to_generate as u64);

self.write_accounts_to_file(validator_type, account_types, keypairs)?;
self.write_accounts_to_file(&validator_type, &account_types, &keypairs)?;

Ok(())
}

fn write_accounts_to_file(
&self,
validator_type: ValidatorType,
account_types: Vec<&str>,
keypairs: Vec<Keypair>, //TODO: reference this
validator_type: &ValidatorType,
account_types: &Vec<&str>,
keypairs: &Vec<Keypair>,
) -> Result<(), Box<dyn Error>> {
for (i, keypair) in keypairs.iter().enumerate() {
let account_index = i / account_types.len();
let account = account_types[i % account_types.len()];
let filename = match validator_type {
ValidatorType::Bootstrap => {
format!("{}/{}.json", validator_type, account)
}
ValidatorType::Standard => {
format!("{}-{}-{}.json", validator_type, account, account_index)
format!("{validator_type}/{account}.json")
}
ValidatorType::RPC => {
format!("{}-{}-{}.json", validator_type, account, account_index)
ValidatorType::Standard | ValidatorType::RPC => {
format!("{validator_type}-{account}-{account_index}.json")
}
ValidatorType::Client => panic!("Client type not supported"),
};
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl SolanaRoot {
Self { root_path: path }
}

pub fn get_root_path(&self) -> PathBuf {
self.root_path.clone()
pub fn get_root_path(&self) -> &PathBuf {
&self.root_path
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ async fn main() {
return;
}
Err(err) => {
error!("Error: {}", err);
error!("Error: {err}");
return;
}
}

let build_config = BuildConfig::new(deploy_method, build_type, &solana_root.get_root_path())
let build_config = BuildConfig::new(deploy_method, build_type, solana_root.get_root_path())
.unwrap_or_else(|err| {
panic!("Error creating BuildConfig: {}", err);
panic!("Error creating BuildConfig: {err}");
});

match build_config.prepare().await {
Expand All @@ -128,15 +128,15 @@ async fn main() {
match genesis.generate_faucet() {
Ok(_) => (),
Err(err) => {
error!("generate faucet error! {}", err);
error!("generate faucet error! {err}");
return;
}
}

match genesis.generate_accounts(ValidatorType::Bootstrap, 1) {
Ok(_) => (),
Err(err) => {
error!("generate accounts error! {}", err);
error!("generate accounts error! {err}");
return;
}
}
Expand Down

0 comments on commit febf952

Please sign in to comment.