Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deduplicate parsing of JSON ABI inputs #3022

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tooling/noirc_abi/src/input_parser/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(crate) fn serialize_to_json(

#[derive(Debug, Deserialize, Serialize, Clone)]
#[serde(untagged)]
pub(super) enum JsonTypes {
pub enum JsonTypes {
// This is most likely going to be a hex string
// But it is possible to support UTF-8
String(String),
Expand All @@ -78,7 +78,7 @@ pub(super) enum JsonTypes {
}

impl JsonTypes {
pub(super) fn try_from_input_value(
pub fn try_from_input_value(
value: &InputValue,
abi_type: &AbiType,
) -> Result<JsonTypes, InputParserError> {
Expand Down Expand Up @@ -133,7 +133,7 @@ impl JsonTypes {
}

impl InputValue {
fn try_from_json(
pub fn try_from_json(
value: JsonTypes,
param_type: &AbiType,
arg_name: &str,
Expand Down
2 changes: 1 addition & 1 deletion tooling/noirc_abi/src/input_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::Serialize;
use crate::errors::InputParserError;
use crate::{Abi, AbiType};

mod json;
pub mod json;
mod toml;

/// This is what all formats eventually transform into
Expand Down
12 changes: 7 additions & 5 deletions tooling/noirc_abi_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use getrandom as _;

use acvm::acir::native_types::WitnessMap;
use iter_extended::try_btree_map;
use noirc_abi::{errors::InputParserError, input_parser::InputValue, Abi, MAIN_RETURN_NAME};
use noirc_abi::{
errors::InputParserError,
input_parser::{json::JsonTypes, InputValue},
Abi, MAIN_RETURN_NAME,
};
use serde::Serialize;
use std::collections::BTreeMap;

Expand All @@ -16,11 +20,9 @@ use wasm_bindgen::{prelude::wasm_bindgen, JsValue};

mod errors;
mod js_witness_map;
mod temp;

use errors::JsAbiError;
use js_witness_map::JsWitnessMap;
use temp::{input_value_from_json_type, JsonTypes};

#[wasm_bindgen(typescript_custom_section)]
const INPUT_MAP: &'static str = r#"
Expand Down Expand Up @@ -92,7 +94,7 @@ pub fn abi_encode(
.map(|return_value| {
let toml_return_value = JsValueSerdeExt::into_serde(&JsValue::from(return_value))
.expect("could not decode return value");
input_value_from_json_type(
InputValue::try_from_json(
toml_return_value,
abi.return_type.as_ref().unwrap(),
MAIN_RETURN_NAME,
Expand All @@ -107,7 +109,7 @@ pub fn abi_encode(
let value = inputs
.get(&arg_name)
.ok_or_else(|| InputParserError::MissingArgument(arg_name.clone()))?;
input_value_from_json_type(value.clone(), &abi_type, &arg_name)
InputValue::try_from_json(value.clone(), &abi_type, &arg_name)
.map(|input_value| (arg_name, input_value))
})?;

Expand Down
136 changes: 0 additions & 136 deletions tooling/noirc_abi_wasm/src/temp.rs

This file was deleted.

Loading