Skip to main content

ChainRegistry

Struct ChainRegistry 

Source
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

Source

pub fn new() -> Self

Create a new registry with all supported chain parsers.

Currently supported chains:

  • ethereum - Ethereum and EVM-compatible chains
  • bitcoin - 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"));
Source

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);
Source

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);
Source

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 supported
  • None if 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());
Source

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"]);
Source

pub fn supports(&self, chain_id: &str) -> bool

Check if a chain is supported.

§Arguments
  • chain_id - The chain identifier to check
§Returns
  • true if the chain is registered
  • false otherwise
§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"));
Source

pub fn len(&self) -> usize

Get the number of registered chains.

§Example
use txgate_chain::ChainRegistry;

let registry = ChainRegistry::new();
assert_eq!(registry.len(), 3);  // ethereum, bitcoin, solana

let registry = ChainRegistry::empty();
assert_eq!(registry.len(), 0);
Source

pub fn is_empty(&self) -> bool

Check if the registry is empty.

§Example
use txgate_chain::ChainRegistry;

let registry = ChainRegistry::new();
assert!(!registry.is_empty());  // has 3 chains registered

let registry = ChainRegistry::empty();
assert!(registry.is_empty());

Trait Implementations§

Source§

impl Clone for ChainRegistry

Source§

fn clone(&self) -> ChainRegistry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChainRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ChainRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more