2020-06-16 12:08:42 +00:00
|
|
|
use ethers::{contract::Abigen, utils::Solc};
|
|
|
|
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
|
|
let mut args = std::env::args();
|
|
|
|
args.next().unwrap(); // skip program name
|
|
|
|
|
2021-08-30 11:00:30 +00:00
|
|
|
let contract_name = args.next().unwrap_or("SimpleStorage".to_owned());
|
|
|
|
let contract: String = args.next().unwrap_or("examples/contract.sol".to_owned());
|
2020-06-16 12:08:42 +00:00
|
|
|
|
|
|
|
println!("Generating bindings for {}\n", contract);
|
|
|
|
|
|
|
|
// compile it if needed
|
|
|
|
let abi = if contract.ends_with(".sol") {
|
|
|
|
let contracts = Solc::new(&contract).build_raw()?;
|
|
|
|
contracts.get(&contract_name).unwrap().abi.clone()
|
|
|
|
} else {
|
|
|
|
contract
|
|
|
|
};
|
|
|
|
|
|
|
|
let bindings = Abigen::new(&contract_name, abi)?.generate()?;
|
|
|
|
|
|
|
|
// print to stdout if no output arg is given
|
|
|
|
if let Some(output_path) = args.next() {
|
|
|
|
bindings.write_to_file(&output_path)?;
|
|
|
|
} else {
|
|
|
|
bindings.write(std::io::stdout())?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|