From 3f474294c0e993a9675b4823194591a607927969 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 12 Mar 2025 17:19:02 +0530 Subject: [PATCH 1/4] fix(`sol!`): pass correct call_struct to call_builder in expansion --- .../sol-macro-expander/src/expand/contract.rs | 21 +++++++++++++++++-- crates/sol-macro/src/lib.rs | 4 ---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/sol-macro-expander/src/expand/contract.rs b/crates/sol-macro-expander/src/expand/contract.rs index cbcdb855e..4882e9f03 100644 --- a/crates/sol-macro-expander/src/expand/contract.rs +++ b/crates/sol-macro-expander/src/expand/contract.rs @@ -983,13 +983,30 @@ 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! { + 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),* + } + } + }; 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) } } } diff --git a/crates/sol-macro/src/lib.rs b/crates/sol-macro/src/lib.rs index 8d41b08b6..79cf82e92 100644 --- a/crates/sol-macro/src/lib.rs +++ b/crates/sol-macro/src/lib.rs @@ -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 { ... }` /// - `pub fn new(...) -> {contract_name}Instance

` + getters and setters From b6415496a46404195c40e4f8d2e8ecca07253981 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:18:57 +0530 Subject: [PATCH 2/4] fix --- crates/sol-macro-expander/src/expand/contract.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sol-macro-expander/src/expand/contract.rs b/crates/sol-macro-expander/src/expand/contract.rs index 4882e9f03..114dd270f 100644 --- a/crates/sol-macro-expander/src/expand/contract.rs +++ b/crates/sol-macro-expander/src/expand/contract.rs @@ -996,7 +996,7 @@ fn call_builder_method(f: &ItemFunction, cx: &ExpCtxt<'_>) -> TokenStream { pub struct #call_name(pub #ty); } } else { - let call_fields = super::expand_fields(&f.parameters, cx); + let call_fields = param_names1.clone(); quote! { pub struct #call_name { #(#call_fields),* From a6d20b58dcee00c0a8165e101637cc16468fca53 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:43:31 +0530 Subject: [PATCH 3/4] don't gen new structs --- crates/sol-macro-expander/src/expand/contract.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/sol-macro-expander/src/expand/contract.rs b/crates/sol-macro-expander/src/expand/contract.rs index 114dd270f..7dcec71fc 100644 --- a/crates/sol-macro-expander/src/expand/contract.rs +++ b/crates/sol-macro-expander/src/expand/contract.rs @@ -987,20 +987,14 @@ fn call_builder_method(f: &ItemFunction, cx: &ExpCtxt<'_>) -> TokenStream { let doc = format!("Creates a new call builder for the [`{name}`] function."); let call_struct = if f.parameters.is_empty() { - quote! { - pub struct #call_name; - } + quote! { #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); - } + let param_name = quote! { _0 }; + quote! { #call_name(#param_name) } } else { let call_fields = param_names1.clone(); quote! { - pub struct #call_name { - #(#call_fields),* - } + #call_name { #(#call_fields),* } } }; quote! { From 85850de05754d379541544e5e03abf605aaff623 Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Wed, 12 Mar 2025 22:43:56 +0530 Subject: [PATCH 4/4] nit --- crates/sol-macro-expander/src/expand/contract.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/sol-macro-expander/src/expand/contract.rs b/crates/sol-macro-expander/src/expand/contract.rs index 7dcec71fc..d27aa9606 100644 --- a/crates/sol-macro-expander/src/expand/contract.rs +++ b/crates/sol-macro-expander/src/expand/contract.rs @@ -989,8 +989,7 @@ fn call_builder_method(f: &ItemFunction, cx: &ExpCtxt<'_>) -> TokenStream { let call_struct = if f.parameters.is_empty() { quote! { #call_name } } else if f.parameters.len() == 1 && f.parameters[0].name.is_none() { - let param_name = quote! { _0 }; - quote! { #call_name(#param_name) } + quote! { #call_name(_0) } } else { let call_fields = param_names1.clone(); quote! {