Skip to content

Commit

Permalink
Rename FileConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Jul 23, 2024
1 parent b13b8a3 commit 66a4681
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 56 deletions.
29 changes: 10 additions & 19 deletions zk_toolbox/crates/config/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ use std::{
use serde::{Deserialize, Serialize, Serializer};
use types::{BaseToken, ChainId, L1BatchCommitmentMode, L1Network, ProverMode, WalletCreation};
use xshell::Shell;
use zksync_config::configs::GeneralConfig as ZkSyncGeneralConfig;
use zksync_protobuf_config::encode_yaml_repr;

use crate::{
consts::{
CONFIG_NAME, CONTRACTS_FILE, GENERAL_FILE, GENESIS_FILE, L1_CONTRACTS_FOUNDRY,
SECRETS_FILE, WALLETS_FILE,
},
consts::{CONFIG_NAME, GENERAL_FILE, L1_CONTRACTS_FOUNDRY, SECRETS_FILE, WALLETS_FILE},
create_localhost_wallets,
traits::{
FileConfig, FileConfigWithDefaultName, ReadConfig, SaveConfig, SaveConfigWithBasePath,
FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig,
SaveConfigWithBasePath, ZkToolboxConfig,
},
ContractsConfig, GeneralConfig, GenesisConfig, SecretsConfig, WalletsConfig,
};
Expand Down Expand Up @@ -73,11 +69,11 @@ impl ChainConfig {
}

pub fn get_genesis_config(&self) -> anyhow::Result<GenesisConfig> {
GenesisConfig::read(self.get_shell(), self.configs.join(GENESIS_FILE))
GenesisConfig::read_with_base_path(self.get_shell(), &self.configs)
}

pub fn get_general_config(&self) -> anyhow::Result<GeneralConfig> {
GeneralConfig::read(self.get_shell(), self.configs.join(GENERAL_FILE))
GeneralConfig::read_with_base_path(self.get_shell(), &self.configs)
}

pub fn get_wallets_config(&self) -> anyhow::Result<WalletsConfig> {
Expand All @@ -93,11 +89,11 @@ impl ChainConfig {
anyhow::bail!("Wallets configs has not been found");
}
pub fn get_contracts_config(&self) -> anyhow::Result<ContractsConfig> {
ContractsConfig::read(self.get_shell(), self.configs.join(CONTRACTS_FILE))
ContractsConfig::read_with_base_path(self.get_shell(), &self.configs)
}

pub fn get_secrets_config(&self) -> anyhow::Result<SecretsConfig> {
SecretsConfig::read(self.get_shell(), self.configs.join(SECRETS_FILE))
SecretsConfig::read_with_base_path(self.get_shell(), &self.configs)
}

pub fn path_to_general_config(&self) -> PathBuf {
Expand All @@ -108,13 +104,8 @@ impl ChainConfig {
self.configs.join(SECRETS_FILE)
}

pub fn save_general_config(&self, general_config: &ZkSyncGeneralConfig) -> anyhow::Result<()> {
let path = self.configs.join(GENERAL_FILE);
let bytes = encode_yaml_repr::<zksync_protobuf_config::proto::general::GeneralConfig>(
general_config,
)?;
self.get_shell().write_file(path, bytes)?;
Ok(())
pub fn save_general_config(&self, general_config: &GeneralConfig) -> anyhow::Result<()> {
general_config.save_with_base_path(self.get_shell(), &self.configs)
}

pub fn path_to_foundry(&self) -> PathBuf {
Expand Down Expand Up @@ -151,4 +142,4 @@ impl FileConfigWithDefaultName for ChainConfigInternal {
const FILE_NAME: &'static str = CONFIG_NAME;
}

impl FileConfig for ChainConfigInternal {}
impl ZkToolboxConfig for ChainConfigInternal {}
6 changes: 3 additions & 3 deletions zk_toolbox/crates/config/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
initialize_bridges::output::InitializeBridgeOutput,
register_chain::output::RegisterChainOutput,
},
traits::{FileConfig, FileConfigWithDefaultName},
traits::{FileConfigWithDefaultName, ZkToolboxConfig},
};

#[derive(Debug, Deserialize, Serialize, Clone, Default)]
Expand Down Expand Up @@ -89,7 +89,7 @@ impl FileConfigWithDefaultName for ContractsConfig {
const FILE_NAME: &'static str = CONTRACTS_FILE;
}

impl FileConfig for ContractsConfig {}
impl ZkToolboxConfig for ContractsConfig {}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct EcosystemContracts {
Expand All @@ -100,7 +100,7 @@ pub struct EcosystemContracts {
pub diamond_cut_data: String,
}

impl FileConfig for EcosystemContracts {}
impl ZkToolboxConfig for EcosystemContracts {}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct BridgesContracts {
Expand Down
6 changes: 3 additions & 3 deletions zk_toolbox/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
},
create_localhost_wallets,
forge_interface::deploy_ecosystem::input::{Erc20DeploymentConfig, InitialDeploymentConfig},
traits::{FileConfig, FileConfigWithDefaultName, ReadConfig, SaveConfig},
traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkToolboxConfig},
ChainConfig, ChainConfigInternal, ContractsConfig, WalletsConfig,
};

Expand Down Expand Up @@ -90,9 +90,9 @@ impl FileConfigWithDefaultName for EcosystemConfig {
const FILE_NAME: &'static str = CONFIG_NAME;
}

impl FileConfig for EcosystemConfigInternal {}
impl ZkToolboxConfig for EcosystemConfigInternal {}

impl FileConfig for EcosystemConfig {}
impl ZkToolboxConfig for EcosystemConfig {}

impl EcosystemConfig {
fn get_shell(&self) -> &Shell {
Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/config/src/external_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use types::{ChainId, L1BatchCommitmentMode};

use crate::{
consts::EN_CONFIG_FILE,
traits::{FileConfig, FileConfigWithDefaultName},
traits::{FileConfigWithDefaultName, ZkToolboxConfig},
};

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
Expand All @@ -25,4 +25,4 @@ impl FileConfigWithDefaultName for ENConfig {
const FILE_NAME: &'static str = EN_CONFIG_FILE;
}

impl FileConfig for ENConfig {}
impl ZkToolboxConfig for ENConfig {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use ethers::types::Address;
use serde::{Deserialize, Serialize};

use crate::traits::FileConfig;
use crate::traits::ZkToolboxConfig;

impl FileConfig for AcceptOwnershipInput {}
impl ZkToolboxConfig for AcceptOwnershipInput {}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AcceptOwnershipInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use types::ChainId;

use crate::{
consts::INITIAL_DEPLOYMENT_FILE,
traits::{FileConfig, FileConfigWithDefaultName},
traits::{FileConfigWithDefaultName, ZkToolboxConfig},
ContractsConfig, GenesisConfig, WalletsConfig,
};

Expand Down Expand Up @@ -61,7 +61,7 @@ impl FileConfigWithDefaultName for InitialDeploymentConfig {
const FILE_NAME: &'static str = INITIAL_DEPLOYMENT_FILE;
}

impl FileConfig for InitialDeploymentConfig {}
impl ZkToolboxConfig for InitialDeploymentConfig {}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Erc20DeploymentConfig {
Expand All @@ -72,7 +72,7 @@ impl FileConfigWithDefaultName for Erc20DeploymentConfig {
const FILE_NAME: &'static str = INITIAL_DEPLOYMENT_FILE;
}

impl FileConfig for Erc20DeploymentConfig {}
impl ZkToolboxConfig for Erc20DeploymentConfig {}

impl Default for Erc20DeploymentConfig {
fn default() -> Self {
Expand Down Expand Up @@ -122,7 +122,7 @@ pub struct DeployL1Config {
pub tokens: TokensDeployL1Config,
}

impl FileConfig for DeployL1Config {}
impl ZkToolboxConfig for DeployL1Config {}

impl DeployL1Config {
pub fn new(
Expand Down Expand Up @@ -216,7 +216,7 @@ pub struct DeployErc20Config {
pub additional_addresses_for_minting: Vec<Address>,
}

impl FileConfig for DeployErc20Config {}
impl ZkToolboxConfig for DeployErc20Config {}

impl DeployErc20Config {
pub fn new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};

use crate::{
consts::ERC20_CONFIGS_FILE,
traits::{FileConfig, FileConfigWithDefaultName},
traits::{FileConfigWithDefaultName, ZkToolboxConfig},
};

#[derive(Debug, Deserialize, Serialize, Clone)]
Expand All @@ -21,7 +21,7 @@ pub struct DeployL1Output {
pub deployed_addresses: DeployL1DeployedAddressesOutput,
}

impl FileConfig for DeployL1Output {}
impl ZkToolboxConfig for DeployL1Output {}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct DeployL1ContractsConfigOutput {
Expand Down Expand Up @@ -97,4 +97,4 @@ impl FileConfigWithDefaultName for DeployErc20Output {
const FILE_NAME: &'static str = ERC20_CONFIGS_FILE;
}

impl FileConfig for DeployErc20Output {}
impl ZkToolboxConfig for DeployErc20Output {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use ethers::types::Address;
use serde::{Deserialize, Serialize};
use types::ChainId;

use crate::{traits::FileConfig, ChainConfig};
use crate::{traits::ZkToolboxConfig, ChainConfig};

impl FileConfig for InitializeBridgeInput {}
impl ZkToolboxConfig for InitializeBridgeInput {}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InitializeBridgeInput {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use ethers::types::Address;
use serde::{Deserialize, Serialize};

use crate::traits::FileConfig;
use crate::traits::ZkToolboxConfig;

impl FileConfig for InitializeBridgeOutput {}
impl ZkToolboxConfig for InitializeBridgeOutput {}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InitializeBridgeOutput {
Expand Down
7 changes: 4 additions & 3 deletions zk_toolbox/crates/config/src/forge_interface/paymaster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ethers::types::Address;
use serde::{Deserialize, Serialize};
use types::ChainId;

use crate::{traits::FileConfig, ChainConfig};
use crate::{traits::ZkToolboxConfig, ChainConfig};

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DeployPaymasterInput {
Expand All @@ -21,11 +21,12 @@ impl DeployPaymasterInput {
})
}
}
impl FileConfig for DeployPaymasterInput {}

impl ZkToolboxConfig for DeployPaymasterInput {}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DeployPaymasterOutput {
pub paymaster: Address,
}

impl FileConfig for DeployPaymasterOutput {}
impl ZkToolboxConfig for DeployPaymasterOutput {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rand::Rng;
use serde::{Deserialize, Serialize};
use types::{ChainId, L1BatchCommitmentMode};

use crate::{traits::FileConfig, ChainConfig, ContractsConfig};
use crate::{traits::ZkToolboxConfig, ChainConfig, ContractsConfig};

#[derive(Debug, Deserialize, Serialize, Clone)]
struct Bridgehub {
Expand Down Expand Up @@ -49,7 +49,7 @@ pub struct ChainL1Config {
pub governance_min_delay: u64,
}

impl FileConfig for RegisterChainL1Config {}
impl ZkToolboxConfig for RegisterChainL1Config {}

impl RegisterChainL1Config {
pub fn new(chain_config: &ChainConfig, contracts: &ContractsConfig) -> anyhow::Result<Self> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ethers::types::Address;
use serde::{Deserialize, Serialize};

use crate::traits::FileConfig;
use crate::traits::ZkToolboxConfig;

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct RegisterChainOutput {
Expand All @@ -10,4 +10,4 @@ pub struct RegisterChainOutput {
pub chain_admin_addr: Address,
}

impl FileConfig for RegisterChainOutput {}
impl ZkToolboxConfig for RegisterChainOutput {}
7 changes: 4 additions & 3 deletions zk_toolbox/crates/config/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use common::files::{
use serde::{de::DeserializeOwned, Serialize};
use xshell::Shell;

pub trait FileConfig {}
// Configs that we use only inside zk toolbox, we don't have protobuf implementation for them.
pub trait ZkToolboxConfig {}

pub trait FileConfigWithDefaultName {
const FILE_NAME: &'static str;
Expand All @@ -17,7 +18,7 @@ pub trait FileConfigWithDefaultName {
}
}

impl<T: Serialize + FileConfig> SaveConfig for T {
impl<T: Serialize + ZkToolboxConfig> SaveConfig for T {
fn save(&self, shell: &Shell, path: impl AsRef<Path>) -> anyhow::Result<()> {
save_with_comment(shell, path, &self, "")
}
Expand Down Expand Up @@ -47,7 +48,7 @@ pub trait ReadConfig: Sized {

impl<T> ReadConfig for T
where
T: DeserializeOwned + Clone + FileConfig,
T: DeserializeOwned + Clone + ZkToolboxConfig,
{
fn read(shell: &Shell, path: impl AsRef<Path>) -> anyhow::Result<Self> {
let error_context = || format!("Failed to parse config file {:?}.", path.as_ref());
Expand Down
6 changes: 3 additions & 3 deletions zk_toolbox/crates/config/src/wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};

use crate::{
consts::WALLETS_FILE,
traits::{FileConfig, FileConfigWithDefaultName},
traits::{FileConfigWithDefaultName, ZkToolboxConfig},
};

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -60,6 +60,6 @@ pub(crate) struct EthMnemonicConfig {
pub(crate) base_path: String,
}

impl FileConfig for EthMnemonicConfig {}
impl ZkToolboxConfig for EthMnemonicConfig {}

impl FileConfig for WalletsConfig {}
impl ZkToolboxConfig for WalletsConfig {}
2 changes: 1 addition & 1 deletion zk_toolbox/crates/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ ethers.workspace = true
serde.workspace = true
strum.workspace = true
thiserror.workspace = true
zksync_basic_types.workspace = true
zksync_basic_types.workspace = true
2 changes: 1 addition & 1 deletion zk_toolbox/crates/zk_inception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ url.workspace = true
thiserror.workspace = true
zksync_config.workspace = true
slugify-rs.workspace = true
zksync_basic_types.workspace = true
zksync_basic_types.workspace = true

0 comments on commit 66a4681

Please sign in to comment.