Skip to content

Commit

Permalink
fix: disable localhost wallets on external network interaction (#2212)
Browse files Browse the repository at this point in the history
## What ❔

- When adding an ecosystem or new chain, localhost wallets should not be
allowed to be selected.

## Why ❔

- Localhost are intended for local development.
<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.

Co-authored-by: Matías Ignacio González <[email protected]>
  • Loading branch information
aon and matias-gonz authored Jun 12, 2024
1 parent 2dcb566 commit a00317d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
22 changes: 18 additions & 4 deletions zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use common::{slugify, Prompt, PromptConfirm, PromptSelect};
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter};
use types::{BaseToken, L1BatchCommitDataGeneratorMode, ProverMode, WalletCreation};
use types::{BaseToken, L1BatchCommitDataGeneratorMode, L1Network, ProverMode, WalletCreation};

use crate::{
defaults::L2_CHAIN_ID,
Expand Down Expand Up @@ -47,7 +47,11 @@ pub struct ChainCreateArgs {
}

impl ChainCreateArgs {
pub fn fill_values_with_prompt(self, number_of_chains: u32) -> ChainCreateArgsFinal {
pub fn fill_values_with_prompt(
self,
number_of_chains: u32,
l1_network: &L1Network,
) -> ChainCreateArgsFinal {
let mut chain_name = self
.chain_name
.unwrap_or_else(|| Prompt::new(MSG_CHAIN_NAME_PROMPT).ask());
Expand All @@ -59,8 +63,18 @@ impl ChainCreateArgs {
.ask()
});

let wallet_creation =
PromptSelect::new(MSG_WALLET_CREATION_PROMPT, WalletCreation::iter()).ask();
let wallet_creation = PromptSelect::new(
MSG_WALLET_CREATION_PROMPT,
WalletCreation::iter().filter(|wallet| {
// Disable localhost wallets for external networks
if l1_network == &L1Network::Localhost {
true
} else {
wallet != &WalletCreation::Localhost
}
}),
)
.ask();

let prover_version = PromptSelect::new(MSG_PROVER_VERSION_PROMPT, ProverMode::iter()).ask();

Expand Down
5 changes: 4 additions & 1 deletion zk_toolbox/crates/zk_inception/src/commands/chain/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ fn create(
ecosystem_config: &mut EcosystemConfig,
shell: &Shell,
) -> anyhow::Result<()> {
let args = args.fill_values_with_prompt(ecosystem_config.list_of_chains().len() as u32);
let args = args.fill_values_with_prompt(
ecosystem_config.list_of_chains().len() as u32,
&ecosystem_config.l1_network,
);

logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&args));
logger::info(MSG_CREATING_CHAIN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl EcosystemCreateArgs {
// Make the only chain as a default one
self.chain.set_as_default = Some(true);

let chain = self.chain.fill_values_with_prompt(0);
let chain = self.chain.fill_values_with_prompt(0, &l1_network);

let start_containers = self.start_containers.unwrap_or_else(|| {
PromptConfirm::new(MSG_START_CONTAINERS_PROMPT)
Expand Down

0 comments on commit a00317d

Please sign in to comment.