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

Open
wants to merge 4 commits into
base: v1.0-rc
Choose a base branch
from

Conversation

yash-atreya
Copy link
Member

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

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@yash-atreya yash-atreya self-assigned this Mar 12, 2025
@yash-atreya yash-atreya modified the milestone: v1.0 Mar 12, 2025
@yash-atreya yash-atreya marked this pull request as ready for review March 12, 2025 11:59
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

some questions

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

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?

Copy link
Member Author

@yash-atreya yash-atreya Mar 12, 2025

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),* })
resulting in compilation issues.

Copy link
Member Author

@yash-atreya yash-atreya Mar 12, 2025

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

Copy link
Member

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);?

Copy link
Member Author

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

@yash-atreya yash-atreya marked this pull request as draft March 12, 2025 16:57
@yash-atreya yash-atreya marked this pull request as ready for review March 12, 2025 17:53
Copy link
Member

@mattsse mattsse left a 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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Reviewed
Development

Successfully merging this pull request may close these issues.

3 participants