Expand description
Event-Scanner is a library made to stream EVM event logs.
The main entry point is EventScanner, built via EventScannerBuilder in one of the
supported modes (e.g. Historic or Live).
§Node compatibility
Event Scanner’s test suite and examples are exercised against Foundry’s anvil dev node.
While the library is intended to work with other EVM nodes and RPC providers, behaviour may vary across implementations. If you encounter errors when using a different node/provider, please report them at https://github.com/OpenZeppelin/Event-Scanner/issues.
After constructing a scanner, register one or more event subscriptions with
EventScanner::subscribe, then call EventScanner::start to begin streaming.
§Stream items
Each subscription yields an EventScannerResult. Successful items are Message values,
which wrap either event batches or a Notification (see ScannerMessage).
§Ordering
Ordering is preserved per subscription stream. There is no global ordering guarantee across different subscriptions.
§Reorgs and finality
When scanning non-finalized blocks, the scanner may detect chain reorganizations and will emit
Notification::ReorgDetected. Consumers should assume the same events might be delivered more
than once around reorgs (i.e. benign duplicates are possible).
BlockNumberOrTag::Finalized is treated as the authoritative finality boundary
when the scanner needs one. In live mode, block_confirmations delays emission to reduce the
chance that already-emitted blocks are affected by shallow reorganizations.
§Dedupe vs rollback
Event-Scanner does not include a built-in deduplication utility. Depending on your application, you can:
- Implement idempotency/deduplication (for example, keyed by transaction hash and log index, optionally including block hash).
- Handle reorgs by rollback: interpret
Notification::ReorgDetectedas a signal to revert application state for blocks after the reported common ancestor.
§Backpressure and lag
Streams are buffered. If a consumer cannot keep up and an internal broadcast receiver lags,
the subscription stream yields ScannerError::Lagged.
Re-exports§
pub use block_range_scanner::BlockRangeScanner;pub use block_range_scanner::BlockRangeScannerBuilder;pub use block_range_scanner::BlockScannerResult;pub use block_range_scanner::DEFAULT_BLOCK_CONFIRMATIONS;pub use block_range_scanner::DEFAULT_MAX_BLOCK_RANGE;pub use block_range_scanner::DEFAULT_STREAM_BUFFER_CAPACITY;pub use block_range_scanner::ReorgHandler;pub use block_range_scanner::RingBufferCapacity;pub use block_range_scanner::RingBufferCapacity as PastBlocksStorageCapacity;
Modules§
Macros§
- assert_
closed - assert_
empty - assert_
event_ sequence - Asserts that a stream emits a specific sequence of events in order.
- assert_
event_ sequence_ final - Same as
assert_event_sequence!, but invokesassert_empty!at the end. - assert_
next - assert_
range_ coverage - Asserts that a stream of block ranges completely covers an expected block range.
Structs§
- Event
Filter - Type representing filters to apply when fetching events from the chain.
- Event
Scanner - An event scanner configured in mode
Modeand bound to networkN. - Event
Scanner Builder - Builder for constructing an
EventScannerin a particular mode. - Event
Subscription - A subscription to scanner events that requires proof the scanner has started.
- Historic
- Mode marker for historical range scanning.
- Latest
Events - Mode marker for latest-events collection.
- Latest
Events Handler - Collects the latest
countlogs per listener before streaming them. - Live
- Mode marker for live streaming.
- Start
Proof - Proof that the scanner has been started.
- Stream
Handler - Streams logs to listeners as soon as each scanned block range is processed.
- Sync
From Block - Mode marker for scanning by syncing from the specified block and then switching to live mode.
- Sync
From Latest Events - Mode marker for scanning by syncing from the specified count of latest events and then switching to live mode.
Enums§
- Notification
- Notifications emitted by the scanner to signal state changes or important events.
- Scanner
Error - Errors emitted by the scanner.
- Scanner
Message - Messages streamed by the scanner to subscribers.
Constants§
- DEFAULT_
MAX_ CONCURRENT_ FETCHES - Default number of maximum concurrent fetches for each scanner mode.
Traits§
- Block
Range Handler - Handles a stream of scanned block ranges.
Type Aliases§
- Event
Scanner Result - The
Resulttype yielded by event subscription streams. - Message
- The item type yielded by event subscription streams.