|
| 1 | +use init4_bin_base::utils::from_env::FromEnv; |
| 2 | +use std::borrow::Cow; |
| 3 | + |
| 4 | +/// Configuration for the block extractor. |
| 5 | +#[derive(Debug, Clone, serde::Deserialize, FromEnv)] |
| 6 | +#[serde(rename_all = "camelCase")] |
| 7 | +pub struct BlockExtractorConfig { |
| 8 | + /// URL of the blob explorer. |
| 9 | + #[from_env(var = "BLOB_EXPLORER_URL", desc = "URL of the blob explorer", infallible)] |
| 10 | + blob_explorer_url: Cow<'static, str>, |
| 11 | + |
| 12 | + /// Consensus layer RPC URL |
| 13 | + #[from_env(var = "SIGNET_CL_URL", desc = "Consensus layer URL", infallible, optional)] |
| 14 | + cl_url: Option<Cow<'static, str>>, |
| 15 | + |
| 16 | + /// The Pylon node URL |
| 17 | + #[from_env(var = "SIGNET_PYLON_URL", desc = "Pylon node URL", infallible, optional)] |
| 18 | + pylon_url: Option<Cow<'static, str>>, |
| 19 | +} |
| 20 | + |
| 21 | +impl BlockExtractorConfig { |
| 22 | + /// Create a new `BlockExtractorConfig` with default values. |
| 23 | + pub const fn new(blob_explorer_url: Cow<'static, str>) -> Self { |
| 24 | + Self { blob_explorer_url, cl_url: None, pylon_url: None } |
| 25 | + } |
| 26 | + |
| 27 | + /// Get the blob explorer URL. |
| 28 | + pub fn set_blob_explorer_url(&mut self, blob_explorer_url: Cow<'static, str>) { |
| 29 | + self.blob_explorer_url = blob_explorer_url; |
| 30 | + } |
| 31 | + |
| 32 | + /// Get the blob explorer URL. |
| 33 | + pub fn set_cl_url(&mut self, cl_url: Cow<'static, str>) { |
| 34 | + self.cl_url = Some(cl_url); |
| 35 | + } |
| 36 | + |
| 37 | + /// Set the Pylon URL. |
| 38 | + pub fn set_pylon_url(&mut self, pylon_url: Cow<'static, str>) { |
| 39 | + self.pylon_url = Some(pylon_url); |
| 40 | + } |
| 41 | + |
| 42 | + /// Create a new `BlockExtractorConfig` with the provided CL URL, Pylon URL, |
| 43 | + pub fn cl_url(&self) -> Option<&str> { |
| 44 | + self.cl_url.as_deref() |
| 45 | + } |
| 46 | + |
| 47 | + /// Get the Pylon URL. |
| 48 | + pub fn pylon_url(&self) -> Option<&str> { |
| 49 | + self.pylon_url.as_deref() |
| 50 | + } |
| 51 | + |
| 52 | + /// Get the blob explorer URL. |
| 53 | + pub fn blob_explorer_url(&self) -> &str { |
| 54 | + &self.blob_explorer_url |
| 55 | + } |
| 56 | +} |
0 commit comments