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(sol!): pass correct call_struct to call_builder in expansion #901

Merged
merged 4 commits into from
Mar 13, 2025
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
14 changes: 12 additions & 2 deletions crates/sol-macro-expander/src/expand/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,13 +983,23 @@ fn call_builder_method(f: &ItemFunction, cx: &ExpCtxt<'_>) -> TokenStream {
let name = cx.function_name(f);
let call_name = cx.call_name(f);
let param_names1 = f.parameters.names().enumerate().map(anon_name);
let param_names2 = param_names1.clone();
let param_tys = f.parameters.types().map(|ty| cx.expand_rust_type(ty));
let doc = format!("Creates a new call builder for the [`{name}`] function.");

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),* }
}
};
Comment on lines +989 to +998
Copy link
Member

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

quote! {
#[doc = #doc]
pub fn #name(&self, #(#param_names1: #param_tys),*) -> alloy_contract::SolCallBuilder<&P, #call_name, N> {
self.call_builder(&#call_name { #(#param_names2),* })
self.call_builder(&#call_struct)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions crates/sol-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ use syn::parse_macro_input;
/// default behavior of [`abigen`]. This makes use of the [`alloy-contract`](https://github.com/alloy-rs/alloy)
/// crate.
///
/// N.B: at the time of writing, the `alloy-contract` crate is not yet released on `crates.io`,
/// and its API is completely unstable and subject to change, so this feature is not yet
/// recommended for use.
///
/// Generates the following items inside of the `{contract_name}` module:
/// - `struct {contract_name}Instance<P: Provider> { ... }`
/// - `pub fn new(...) -> {contract_name}Instance<P>` + getters and setters
Expand Down