pub struct ChainRouter { /* private fields */ }Expand description
A router that maps chain IDs to transport instances.
Allows a single entry point for multiple chains:
ⓘ
let router = ChainRouter::new();
router.add_chain(1, eth_pool); // Ethereum mainnet
router.add_chain(137, polygon_pool); // Polygon
router.add_chain(42161, arb_pool); // Arbitrum
let balance = router.chain(1).send(req).await?;Implementations§
Source§impl ChainRouter
impl ChainRouter
Sourcepub fn add_chain(&mut self, chain_id: u64, transport: Arc<dyn RpcTransport>)
pub fn add_chain(&mut self, chain_id: u64, transport: Arc<dyn RpcTransport>)
Register a transport for a chain ID.
Sourcepub fn chain(&self, chain_id: u64) -> Result<&dyn RpcTransport, TransportError>
pub fn chain(&self, chain_id: u64) -> Result<&dyn RpcTransport, TransportError>
Get the transport for a specific chain.
Sourcepub async fn send_to(
&self,
chain_id: u64,
req: JsonRpcRequest,
) -> Result<JsonRpcResponse, TransportError>
pub async fn send_to( &self, chain_id: u64, req: JsonRpcRequest, ) -> Result<JsonRpcResponse, TransportError>
Send a request to a specific chain.
Sourcepub async fn parallel(
&self,
requests: Vec<(u64, JsonRpcRequest)>,
) -> Vec<Result<JsonRpcResponse, TransportError>>
pub async fn parallel( &self, requests: Vec<(u64, JsonRpcRequest)>, ) -> Vec<Result<JsonRpcResponse, TransportError>>
Send requests to multiple chains in parallel and collect results.
Returns results in the same order as the input. If any request fails, its slot contains the error.
Sourcepub fn chain_count(&self) -> usize
pub fn chain_count(&self) -> usize
Number of configured chains.
Sourcepub fn health_summary(&self) -> Vec<(u64, HealthStatus)>
pub fn health_summary(&self) -> Vec<(u64, HealthStatus)>
Health summary across all chains.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ChainRouter
impl !RefUnwindSafe for ChainRouter
impl Send for ChainRouter
impl Sync for ChainRouter
impl Unpin for ChainRouter
impl UnsafeUnpin for ChainRouter
impl !UnwindSafe for ChainRouter
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
Mutably borrows from an owned value. Read more