From a05c41b595b9048289e18ab15cbd624646842d35 Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Tue, 10 Sep 2024 14:32:23 -0600 Subject: [PATCH] more refactor --- src/http.rs | 8 ++++---- src/json.rs | 12 +++++++++--- src/main.rs | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/http.rs b/src/http.rs index 6e065df..5470446 100644 --- a/src/http.rs +++ b/src/http.rs @@ -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> { let mut circuit_buffer = String::new(); @@ -391,12 +391,12 @@ fn locker_circuit( } // TODO: This needs to codegen a circuit now. -pub fn http_lock(args: HttpArgs) -> Result<(), Box> { +pub fn http_circuit(args: HttpArgs) -> Result<(), Box> { 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(()) } diff --git a/src/json.rs b/src/json.rs index 5ef5f16..d6a375f 100644 --- a/src/json.rs +++ b/src/json.rs @@ -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> { 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"; @@ -510,11 +516,11 @@ fn parse_json_request( Ok(()) } -pub fn extractor(args: JsonArgs) -> Result<(), Box> { +pub fn json_circuit(args: JsonArgs) -> Result<(), Box> { 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(()) } diff --git a/src/main.rs b/src/main.rs index 0ff3e54..1ffbddb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ pub struct HttpArgs { pub fn main() -> Result<(), Box> { 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), } }