Skip to content

Commit 3c384e1

Browse files
committed
Add the possibility to insert .args files for compiling complex contracts
1 parent 6bd62dc commit 3c384e1

1 file changed

Lines changed: 37 additions & 9 deletions

File tree

src/main.rs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use base64::display::Base64Display;
22
use base64::engine::general_purpose::STANDARD;
33
use clap::{Arg, ArgAction, Command};
44

5-
use simplicityhl::{Arguments, CompiledProgram};
5+
use simplicityhl::CompiledProgram;
66
use std::{env, fmt};
77

88
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
@@ -43,10 +43,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4343
)
4444
.arg(
4545
Arg::new("wit_file")
46+
.long("wit")
47+
.short('w')
4648
.value_name("WITNESS_FILE")
4749
.action(ArgAction::Set)
4850
.help("File containing the witness data"),
4951
)
52+
.arg(
53+
Arg::new("args_file")
54+
.long("args")
55+
.short('a')
56+
.value_name("ARGUMENTS_FILE")
57+
.action(ArgAction::Set)
58+
.help("File containing the arguments data"),
59+
)
5060
.arg(
5161
Arg::new("debug")
5262
.long("debug")
@@ -69,14 +79,32 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6979
let include_debug_symbols = matches.get_flag("debug");
7080
let output_json = matches.get_flag("json");
7181

72-
let compiled =
73-
match CompiledProgram::new(prog_text, Arguments::default(), include_debug_symbols) {
74-
Ok(program) => program,
75-
Err(e) => {
76-
eprintln!("{}", e);
77-
std::process::exit(1);
78-
}
79-
};
82+
#[cfg(feature = "serde")]
83+
let args_opt: simplicityhl::Arguments = match matches.get_one::<String>("args_file") {
84+
None => simplicityhl::Arguments::default(),
85+
Some(args_file) => {
86+
let args_path = std::path::Path::new(&args_file);
87+
let args_text = std::fs::read_to_string(args_path).map_err(|e| e.to_string())?;
88+
serde_json::from_str::<simplicityhl::Arguments>(&args_text)?
89+
}
90+
};
91+
#[cfg(not(feature = "serde"))]
92+
let args_opt: simplicityhl::Arguments = if matches.contains_id("args_file") {
93+
return Err(
94+
"Program was compiled without the 'serde' feature and cannot process .args files."
95+
.into(),
96+
);
97+
} else {
98+
simplicityhl::Arguments::default()
99+
};
100+
101+
let compiled = match CompiledProgram::new(prog_text, args_opt, include_debug_symbols) {
102+
Ok(program) => program,
103+
Err(e) => {
104+
eprintln!("{}", e);
105+
std::process::exit(1);
106+
}
107+
};
80108

81109
#[cfg(feature = "serde")]
82110
let witness_opt = matches

0 commit comments

Comments
 (0)