pub struct ChainRegistry { /* private fields */ }Expand description
Registry mapping genesis hashes to ChainId values.
Use ChainRegistry::from_known_chains to build a registry pre-populated
with all chains whose genesis hashes are known at compile time. Additional
chains (e.g. testnets) can be added at runtime with ChainRegistry::insert.
Implementations§
Source§impl ChainRegistry
impl ChainRegistry
Sourcepub fn from_known_chains() -> Self
pub fn from_known_chains() -> Self
Build a registry containing every chain that has a compile-time known
genesis hash (i.e. ChainId::genesis_hash() returns Some).
Only chains with known genesis hashes get full entries here. Testnets
without compile-time genesis hashes are inserted at runtime after
connecting, via ChainRegistry::insert or ChainRegistry::insert_entry.
Sourcepub fn insert_entry(&mut self, entry: ChainRegistryEntry)
pub fn insert_entry(&mut self, entry: ChainRegistryEntry)
Insert a fully populated ChainRegistryEntry into the registry.
Deduplicates by both genesis hash and ChainId: if the same ChainId was previously registered with a different hash (e.g. testnet reset), the old entry is removed. If the same hash was registered under a different ChainId, that entry is also removed.
Sourcepub fn insert(&mut self, id: ChainId, genesis_hash: GenesisHash)
pub fn insert(&mut self, id: ChainId, genesis_hash: GenesisHash)
Insert a chain into the registry with minimal data.
Convenience method for runtime-discovered chains (e.g. testnets) where
only the genesis hash is known at insertion time. Configuration fields
are populated from ChainId methods. Prefer ChainRegistry::insert_entry
when you have a fully constructed entry.
Deduplicates by both genesis hash and ChainId: if the same ChainId was previously registered with a different hash (e.g. testnet reset), the old entry is removed. If the same hash was registered under a different ChainId, that entry is also removed.
Sourcepub fn by_genesis_hash(&self, hash: &GenesisHash) -> Option<ChainId>
pub fn by_genesis_hash(&self, hash: &GenesisHash) -> Option<ChainId>
Look up a chain by its genesis hash.
Returns None if the hash is not registered.
Sourcepub fn genesis_hashes(&self) -> Vec<GenesisHash> ⓘ
pub fn genesis_hashes(&self) -> Vec<GenesisHash> ⓘ
Return all genesis hashes currently in the registry.
Sourcepub fn entries(&self) -> &[ChainRegistryEntry]
pub fn entries(&self) -> &[ChainRegistryEntry]
Return all entries in insertion order.