-
Notifications
You must be signed in to change notification settings - Fork 178
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(sol!
): pass correct call_struct to call_builder in expansion
#901
base: v1.0-rc
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some questions
let call_struct = if f.parameters.is_empty() { | ||
quote! { | ||
pub struct #call_name; | ||
} | ||
} else if f.parameters.len() == 1 && f.parameters[0].name.is_none() { | ||
let ty = cx.expand_rust_type(&f.parameters[0].ty); | ||
quote! { | ||
pub struct #call_name(pub #ty); | ||
} | ||
} else { | ||
let call_fields = super::expand_fields(&f.parameters, cx); | ||
quote! { | ||
pub struct #call_name { | ||
#(#call_fields),* | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, unclear why we need this here, do you have an example?
are we introducing new types here to group tuples together?
this previously didn't generate new structs and used call_name
directly, why do we need a new struct here?
how will this be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find the issue here: https://github.com/alloy-rs/examples/blob/33ceda8de21372b3a1315dad50983b25928f2471/examples/contracts/examples/interact_with_abi.rs#L18 (part of core 1.0 bump in examples: alloy-rs/examples#188)
TL;DR:
Take the following as an example:
sol! {
contract WETH {
function balanceOf(address) returns (uint256);
}
}
Previously, the expanded call type would be:
struct balanceOfCall {
_0: Address
}
After #884
struct balanceOfCall(pub Address); // Because there is only one param and it is unnamed.
However, call builder related code is still being expanded as:
// .. snip ..
self.call_builder(&balanceOfCall { _0 })
// .. snip ..
due to this line:
self.call_builder(&#call_name { #(#param_names2),* }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this previously didn't generate new structs and used call_name directly, why do we need a new struct here?
Fixed in a6d20b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct balanceOfCall(Address); // Because there is only one param and it is unnamed.
this should be struct balanceOfCall(pub Address);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct balanceOfCall(Address); // Because there is only one param and it is unnamed.
this should be
struct balanceOfCall(pub Address);
?
Yes, fixed above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense to me now
pending @DaniPopes
let call_struct = if f.parameters.is_empty() { | ||
quote! { #call_name } | ||
} else if f.parameters.len() == 1 && f.parameters[0].name.is_none() { | ||
quote! { #call_name(_0) } | ||
} else { | ||
let call_fields = param_names1.clone(); | ||
quote! { | ||
#call_name { #(#call_fields),* } | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a note here that this is supposed t deconstructs the struct
Motivation
After #884, call types are expanded depending on the number of params.
This change isn't propagated to
rpc
expansion code where call_builder is called.Solution
sol!
)!: gen unit/tuple structs for call types with 0/1 param #884call_builder
PR Checklist