1pub mod primitivies;
3pub mod utils;
4
5use colored::Colorize;
6use indicatif::ProgressBar;
7use primitivies::Contract;
8use std::{fs, path::Path};
9use tracing::info;
10use utils::obtain_contract_by_path;
11
12pub fn run_contract_compilation(
14 contract_root: &Path,
15 is_check: bool,
16 pb: ProgressBar,
17 out: String,
18) -> Result<(), anyhow::Error> {
19 let output_dir = contract_root.join("out");
20 fs::create_dir_all(&output_dir)?;
21
22 let contract: Contract = obtain_contract_by_path(contract_root)
23 .ok_or(anyhow::anyhow!("contract fetch by path error"))?
24 .into();
25
26 info!("Compiling contract: {}", contract.name.ident);
27
28 let deploy_bytecode = contract.compile_r55()?;
29 let deploy_path = output_dir.join(format!("{}.bin", contract.name.package));
30
31 if is_check {
32 pb.finish_with_message("Contract check completed successfully!".green().to_string());
33 println!("\n✅ {}\n", "Contract syntax check passed!".green().bold());
34 } else {
35 fs::write(deploy_path, deploy_bytecode)?;
36 pb.finish_with_message("Contract build completed successfully!".green().to_string());
37 println!(
38 "\n✅ {} to {}\n",
39 "Contract built successfully".green().bold(),
40 out.cyan()
41 );
42 }
43
44 Ok(())
45}