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

fix(json-abi): correct to-sol for UDVT arrays in structs #745

Merged
merged 2 commits into from
Sep 24, 2024
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/json-abi/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Param {
/// instantiate directly. Use Param::new instead.
#[doc(hidden)]
pub name: String,
/// If the paramaeter is a compound type (a struct or tuple), a list of the
/// If the parameter is a compound type (a struct or tuple), a list of the
/// parameter's components, in order. Empty otherwise
pub components: Vec<Param>,
/// The internal type of the parameter. This type represents the type that
Expand Down Expand Up @@ -325,7 +325,7 @@ pub struct EventParam {
/// Whether the parameter is indexed. Indexed parameters have their
/// value, or the hash of their value, stored in the log topics.
pub indexed: bool,
/// If the paramaeter is a compound type (a struct or tuple), a list of the
/// If the parameter is a compound type (a struct or tuple), a list of the
/// parameter's components, in order. Empty otherwise. Because the
/// components are not top-level event params, they will not have an
/// `indexed` field.
Expand Down
10 changes: 6 additions & 4 deletions crates/json-abi/src/to_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a> InternalTypes<'a> {
&mut self,
internal_type: Option<&'a InternalType>,
components: &'a Vec<Param>,
real_ty: &'a String,
real_ty: &'a str,
) {
match internal_type {
None | Some(InternalType::AddressPayable(_) | InternalType::Contract(_)) => {}
Expand All @@ -229,9 +229,11 @@ impl<'a> InternalTypes<'a> {
}
}
Some(it @ InternalType::Other { contract, ty }) => {
// `Other` is a UDVT if it's not a basic Solidity type and not an array
// `Other` is a UDVT if it's not a basic Solidity type.
if let Some(it) = it.other_specifier() {
if it.try_basic_solidity().is_err() && !it.is_array() {
if it.try_basic_solidity().is_err() {
let ty = ty.split('[').next().unwrap();
let real_ty = real_ty.split('[').next().unwrap();
Comment on lines +235 to +236
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should work for non-arrays and arrays alike

self.extend_one(contract, It::new(ty, ItKind::Udvt(real_ty)));
}
}
Expand Down Expand Up @@ -264,7 +266,7 @@ struct It<'a> {
#[derive(PartialEq, Eq)]
enum ItKind<'a> {
Enum,
Udvt(&'a String),
Udvt(&'a str),
Struct(&'a Vec<Param>),
}

Expand Down
2 changes: 2 additions & 0 deletions crates/json-abi/tests/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ fn to_sol_test(path: &str, abi: &JsonAbi, run_solc: bool) {
|"ZeroXExchange"| "GaugeController" | "DoubleExponentInterestSetter" | "NamelessParams"
// UniswapV1Exchange has return values with the same name.
| "UniswapV1Exchange"
// https://github.com/alloy-rs/core/issues/744
| "DelegationManager"
) {
return;
}
Expand Down
Loading