Skip to main content

fhevm_forge/
config.rs

1use anyhow::Result;
2use serde::{Deserialize, Serialize};
3use std::fs;
4
5#[derive(Debug, Default, Deserialize, Serialize)]
6pub struct FhevmForgeConfig {
7    #[serde(default)]
8    pub deploy: DeployConfig,
9
10    #[serde(default)]
11    pub lint: LintConfig,
12
13    #[serde(default)]
14    pub gas: GasConfig,
15}
16
17#[derive(Debug, Default, Deserialize, Serialize)]
18pub struct DeployConfig {
19    #[serde(default)]
20    pub chains: Vec<String>,
21    pub default_contract: Option<String>,
22}
23
24#[derive(Debug, Default, Deserialize, Serialize)]
25pub struct LintConfig {
26    #[serde(default)]
27    pub ignore: Vec<String>,
28}
29
30#[derive(Debug, Default, Deserialize, Serialize)]
31pub struct GasConfig {
32    pub output: Option<Vec<String>>,
33    pub json_path: Option<String>,
34    pub warn_if_coprocessor_gas_exceeds: Option<u64>,
35}
36
37impl FhevmForgeConfig {
38    pub fn load() -> Result<Self> {
39        let path = "fhevm-forge.toml";
40        if !std::path::Path::new(path).exists() {
41            return Ok(Self::default());
42        }
43        let contents = fs::read_to_string(path)?;
44        let config: FhevmForgeConfig = toml::from_str(&contents)?;
45        Ok(config)
46    }
47}