Skip to content

Commit

Permalink
feat(zk_toolbox): Dev command (#2347)
Browse files Browse the repository at this point in the history
## What ❔

Shortcut for developers, for not answering all questions 

## Why ❔

<!-- 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. -->

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

Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Jun 28, 2024
1 parent 3a8fed4 commit f508ac1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
48 changes: 32 additions & 16 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
defaults::LOCAL_RPC_URL,
messages::{
MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_DEPLOY_ERC20_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT,
MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR,
MSG_DEV_ARG_HELP, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR,
MSG_L1_RPC_URL_PROMPT,
},
};
Expand All @@ -29,15 +29,22 @@ pub struct EcosystemArgs {
}

impl EcosystemArgs {
pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemArgsFinal {
pub fn fill_values_with_prompt(self, l1_network: L1Network, dev: bool) -> EcosystemArgsFinal {
let deploy_ecosystem = self.deploy_ecosystem.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT)
.default(true)
.ask()
if dev {
return true;
} else {
PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT)
.default(true)
.ask()
}
});

let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| {
let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT);
if dev {
return LOCAL_RPC_URL.to_string();
}
if l1_network == L1Network::Localhost {
prompt = prompt.default(LOCAL_RPC_URL);
}
Expand Down Expand Up @@ -81,27 +88,35 @@ pub struct EcosystemInitArgs {
#[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)]
#[serde(flatten)]
pub genesis_args: GenesisArgs,
#[clap(long, help = MSG_DEV_ARG_HELP)]
pub dev: bool,
}

impl EcosystemInitArgs {
pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemInitArgsFinal {
let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT)
.default(true)
.ask()
});
let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_ERC20_PROMPT)
.default(true)
.ask()
});
let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network);
let (deploy_paymaster, deploy_erc20) = if self.dev {
(true, true)
} else {
let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT)
.default(true)
.ask()
});
let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| {
PromptConfirm::new(MSG_DEPLOY_ERC20_PROMPT)
.default(true)
.ask()
});
(deploy_paymaster, deploy_erc20)
};
let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network, self.dev);

EcosystemInitArgsFinal {
deploy_paymaster,
deploy_erc20,
ecosystem,
forge_args: self.forge_args.clone(),
dev: self.dev,
}
}
}
Expand All @@ -112,4 +127,5 @@ pub struct EcosystemInitArgsFinal {
pub deploy_erc20: bool,
pub ecosystem: EcosystemArgsFinal,
pub forge_args: ForgeScriptArgs,
pub dev: bool,
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> {
Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?,
};

let genesis_args = args.genesis_args.clone();
let mut genesis_args = args.genesis_args.clone();
if args.dev {
genesis_args.use_default = true;
}
let mut final_ecosystem_args = args.fill_values_with_prompt(ecosystem_config.l1_network);

logger::info(MSG_INITIALIZING_ECOSYSTEM);
Expand Down
2 changes: 2 additions & 0 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub(super) const MSG_LINK_TO_CODE_SELECTION_PATH: &str = "I have the code alread
/// Ecosystem and chain init related messages
pub(super) const MSG_L1_RPC_URL_HELP: &str = "L1 RPC URL";
pub(super) const MSG_GENESIS_ARGS_HELP: &str = "Genesis options";
pub(super) const MSG_DEV_ARG_HELP: &str =
"Deploy ecosystem using all defaults. Suitable for local development";
pub(super) const MSG_DEPLOY_ECOSYSTEM_PROMPT: &str =
"Do you want to deploy ecosystem contracts? (Not needed if you already have an existing one)";
pub(super) const MSG_L1_RPC_URL_PROMPT: &str = "What is the RPC URL of the L1 network?";
Expand Down

0 comments on commit f508ac1

Please sign in to comment.