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!)!: gen unit struct for no param events #885

Open
wants to merge 2 commits into
base: yash/err-bindings
Choose a base branch
from

Conversation

yash-atreya
Copy link
Member

Motivation

Closes #879
Stacked over #883

Solution

  • If event does not contain any params, generate a unit struct instead of an empty struct.
sol! {
   event Empty();
}

// New 
pub struct Empty;

// Previous 
pub struct Empty {};

Bindings for events with params remain unchanged.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@yash-atreya yash-atreya changed the title fix(event): gen unit struct for no param events fix(event)!: gen unit struct for no param events Feb 21, 2025
@yash-atreya yash-atreya changed the base branch from main to yash/err-bindings February 21, 2025 08:19
@yash-atreya yash-atreya changed the title fix(event)!: gen unit struct for no param events fix(sol!)!: gen unit struct for no param events Feb 21, 2025
@yash-atreya yash-atreya marked this pull request as ready for review February 21, 2025 08:25
@@ -146,14 +146,24 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, event: &ItemEvent) -> Result<TokenStream>

let alloy_sol_types = &cx.crates.sol_types;

let event_struct = if event.parameters.is_empty() {
quote! {
pub struct #name;
Copy link
Member

Choose a reason for hiding this comment

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

should we derive default in these cases?

@DaniPopes
Copy link
Member

I don't think we should do this, it doesn't make that much of a difference to keep it consistent when there are no fields vs 1 or more fields.

@yash-atreya yash-atreya self-assigned this Feb 24, 2025
@yash-atreya yash-atreya added breaking enhancement New feature or request labels Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] feat(sol!)!: improve event bindings
3 participants