diff --git a/offchain/advance-runner/src/snapshot/config.rs b/offchain/advance-runner/src/snapshot/config.rs index 3f134bf80..3b25d6d8d 100644 --- a/offchain/advance-runner/src/snapshot/config.rs +++ b/offchain/advance-runner/src/snapshot/config.rs @@ -3,7 +3,7 @@ use clap::Parser; use rollups_events::Address; -use snafu::{ensure, ResultExt, Snafu}; +use snafu::{ensure, Snafu}; use std::path::PathBuf; use url::Url; @@ -35,19 +35,14 @@ impl SnapshotConfig { ensure!(snapshot_latest.is_symlink(), SymlinkSnafu); let validation_enabled = cli_config.snapshot_validation_enabled; - let provider_http_endpoint = if validation_enabled { - if let Some(endpoint) = &cli_config.provider_http_endpoint { - let url = - Url::parse(&endpoint).context(EndpointParseSnafu)?; - Some(url) - } else { - return Err( - SnapshotConfigError::NoProviderEndpointError {}, - ); - } - } else { - None - }; + if validation_enabled { + ensure!( + cli_config.provider_http_endpoint.is_some(), + NoProviderEndpointSnafu, + ); + } + + let provider_http_endpoint = cli_config.provider_http_endpoint; Ok(SnapshotConfig::FileSystem(FSManagerConfig { snapshot_dir, @@ -73,9 +68,6 @@ pub enum SnapshotConfigError { #[snafu(display("A provider http endpoint is required"))] NoProviderEndpointError {}, - - #[snafu(display("provider_http_endpoint isn't a valid URL"))] - EndpointParseError { source: url::ParseError }, } #[derive(Parser, Debug)] @@ -99,6 +91,6 @@ pub struct SnapshotCLIConfig { /// The endpoint for a JSON-RPC provider. /// Required if SNAPSHOT_VALIDATION_ENABLED is `true` - #[arg(long, env)] - provider_http_endpoint: Option, + #[arg(long, env, value_parser = Url::parse)] + provider_http_endpoint: Option, }