diff --git a/src/extensions/api/eth.rs b/src/extensions/api/eth.rs index 7eaa303..2d79ae1 100644 --- a/src/extensions/api/eth.rs +++ b/src/extensions/api/eth.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use std::{sync::Arc, time::Duration}; use async_trait::async_trait; @@ -33,7 +34,7 @@ impl Extension for EthApi { type Config = EthApiConfig; async fn from_config(config: &Self::Config, registry: &ExtensionRegistry) -> Result { - let client = registry.get::().await.expect("Client not found"); + let client = registry.get::().await.context("Client not found")?; Ok(Self::new(client, Duration::from_secs(config.stale_timeout_seconds))) } diff --git a/src/extensions/api/substrate.rs b/src/extensions/api/substrate.rs index f8b8ed9..b2d2079 100644 --- a/src/extensions/api/substrate.rs +++ b/src/extensions/api/substrate.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use std::{sync::Arc, time::Duration}; use async_trait::async_trait; @@ -34,7 +35,7 @@ impl Extension for SubstrateApi { type Config = SubstrateApiConfig; async fn from_config(config: &Self::Config, registry: &ExtensionRegistry) -> Result { - let client = registry.get::().await.expect("Client not found"); + let client = registry.get::().await.context("Client not found")?; Ok(Self::new(client, Duration::from_secs(config.stale_timeout_seconds))) } diff --git a/src/extensions/validator/mod.rs b/src/extensions/validator/mod.rs index 742ae93..19392c5 100644 --- a/src/extensions/validator/mod.rs +++ b/src/extensions/validator/mod.rs @@ -1,5 +1,6 @@ use crate::extensions::client::Client; use crate::middlewares::{CallRequest, CallResult}; +use anyhow::Context; use async_trait::async_trait; use serde::Deserialize; use std::sync::Arc; @@ -21,15 +22,18 @@ impl Extension for Validator { type Config = ValidateConfig; async fn from_config(config: &Self::Config, registry: &ExtensionRegistry) -> Result { - let client = registry.get::().await.expect("Client extension not found"); + let client = registry.get::().await.context("Client extension not found")?; let clients = client .endpoints() .iter() - .map(|e| Arc::new(Client::with_endpoints([e]).expect("Unable to create client"))) - .collect(); + .map(|e| { + let client = Client::with_endpoints([e]).context("Failed to connect endpoint")?; + Ok(Arc::new(client)) + }) + .collect::>, anyhow::Error>>(); - Ok(Self::new(config.clone(), clients)) + Ok(Self::new(config.clone(), clients?)) } } diff --git a/src/middlewares/methods/block_tag.rs b/src/middlewares/methods/block_tag.rs index 1e0c6cf..b27621a 100644 --- a/src/middlewares/methods/block_tag.rs +++ b/src/middlewares/methods/block_tag.rs @@ -30,7 +30,7 @@ impl MiddlewareBuilder for BlockTagMiddlewar .get::() .expect("EthApi extension not found"); - Some(Box::new(BlockTagMiddleware::new(eth_api, index))) + Some(Box::new(Self::new(eth_api, index))) } } diff --git a/src/middlewares/methods/delay.rs b/src/middlewares/methods/delay.rs index ae07888..a3f3f5a 100644 --- a/src/middlewares/methods/delay.rs +++ b/src/middlewares/methods/delay.rs @@ -28,7 +28,7 @@ impl MiddlewareBuilder for DelayMiddleware { ) -> Option>> { method .delay_ms - .map(|delay| Box::new(DelayMiddleware::new(delay)) as Box>) + .map(|delay| Box::new(Self::new(delay)) as Box>) } } diff --git a/src/middlewares/methods/response.rs b/src/middlewares/methods/response.rs index 304d919..e797782 100644 --- a/src/middlewares/methods/response.rs +++ b/src/middlewares/methods/response.rs @@ -25,7 +25,7 @@ impl MiddlewareBuilder for ResponseMiddlewar method .response .as_ref() - .map(|resp| Box::new(ResponseMiddleware::new(resp.clone())) as Box>) + .map(|resp| Box::new(Self::new(resp.clone())) as Box>) } } diff --git a/src/middlewares/methods/testing.rs b/src/middlewares/methods/testing.rs index 4a51d91..71aa5e7 100644 --- a/src/middlewares/methods/testing.rs +++ b/src/middlewares/methods/testing.rs @@ -21,7 +21,7 @@ impl MiddlewareBuilder for CrazyMiddleware { method: &RpcMethod, _extensions: &TypeRegistryRef, ) -> Option>> { - Some(Box::new(CrazyMiddleware::new(method.method == "go_crazy"))) + Some(Box::new(Self::new(method.method == "go_crazy"))) } } diff --git a/src/middlewares/methods/upstream.rs b/src/middlewares/methods/upstream.rs index ba7ead4..467031b 100644 --- a/src/middlewares/methods/upstream.rs +++ b/src/middlewares/methods/upstream.rs @@ -30,7 +30,7 @@ impl MiddlewareBuilder for UpstreamMiddlewar .await .get::() .expect("Client extension not found"); - Some(Box::new(UpstreamMiddleware::new(client))) + Some(Box::new(Self::new(client))) } } diff --git a/src/middlewares/methods/validate.rs b/src/middlewares/methods/validate.rs index d4edf10..2c960be 100644 --- a/src/middlewares/methods/validate.rs +++ b/src/middlewares/methods/validate.rs @@ -29,7 +29,7 @@ impl MiddlewareBuilder for ValidateMiddlewar .get::() .expect("Validator extension not found"); - Some(Box::new(ValidateMiddleware::new(validate))) + Some(Box::new(Self::new(validate))) } }