pub struct ChainRegistry { /* private fields */ }Expand description
Registry of supported blockchain parsers.
The registry provides runtime lookup of chain parsers by their identifier.
It is designed to be cloned cheaply (via Arc) for use across async tasks.
§Construction
Use ChainRegistry::new() to create a registry with all production chains,
or ChainRegistry::empty() for testing.
§Example
use txgate_chain::ChainRegistry;
let registry = ChainRegistry::new();
println!("Supported chains: {:?}", registry.supported_chains());
if let Some(parser) = registry.get("ethereum") {
// Use parser...
println!("Found: {}", parser.id());
}Implementations§
Source§impl ChainRegistry
impl ChainRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new registry with all supported chain parsers.
Currently supported chains:
ethereum- Ethereum and EVM-compatible chainsbitcoin- Bitcoin (Legacy,SegWit, Taproot)solana- Solana (Legacy and Versioned messages)
§Example
use txgate_chain::ChainRegistry;
let registry = ChainRegistry::new();
assert_eq!(registry.len(), 3);
assert!(registry.supports("ethereum"));
assert!(registry.supports("bitcoin"));
assert!(registry.supports("solana"));Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty registry (for testing).
This is useful when you need a registry without any production chains, typically for unit tests where you want to register mock chains.
§Example
use txgate_chain::ChainRegistry;
let registry = ChainRegistry::empty();
assert!(registry.is_empty());
assert_eq!(registry.len(), 0);Sourcepub fn register<C: Chain + 'static>(&mut self, chain: C)
pub fn register<C: Chain + 'static>(&mut self, chain: C)
Register a chain parser.
This is primarily used for testing with mock parsers.
In production, use ChainRegistry::new() which registers all supported chains.
§Arguments
chain- The chain parser to register
§Note
If a chain with the same ID is already registered, it will be replaced.
§Example
use txgate_chain::{ChainRegistry, MockChain};
let mut registry = ChainRegistry::empty();
let mock = MockChain {
id: "test-chain",
..Default::default()
};
registry.register(mock);
assert!(registry.supports("test-chain"));
assert_eq!(registry.len(), 1);Sourcepub fn get(&self, chain_id: &str) -> Option<&dyn Chain>
pub fn get(&self, chain_id: &str) -> Option<&dyn Chain>
Look up a chain parser by ID.
§Arguments
chain_id- The chain identifier (e.g., “ethereum”, “bitcoin”)
§Returns
Some(&dyn Chain)if the chain is supportedNoneif the chain is not supported
§Example
use txgate_chain::ChainRegistry;
let registry = ChainRegistry::new();
// Look up a chain (returns None if not registered)
let parser = registry.get("ethereum");
// Currently None - parsers will be added in future tasks
// Not found
let missing = registry.get("nonexistent");
assert!(missing.is_none());Sourcepub fn supported_chains(&self) -> Vec<&str>
pub fn supported_chains(&self) -> Vec<&str>
List all supported chain IDs.
Returns a sorted list of chain identifiers for consistency.
§Example
use txgate_chain::ChainRegistry;
let registry = ChainRegistry::new();
// Get list of all supported chains (sorted alphabetically)
let chains = registry.supported_chains();
assert_eq!(chains, vec!["bitcoin", "ethereum", "solana"]);Sourcepub fn supports(&self, chain_id: &str) -> bool
pub fn supports(&self, chain_id: &str) -> bool
Check if a chain is supported.
§Arguments
chain_id- The chain identifier to check
§Returns
trueif the chain is registeredfalseotherwise
§Example
use txgate_chain::ChainRegistry;
let registry = ChainRegistry::new();
// Check if a chain is supported
assert!(registry.supports("ethereum"));
assert!(registry.supports("bitcoin"));
assert!(registry.supports("solana"));
assert!(!registry.supports("unknown"));Trait Implementations§
Source§impl Clone for ChainRegistry
impl Clone for ChainRegistry
Source§fn clone(&self) -> ChainRegistry
fn clone(&self) -> ChainRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChainRegistry
impl Debug for ChainRegistry
Auto Trait Implementations§
impl Freeze for ChainRegistry
impl !RefUnwindSafe for ChainRegistry
impl Send for ChainRegistry
impl Sync for ChainRegistry
impl Unpin for ChainRegistry
impl !UnwindSafe for ChainRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more