Event Filter struct and helper functions to work with the event filters
Summary
Functions
Combines multiple event filters into a single Ethers.CombinedEventFilter matching
any of the given events (OR semantics) in one eth_getLogs request.
Types
@type t() :: %Ethers.EventFilter{ default_address: nil | Ethers.Types.t_address(), selector: ABI.FunctionSelector.t(), topics: [binary()] }
Holds event filter topics, the event selector and the default address.
Can be passed in to Ethers.get_logs/2 filter and fetch the logs.
Functions
@spec combine([t() | module()] | module()) :: Ethers.CombinedEventFilter.t()
Combines multiple event filters into a single Ethers.CombinedEventFilter matching
any of the given events (OR semantics) in one eth_getLogs request.
The combined filter can be used anywhere a regular event filter is accepted
(e.g. Ethers.get_logs/2 and Ethers.batch/2). Filtering happens server side using
an OR-ed list of topic_0 values and each fetched log is decoded using its matching
event selector.
Accepts event filters as well as EventFilters modules of contracts, which translate
to all events of that contract. (e.g. Ethers.Contracts.ERC20.EventFilters)
Rules
Raises ArgumentError if:
- The list of filters is empty.
- Any filter has indexed-argument values. Only wildcard filters (all indexed
arguments set to
nil) can be combined, sinceeth_getLogstopics are positional and OR-ing them across events would match unintended logs. - Filters have conflicting default addresses.
eth_getLogsaccepts a single address, so all combined filters must belong to the same contract.
Examples
filter =
Ethers.EventFilter.combine([
Ethers.Contracts.ERC20.EventFilters.transfer(nil, nil),
Ethers.Contracts.ERC20.EventFilters.approval(nil, nil)
])
Ethers.get_logs(filter, address: "0x...")
#=> {:ok, [%Ethers.Event{...}, ...]}
# All events of a contract
Ethers.EventFilter.combine([Ethers.Contracts.ERC20.EventFilters])