From c09b5ed76589936fcfc130cb86b64d3e0709255a Mon Sep 17 00:00:00 2001 From: Illia Kripaka Date: Fri, 30 Jan 2026 21:47:33 +0200 Subject: [PATCH] Add the possibility to insert .args files for compiling complex contracts --- src/main.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1135a31..0aa8256 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use base64::display::Base64Display; use base64::engine::general_purpose::STANDARD; use clap::{Arg, ArgAction, Command}; -use simplicityhl::{Arguments, CompiledProgram}; +use simplicityhl::CompiledProgram; use std::{env, fmt}; #[cfg_attr(feature = "serde", derive(serde::Serialize))] @@ -43,10 +43,20 @@ fn main() -> Result<(), Box> { ) .arg( Arg::new("wit_file") + .long("wit") + .short('w') .value_name("WITNESS_FILE") .action(ArgAction::Set) .help("File containing the witness data"), ) + .arg( + Arg::new("args_file") + .long("args") + .short('a') + .value_name("ARGUMENTS_FILE") + .action(ArgAction::Set) + .help("File containing the arguments data"), + ) .arg( Arg::new("debug") .long("debug") @@ -69,8 +79,26 @@ fn main() -> Result<(), Box> { let include_debug_symbols = matches.get_flag("debug"); let output_json = matches.get_flag("json"); - let compiled = CompiledProgram::new(prog_text, Arguments::default(), include_debug_symbols)?; + #[cfg(feature = "serde")] + let args_opt: simplicityhl::Arguments = match matches.get_one::("args_file") { + None => simplicityhl::Arguments::default(), + Some(args_file) => { + let args_path = std::path::Path::new(&args_file); + let args_text = std::fs::read_to_string(args_path).map_err(|e| e.to_string())?; + serde_json::from_str::(&args_text)? + } + }; + #[cfg(not(feature = "serde"))] + let args_opt: simplicityhl::Arguments = if matches.contains_id("args_file") { + return Err( + "Program was compiled without the 'serde' feature and cannot process .args files." + .into(), + ); + } else { + simplicityhl::Arguments::default() + }; + let compiled = CompiledProgram::new(prog_text, args_opt, include_debug_symbols)?; #[cfg(feature = "serde")] let witness_opt = matches .get_one::("wit_file")