[Feature] Support querying all events from a contract instance without manually specifying topics
- Vorherrschende Sprache
- Rust
- Sterne
- 1.3k
- Forks
- 668
- Ø Merge
- 2 T. 2 Std.
- Gemergte PRs (30 T.)
- 29
Beschreibung
### 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_
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.