use maili_genesis::ChainConfig;
use maili_superchain::{Superchain, SuperchainConfig, Superchains};
fn main() {
let src_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let chain_list = format!("{}/superchain-registry/chainList.json", src_dir);
std::fs::copy(chain_list, "etc/chainList.json").unwrap();
let configs_dir = format!("{}/superchain-registry/superchain/configs", src_dir);
let configs = std::fs::read_dir(configs_dir).unwrap();
let mut superchains = Superchains::default();
for config in configs {
let config = config.unwrap();
let config_path = config.path();
let superchain_name = config.file_name().into_string().unwrap();
let mut superchain =
Superchain { name: superchain_name, chains: Vec::new(), ..Default::default() };
if config_path.is_dir() {
let config_files = std::fs::read_dir(&config_path).unwrap();
for config_file in config_files {
let config_file = config_file.unwrap();
let config_file_path = config_file.path();
let config_file_name = config_file.file_name().into_string().unwrap();
if config_file_name == "superchain.toml" {
let config = std::fs::read_to_string(config_file_path).unwrap();
let config: SuperchainConfig = toml::from_str(&config).unwrap();
superchain.config = config;
continue;
}
let config = std::fs::read_to_string(config_file_path).unwrap();
let config: ChainConfig = toml::from_str(&config).unwrap();
superchain.chains.push(config);
}
superchains.superchains.push(superchain);
}
}
std::fs::write("etc/configs.json", serde_json::to_string(&superchains).unwrap()).unwrap();
}