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

feat(json-abi): permit keyword prefixes in HR parser #420

Merged
merged 2 commits into from
Nov 18, 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
4 changes: 2 additions & 2 deletions crates/dyn-abi/src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ type Flat<S, T> = Flatten<StratMap<S, T>>;
type Rec<T, S> = Recursive<T, fn(BoxedStrategy<T>) -> S>;

#[cfg(feature = "eip712")]
const IDENT_STRATEGY: &str = alloy_sol_type_parser::IDENT_REGEX;
const IDENT_STRATEGY: &str = parser::IDENT_REGEX;
#[cfg(feature = "eip712")]
type CustomStructStrategy<T> = BoxedStrategy<T>;

Expand Down Expand Up @@ -548,7 +548,7 @@ fn adjust_fb(mut word: B256, size: usize) -> B256 {
mod tests {
use super::*;
#[cfg(feature = "eip712")]
use alloy_sol_type_parser::{is_id_continue, is_id_start, is_valid_identifier};
use parser::{is_id_continue, is_id_start, is_valid_identifier};

proptest! {
#![proptest_config(ProptestConfig {
Expand Down
4 changes: 2 additions & 2 deletions crates/dyn-abi/src/coerce.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{ty::as_tuple, DynSolType, DynSolValue, Result};
use alloc::vec::Vec;
use alloy_primitives::{Address, FixedBytes, Function, Sign, I256, U256};
use alloy_sol_type_parser::utils::{array_parser, char_parser, spanned};
use alloy_sol_types::Word;
use core::fmt;
use hex::FromHexError;
use parser::utils::{array_parser, char_parser, spanned};
use winnow::{
ascii::{alpha0, alpha1, digit1, hex_digit0, hex_digit1, space0},
combinator::{cut_err, dispatch, fail, opt, preceded, success},
Expand Down Expand Up @@ -76,7 +76,7 @@ impl DynSolType {
pub fn coerce_str(&self, s: &str) -> Result<DynSolValue> {
ValueParser::new(self)
.parse(s)
.map_err(|e| crate::Error::TypeParser(alloy_sol_type_parser::Error::parser(e)))
.map_err(|e| crate::Error::TypeParser(parser::Error::parser(e)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/eip712/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
Error,
};
use alloc::vec::Vec;
use alloy_sol_type_parser::{Error as TypeParserError, TypeSpecifier};
use parser::{Error as TypeParserError, TypeSpecifier};

/// A property is a type and a name. Of the form `type name`. E.g.
/// `uint256 foo` or `(MyStruct[23],bool) bar`.
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/eip712/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use alloc::{
vec::Vec,
};
use alloy_primitives::{keccak256, B256};
use alloy_sol_type_parser::{RootType, TypeSpecifier, TypeStem};
use alloy_sol_types::SolStruct;
use core::{cmp::Ordering, fmt};
use parser::{RootType, TypeSpecifier, TypeStem};
use serde::{Deserialize, Deserializer, Serialize};

/// An EIP-712 property definition.
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/eip712/typed_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
};
use alloc::{collections::BTreeMap, string::String, vec::Vec};
use alloy_primitives::{keccak256, B256};
use alloy_sol_type_parser::TypeSpecifier;
use alloy_sol_types::{Eip712Domain, SolStruct};
use derive_more::{Deref, DerefMut, From, Into, IntoIterator};
use parser::TypeSpecifier;
use serde::{Deserialize, Serialize};

/// Custom types for `TypedData`.
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use alloc::{borrow::Cow, string::String};
use alloy_primitives::B256;
use alloy_sol_type_parser::Error as TypeParserError;
use alloy_sol_types::Error as SolTypesError;
use core::fmt;
use hex::FromHexError;
use parser::Error as TypeParserError;

/// Dynamic ABI result type.
pub type Result<T, E = Error> = core::result::Result<T, E>;
Expand Down
4 changes: 2 additions & 2 deletions crates/dyn-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#[macro_use]
extern crate alloc;

pub extern crate alloy_sol_type_parser as parser;

#[cfg(feature = "arbitrary")]
mod arbitrary;

Expand Down Expand Up @@ -59,8 +61,6 @@ pub mod eip712;
#[cfg(feature = "eip712")]
pub use eip712::{parser as eip712_parser, Eip712Types, PropertyDef, Resolver, TypeDef, TypedData};

#[doc(no_inline)]
pub use alloy_sol_type_parser as parser;
#[doc(no_inline)]
pub use alloy_sol_types::{
abi::{self, Decoder, Encoder},
Expand Down
13 changes: 5 additions & 8 deletions crates/dyn-abi/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
use crate::{DynSolEvent, DynSolType, Result};
use alloc::vec::Vec;
use alloy_json_abi::{EventParam, Param};
use alloy_sol_type_parser::{
Error as ParserError, ParameterSpecifier, Parameters, RootType, TupleSpecifier, TypeSpecifier,
TypeStem,
};
use parser::{ParameterSpecifier, Parameters, RootType, TupleSpecifier, TypeSpecifier, TypeStem};

#[cfg(feature = "eip712")]
use alloy_json_abi::InternalType;
Expand Down Expand Up @@ -36,7 +33,7 @@ pub trait ResolveSolEvent {
/// This trait provides a single pattern for resolving those encodings into
/// Solidity types.
///
/// This trait is implemented for all the [`alloy_sol_type_parser`] types, the
/// This trait is implemented for all the [`parser`] types, the
/// [`Param`] and [`EventParam`] structs, and [`str`].
///
/// The [`str`] implementation calls [`DynSolType::parse`].
Expand Down Expand Up @@ -86,7 +83,7 @@ impl ResolveSolType for RootType<'_> {
return Ok(DynSolType::FixedBytes(sz));
}
}
return Err(ParserError::invalid_size(name).into());
return Err(parser::Error::invalid_size(name).into());
}

// fast path both integer types
Expand All @@ -103,9 +100,9 @@ impl ResolveSolType for RootType<'_> {
};
}
}
Err(ParserError::invalid_size(name).into())
Err(parser::Error::invalid_size(name).into())
} else {
Err(ParserError::invalid_type_string(name).into())
Err(parser::Error::invalid_type_string(name).into())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/ty.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{resolve::ResolveSolType, DynSolValue, DynToken, Error, Result, SolType, Word};
use alloc::{borrow::Cow, boxed::Box, string::String, vec::Vec};
use alloy_sol_type_parser::TypeSpecifier;
use alloy_sol_types::{abi::Decoder, sol_data};
use core::{fmt, iter::zip, num::NonZeroUsize, str::FromStr};
use parser::TypeSpecifier;

#[cfg(feature = "eip712")]
macro_rules! as_tuple {
Expand Down
5 changes: 2 additions & 3 deletions crates/json-abi/src/abi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{AbiItem, Constructor, Error, Event, Fallback, Function, Receive};
use alloc::{collections::btree_map, string::String, vec::Vec};
use alloy_primitives::Bytes;
use alloy_sol_type_parser::{Error as ParserError, Result as ParserResult};
use btree_map::BTreeMap;
use core::{fmt, iter, iter::Flatten};
use serde::{
Expand Down Expand Up @@ -91,12 +90,12 @@ impl JsonAbi {
/// assert_eq!(abi.len(), 9);
/// # Ok::<(), alloy_sol_type_parser::Error>(())
/// ```
pub fn parse<'a, I: IntoIterator<Item = &'a str>>(strings: I) -> ParserResult<Self> {
pub fn parse<'a, I: IntoIterator<Item = &'a str>>(strings: I) -> parser::Result<Self> {
let mut abi = Self::new();
for string in strings {
let item = AbiItem::parse(string)?;
abi.insert_item(item)
.map_err(|s| ParserError::_new("duplicate JSON ABI field: ", &s))?;
.map_err(|s| parser::Error::_new("duplicate JSON ABI field: ", &s))?;
}
Ok(abi)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/json-abi/src/internal_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::string::{String, ToString};
use alloy_sol_type_parser::TypeSpecifier;
use core::fmt;
use parser::TypeSpecifier;
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};

/// The contract internal type. This could be a regular Solidity type, a
Expand Down
Loading