alloy-rs / alloy-rs/alloy

[Feature] Support querying all events from a contract instance without manually specifying topics

Abierto
#2,890 3 comentarios 0 reacciones 1 asignado Reclamado por @SWASTIC-7 Ver en GitHub
enhancement
Lenguaje dominante
Rust
Estrellas
1.3k
Forks
668
Merge medio
2 d 1 h
PR fusionados (30 d)
29

Descripción

### Component

contract

### Describe the feature you would like

# Problem

Right now, when using generated Alloy bindings, querying for a **single event** type from a contract is very ergonomic:

```rust
async fn get_events_by_block_hash(
instance: UniswapV3Pool::Instance,
block_hash: B256,
) -> Result> {
instance
.event_filter()
.at_block_hash(block_hash)
.query()
.await
.map_err(anyhow::Error::from)
}
```

The `event_filter()` function already knows the contract address and event signature, so I don’t need to manually specify topics or addresses.

However, when I need all events from the contract for a given block, I currently have to:
- Construct a Filter manually.
- Add the contract address explicitly.
- Manually collect all event signatures.
- Decode each Log into the generated events enum(e.g. `UniswapV3Pool::UniswapV3PoolEvents`).

```rust
async fn get_events_by_block_hash(
instance: UniswapV3Pool::Instance,
block_hash: B256,
) -> Result> {
let filter = Filter::new()
.address(*instance.address())
.events(vec![
UniswapV3Pool::Burn::SIGNATURE,
UniswapV3Pool::Swap::SIGNATURE,
UniswapV3Pool::Mint::SIGNATURE,
])
.at_block_hash(block_hash);

let events = instance
.provider()
.get_logs(&filter)
.await
.map_err(anyhow::Error::from)?
.into_iter()
.filter_map(|log| {
let event = UniswapV3Pool::UniswapV3PoolEvents::decode_log(&log.inner).ok()?;
Some((event.data, log))
})
.collect::>();

Ok(events)
}
```

This works, but it’s a lot more boilerplate compared to the single-event flow.

# Proposal

It would be great if Alloy provided an ergonomic way to query all events from a generated contract instance. For example:
- An `all_events_filter()` function on Instance that builds a filter for all events defined in the ABI.
- Or the ability for `event_filter()` to take an enum variant like `UniswapV3PoolEvents` and generate a filter covering all signatures.

The end-user experience could look something like:
```rust
let events = instance
.all_events_filter()
.at_block_hash(block_hash)
.query()
.await?;
```

### Additional context

_No response_

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.