pub struct FactoryRegistry { /* private fields */ }Expand description
Thread-safe registry of factory contracts and their discovered children.
Call register to add factory configurations, then feed
incoming events through process_event. When a
creation event is detected, the child address is extracted and tracked.
Use get_all_addresses to build an
EventFilter that covers all factory and
child addresses.
Implementations§
Source§impl FactoryRegistry
impl FactoryRegistry
Sourcepub fn register(&self, config: FactoryConfig)
pub fn register(&self, config: FactoryConfig)
Register a factory contract configuration.
After registration, any DecodedEvent from this factory with the
matching topic0 will be checked for child address extraction.
Sourcepub fn process_event(&self, event: &DecodedEvent) -> Option<DiscoveredChild>
pub fn process_event(&self, event: &DecodedEvent) -> Option<DiscoveredChild>
Process an incoming event, checking if it is a factory creation event.
Returns Some(DiscoveredChild) if the event matched a registered
factory and a new child address was extracted. Returns None if:
- The event is not from a registered factory.
- The event topic0 does not match a creation event.
- The child address was already discovered (dedup).
- The child address field could not be found in
fields_json.
Sourcepub fn get_all_addresses(&self) -> Vec<String>
pub fn get_all_addresses(&self) -> Vec<String>
Get all tracked addresses (factories + discovered children).
Useful for building an EventFilter
that covers all contracts the indexer should watch.
Sourcepub fn children_of(&self, factory_address: &str) -> Vec<DiscoveredChild>
pub fn children_of(&self, factory_address: &str) -> Vec<DiscoveredChild>
Get all children discovered from a specific factory.
Returns an empty vec if the factory has no children or is not registered.
Sourcepub fn snapshot(&self) -> FactorySnapshot
pub fn snapshot(&self) -> FactorySnapshot
Create a serializable snapshot of the current registry state.
Use this to persist discovered children across restarts.
Sourcepub fn restore(&self, snapshot: FactorySnapshot)
pub fn restore(&self, snapshot: FactorySnapshot)
Restore the registry from a previously saved snapshot.
This re-registers all factory configs and re-populates the children sets. Any existing state is merged (not replaced).
Sourcepub fn factory_count(&self) -> usize
pub fn factory_count(&self) -> usize
Returns the number of registered factories.
Sourcepub fn child_count(&self) -> usize
pub fn child_count(&self) -> usize
Returns the total number of discovered children across all factories.