You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -111,16 +110,67 @@ Once configured, connect using either `connect_ws::<Ethereum>(ws_url)` or `conne
111
110
112
111
Create an `EventFilter` for each contract/event pair you want to track. The filter bundles the contract address, the event signature (from `SolEvent::SIGNATURE`), and an `Arc<dyn EventCallback + Send + Sync>`.
113
112
113
+
Both `contract_address` and `event` fields are optional, allowing for flexible event tracking.
114
+
115
+
You can construct EventFilters using either the builder pattern (recommended) or direct struct construction:
116
+
117
+
### Builder Pattern (Recommended)
118
+
119
+
```rust
120
+
// Track a specific event from a specific contract
event:None, // Will track all events from this contract
150
+
callback:Arc::new(AllEventsCallback),
151
+
};
152
+
153
+
// Track ALL events from ALL contracts in the block range
154
+
letall_events_filter=EventFilter {
155
+
contract_address:None, // Will track events from all contracts
156
+
event:None, // Will track all event types
157
+
callback:Arc::new(GlobalEventsCallback),
158
+
};
120
159
```
121
160
122
161
Register multiple filters by calling either `with_event_filter` repeatedly or `with_event_filters` once.
123
162
163
+
#### Use Cases for Optional Fields
164
+
165
+
The optional `contract_address` and `event` fields enable several powerful use cases:
166
+
167
+
-**Track all events from a specific contract**: Set `contract_address` but leave `event` as `None`
168
+
-**Track all events across all contracts**: Set both `contract_address` and `event` as `None`
169
+
-**Track specific events from specific contracts**: Set both fields (traditional usage)
170
+
-**Mixed filtering**: Use multiple filters with different optional field combinations
171
+
172
+
This flexibility allows you to build sophisticated event monitoring systems that can track events at different granularities depending on your application's needs.
0 commit comments