From a43532f46870f0af058c12a77e1f66c13b9d27db Mon Sep 17 00:00:00 2001 From: matias-gonz Date: Fri, 15 Nov 2024 14:02:46 -0300 Subject: [PATCH] Make wallets_path non optional --- .../zkstack/src/commands/chain/args/init/mod.rs | 6 ++---- .../crates/zkstack/src/commands/chain/common.rs | 15 +++++---------- .../crates/zkstack/src/commands/chain/init/mod.rs | 6 +++--- zkstack_cli/crates/zkstack/src/messages.rs | 1 - 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs index f2c8444fd29..84e7d71bc8a 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs @@ -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(), ); diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs index 0b41ab5b552..c14e140679c 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/common.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/common.rs @@ -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, + wallets: &WalletsConfig, ) -> anyhow::Result<()> { if chain_config.wallet_creation != WalletCreation::Localhost || chain_config.l1_network != L1Network::Localhost @@ -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, @@ -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(), @@ -52,7 +48,7 @@ pub async fn distribute_eth( pub async fn mint_base_token( chain_config: &ChainConfig, l1_rpc_url: String, - wallets: Option, + wallets: &WalletsConfig, ) -> anyhow::Result<()> { if chain_config.wallet_creation != WalletCreation::Localhost || chain_config.l1_network != L1Network::Localhost @@ -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, diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs index 145c442aa8b..10e4a40de33 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -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); diff --git a/zkstack_cli/crates/zkstack/src/messages.rs b/zkstack_cli/crates/zkstack/src/messages.rs index 29f1b9e193f..59ac3b0970d 100644 --- a/zkstack_cli/crates/zkstack/src/messages.rs +++ b/zkstack_cli/crates/zkstack/src/messages.rs @@ -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 {