eval with inputs (#56)
This commit is contained in:
@@ -39,9 +39,11 @@ pub enum UplcCommand {
|
||||
},
|
||||
/// Evaluate an Untyped Plutus Core program
|
||||
Eval {
|
||||
input: PathBuf,
|
||||
script: PathBuf,
|
||||
#[clap(short, long)]
|
||||
flat: bool,
|
||||
/// Arguments to pass to the uplc program
|
||||
args: Vec<String>,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -82,21 +82,28 @@ fn main() -> anyhow::Result<()> {
|
||||
fs::write(&out_name, pretty)?;
|
||||
}
|
||||
}
|
||||
UplcCommand::Eval { input, flat } => {
|
||||
let program = if flat {
|
||||
let bytes = std::fs::read(&input)?;
|
||||
|
||||
UplcCommand::Eval { script, flat, args } => {
|
||||
let mut program = if flat {
|
||||
let bytes = std::fs::read(&script)?;
|
||||
|
||||
let prog = Program::<FakeNamedDeBruijn>::from_flat(&bytes)?;
|
||||
|
||||
prog.into()
|
||||
} else {
|
||||
let code = std::fs::read_to_string(&input)?;
|
||||
let code = std::fs::read_to_string(&script)?;
|
||||
|
||||
let prog = parser::program(&code)?;
|
||||
|
||||
Program::<NamedDeBruijn>::try_from(prog)?
|
||||
};
|
||||
|
||||
for arg in args {
|
||||
let term: Term<NamedDeBruijn> = parser::term(&arg)?.try_into()?;
|
||||
|
||||
program = program.apply_term(&term);
|
||||
}
|
||||
|
||||
let (term, cost, logs) = program.eval();
|
||||
|
||||
match term {
|
||||
@@ -121,7 +128,10 @@ fn main() -> anyhow::Result<()> {
|
||||
"\nBudget\n------\ncpu: {}\nmemory: {}\n",
|
||||
cost.cpu, cost.mem
|
||||
);
|
||||
println!("\nLogs\n----\n{}", logs.join("\n"))
|
||||
|
||||
if !logs.is_empty() {
|
||||
println!("\nLogs\n----\n{}", logs.join("\n"))
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user