Skip to content

Commit

Permalink
refactor: update deprecated to_serde/from_serde (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Dec 30, 2022
1 parent 2fdd4f7 commit b40e2c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ noirc_driver = { path = "../noirc_driver", features = ["wasm"] }
console_error_panic_hook = "*"

wasm-bindgen = { version = "*", features = ["serde-serialize"] }
gloo-utils = { version = "0.1", features = ["serde"] }

getrandom = { version = "0.2.4", features = ["js"] }
js-sys = "0.3.55"
Expand Down
7 changes: 4 additions & 3 deletions crates/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use acvm::acir::circuit::Circuit;
use gloo_utils::format::JsValueSerdeExt;
use std::path::PathBuf;
use wasm_bindgen::prelude::*;

Expand All @@ -10,19 +11,19 @@ pub fn compile(src: String) -> JsValue {
let language = acvm::Language::PLONKCSat { width: 3 };
let path = PathBuf::from(src);
let compiled_program = noirc_driver::Driver::compile_file(path, language);
JsValue::from_serde(&compiled_program).unwrap()
<JsValue as JsValueSerdeExt>::from_serde(&compiled_program).unwrap()
}
// Deserialises bytes into ACIR structure
#[wasm_bindgen]
pub fn acir_from_bytes(bytes: Vec<u8>) -> JsValue {
console_error_panic_hook::set_once();
let circuit = Circuit::from_bytes(&bytes);
JsValue::from_serde(&circuit).unwrap()
<JsValue as JsValueSerdeExt>::from_serde(&circuit).unwrap()
}

#[wasm_bindgen]
pub fn acir_to_bytes(acir: JsValue) -> Vec<u8> {
console_error_panic_hook::set_once();
let circuit: Circuit = acir.into_serde().unwrap();
let circuit: Circuit = JsValueSerdeExt::into_serde(&acir).unwrap();
circuit.to_bytes()
}

0 comments on commit b40e2c8

Please sign in to comment.