use anyhow::Result;
use std::fs;
use std::path::PathBuf;
use substreams_ethereum::Abigen;
use walkdir::WalkDir;
fn main() -> Result<()> {
let out_base = PathBuf::from("./src");
for entry in WalkDir::new("./abi").into_iter().filter_map(|e| e.ok()) {
let json_path = entry.path();
if json_path.is_file() && json_path.extension().and_then(|ext| ext.to_str()) == Some("json")
{
let contract_name = json_path
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("unknown_contract")
.to_lowercase();
let relative_path = json_path.strip_prefix("./abi")?;
let mut output_path = out_base.join(relative_path);
output_path.set_file_name(format!("{}.rs", contract_name));
if let Some(parent) = output_path.parent() {
fs::create_dir_all(parent)?;
}
Abigen::new(&contract_name, &json_path.to_string_lossy().to_string())?
.generate()?
.write_to_file(output_path)?;
}
}
Ok(())
}