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

[Feature] Implement Filter's builder methods on alloy_contract::Event #824

Closed
StackOverflowExcept1on opened this issue May 23, 2024 · 5 comments · Fixed by #960
Closed
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@StackOverflowExcept1on
Copy link
Contributor

StackOverflowExcept1on commented May 23, 2024

Component

contract

Describe the feature you would like

It would be nice to have method like event_filter_with_address::<Event>(address: impl Into<ValueOrArray<Address>>). For example, you want to subscribe to all DEXs like uniswap.

/// Event filters.
#[automatically_derived]
impl<
    T: alloy_contract::private::Transport + ::core::clone::Clone,
    P: alloy_contract::private::Provider<T, N>,
    N: alloy_contract::private::Network,
> RouterInstance<T, P, N> {
    /// Creates a new event filter using this contract instance's provider and address.
    ///
    /// Note that the type can be any event, not just those defined in this contract.
    /// Prefer using the other methods for building type-safe event filters.
    pub fn event_filter<E: alloy_sol_types::SolEvent>(
        &self,
    ) -> alloy_contract::Event<T, &P, E, N> {
        alloy_contract::Event::new_sol(&self.provider, &self.address)
    }
    ///Creates a new event filter for the [`CreateProgram`] event.
    pub fn CreateProgram_filter(
        &self,
    ) -> alloy_contract::Event<T, &P, CreateProgram, N> {
        self.event_filter::<CreateProgram>()
    }
}

#[doc(hidden)]
impl<'a, T: Transport + Clone, P: Provider<T, N>, E: SolEvent, N: Network> Event<T, &'a P, E, N> {
// `sol!` macro constructor, see `#[sol(rpc)]`. Not public API.
// NOTE: please avoid changing this function due to its use in the `sol!` macro.
pub fn new_sol(provider: &'a P, address: &Address) -> Self {
// keccak256 hash of the event signature needed for the filter to actually filter by event
// check that the event is not anonymous to include the event signature in the filter
if E::ANONYMOUS {
Self::new(provider, Filter::new().address(*address))
} else {
Self::new(provider, Filter::new().address(*address).event_signature(E::SIGNATURE_HASH))
}
}
}

Additional context

No response

@StackOverflowExcept1on StackOverflowExcept1on added the enhancement New feature or request label May 23, 2024
@DaniPopes
Copy link
Member

DaniPopes commented May 23, 2024

the internal filter can be modified with .filter.address = ...

@StackOverflowExcept1on
Copy link
Contributor Author

I see, but you need unnecessary mutability

@prestwich prestwich transferred this issue from alloy-rs/alloy May 27, 2024
@prestwich
Copy link
Member

prestwich commented May 27, 2024

migrated this, as contract codegen is performed in core.

I am not convinced that we actually want an constructor _with_whatever here instead of a builder-style method. Builders are our typical idiom

@DaniPopes
Copy link
Member

In that case if we want to do this it should be builder methods on alloy contract event that just delegate to the underlying filter?

@prestwich
Copy link
Member

that sounds right to me

@DaniPopes DaniPopes transferred this issue from alloy-rs/core Jun 4, 2024
@DaniPopes DaniPopes changed the title [Feature] Generate code for contract instance in such way that you can pass multiple addresses for events [Feature] Implement Filter's builder methods on alloy_contract::Event Jun 4, 2024
@DaniPopes DaniPopes added the good first issue Good for newcomers label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants