Skip to content

Commit

Permalink
more refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Sep 10, 2024
1 parent 0805aa5 commit a05c41b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ where

const PRAGMA: &str = "pragma circom 2.1.9;\n\n";

fn locker_circuit(
fn build_http_circuit(
data: HttpData,
debug: bool,
output_filename: String,
debug: bool,
) -> Result<(), Box<dyn std::error::Error>> {
let mut circuit_buffer = String::new();

Expand Down Expand Up @@ -391,12 +391,12 @@ fn locker_circuit(
}

// TODO: This needs to codegen a circuit now.
pub fn http_lock(args: HttpArgs) -> Result<(), Box<dyn Error>> {
pub fn http_circuit(args: HttpArgs) -> Result<(), Box<dyn Error>> {
let data = std::fs::read(&args.lockfile)?;

let http_data: HttpData = serde_json::from_slice(&data)?;

locker_circuit(http_data, args.debug, args.output_filename)?;
build_http_circuit(http_data, args.output_filename, args.debug)?;

Ok(())
}
12 changes: 9 additions & 3 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,18 @@ fn extract_number(data: Data, circuit_buffer: &mut String) {
"#;
}

fn parse_json_request(
fn build_json_circuit(
data: Data,
output_filename: String,
debug: bool,
) -> Result<(), Box<dyn std::error::Error>> {
let mut circuit_buffer = String::new();

// Dump out the contents of the lockfile used into the circuit
circuit_buffer += "/*\n";
circuit_buffer += &format!("{:#?}", data);
circuit_buffer += "\n*/\n";

circuit_buffer += PRAGMA;
circuit_buffer += "include \"../json/interpreter.circom\";\n\n";

Expand Down Expand Up @@ -510,11 +516,11 @@ fn parse_json_request(
Ok(())
}

pub fn extractor(args: JsonArgs) -> Result<(), Box<dyn std::error::Error>> {
pub fn json_circuit(args: JsonArgs) -> Result<(), Box<dyn std::error::Error>> {
let data = std::fs::read(&args.template)?;
let json_data: Data = serde_json::from_slice(&data)?;

parse_json_request(json_data, args.output_filename, args.debug)?;
build_json_circuit(json_data, args.output_filename, args.debug)?;

Ok(())
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct HttpArgs {
pub fn main() -> Result<(), Box<dyn Error>> {
match Args::parse().command {
Command::Witness(args) => witness::witness(args),
Command::Json(args) => json::extractor(args),
Command::Http(args) => http::http_lock(args),
Command::Json(args) => json::json_circuit(args),
Command::Http(args) => http::http_circuit(args),
}
}

0 comments on commit a05c41b

Please sign in to comment.