Skip to content

Commit

Permalink
chore: deduplicate parsing of JSON ABI inputs (#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Oct 12, 2023
1 parent fb3dd94 commit 7c43c4c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 145 deletions.
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.

0 comments on commit 7c43c4c

Please sign in to comment.