Skip to content

Commit

Permalink
Make wallets_path non optional
Browse files Browse the repository at this point in the history
  • Loading branch information
matias-gonz committed Nov 15, 2024
1 parent a42517c commit a43532f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ impl InitArgs {

let wallets_path = ecosystem.map_or_else(
|| {
self.wallets_path.map_or_else(
|| Prompt::new(MSG_WALLETS_PATH_PROMPT).allow_empty().ask(),
PathBuf::from,
)
self.wallets_path
.map_or_else(|| Prompt::new(MSG_WALLETS_PATH_PROMPT).ask(), PathBuf::from)
},
|e| e.get_wallets_path(),
);
Expand Down
15 changes: 5 additions & 10 deletions zkstack_cli/crates/zkstack/src/commands/chain/common.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
use anyhow::Context;
use common::spinner::Spinner;
use config::{ChainConfig, WalletsConfig};
use types::{BaseToken, L1Network, WalletCreation};

use crate::{
consts::AMOUNT_FOR_DISTRIBUTION_TO_WALLETS,
messages::{
MSG_DISTRIBUTING_ETH_SPINNER, MSG_MINT_BASE_TOKEN_SPINNER, MSG_MISSING_WALLETS_CONFIG,
},
messages::{MSG_DISTRIBUTING_ETH_SPINNER, MSG_MINT_BASE_TOKEN_SPINNER},
};

// Distribute eth to the chain wallets for localhost environment
pub async fn distribute_eth(
chain_config: &ChainConfig,
l1_rpc_url: String,
wallets: Option<WalletsConfig>,
wallets: &WalletsConfig,
) -> anyhow::Result<()> {
if chain_config.wallet_creation != WalletCreation::Localhost
|| chain_config.l1_network != L1Network::Localhost
Expand All @@ -23,7 +20,6 @@ pub async fn distribute_eth(
}

let spinner = Spinner::new(MSG_DISTRIBUTING_ETH_SPINNER);
let wallets = wallets.context(MSG_MISSING_WALLETS_CONFIG)?;
let chain_wallets = chain_config.get_wallets_config()?;
let mut addresses = vec![
chain_wallets.operator.address,
Expand All @@ -37,7 +33,7 @@ pub async fn distribute_eth(
addresses.push(setter.address);
}
common::ethereum::distribute_eth(
wallets.operator,
wallets.operator.clone(),
addresses,
l1_rpc_url,
chain_config.l1_network.chain_id(),
Expand All @@ -52,7 +48,7 @@ pub async fn distribute_eth(
pub async fn mint_base_token(
chain_config: &ChainConfig,
l1_rpc_url: String,
wallets: Option<WalletsConfig>,
wallets: &WalletsConfig,
) -> anyhow::Result<()> {
if chain_config.wallet_creation != WalletCreation::Localhost
|| chain_config.l1_network != L1Network::Localhost
Expand All @@ -62,14 +58,13 @@ pub async fn mint_base_token(
}

let spinner = Spinner::new(MSG_MINT_BASE_TOKEN_SPINNER);
let wallets = wallets.context(MSG_MISSING_WALLETS_CONFIG)?;
let chain_wallets = chain_config.get_wallets_config()?;
let base_token = &chain_config.base_token;
let addresses = vec![wallets.governor.address, chain_wallets.governor.address];
let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128
/ base_token.denominator as u128;
common::ethereum::mint_token(
wallets.governor,
wallets.governor.clone(),
base_token.address,
addresses,
l1_rpc_url,
Expand Down
6 changes: 3 additions & 3 deletions zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ pub async fn init(
let mut contracts_config = init_configs(&init_configs_args, shell, chain_config).await?;

// Fund some wallet addresses with ETH or base token (only for Localhost)
let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone()).ok();
distribute_eth(chain_config, init_args.l1_rpc_url.clone(), wallets.clone()).await?;
mint_base_token(chain_config, init_args.l1_rpc_url.clone(), wallets).await?;
let wallets = WalletsConfig::read(shell, init_args.wallets_path.clone())?;
distribute_eth(chain_config, init_args.l1_rpc_url.clone(), &wallets).await?;
mint_base_token(chain_config, init_args.l1_rpc_url.clone(), &wallets).await?;

// Register chain on BridgeHub (run by L1 Governor)
let spinner = Spinner::new(MSG_REGISTERING_CHAIN_SPINNER);
Expand Down
1 change: 0 additions & 1 deletion zkstack_cli/crates/zkstack/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ pub(super) const MSG_RECREATE_ROCKS_DB_ERRROR: &str = "Failed to create rocks db
pub(super) const MSG_ERA_OBSERVABILITY_ALREADY_SETUP: &str = "Era observability already setup";
pub(super) const MSG_DOWNLOADING_ERA_OBSERVABILITY_SPINNER: &str =
"Downloading era observability...";
pub(super) const MSG_MISSING_WALLETS_CONFIG: &str = "Missing wallets config";
pub(super) const MSG_WALLETS_PATH_PROMPT: &str = "Provide the path to the wallets";

pub(super) fn msg_ecosystem_no_found_preexisting_contract(chains: &str) -> String {
Expand Down

0 comments on commit a43532f

Please sign in to comment.