diff --git a/crates/blobber/Cargo.toml b/crates/blobber/Cargo.toml index e278b91..083952e 100644 --- a/crates/blobber/Cargo.toml +++ b/crates/blobber/Cargo.toml @@ -20,6 +20,7 @@ reth.workspace = true reth-chainspec.workspace = true reth-transaction-pool = { workspace = true, optional = true } +serde.workspace = true smallvec.workspace = true tokio.workspace = true tracing.workspace = true diff --git a/crates/blobber/src/builder.rs b/crates/blobber/src/builder.rs index 6d86beb..c65dd28 100644 --- a/crates/blobber/src/builder.rs +++ b/crates/blobber/src/builder.rs @@ -1,4 +1,4 @@ -use crate::block_data::BlockExtractor; +use crate::{block_data::BlockExtractor, BlockExtractorConfig}; use init4_bin_base::utils::calc::SlotCalculator; use reth::transaction_pool::TransactionPool; use url::Url; @@ -59,6 +59,20 @@ impl BlockExtractorBuilder { self.with_pool(reth_transaction_pool::test_utils::testing_pool()) } + /// Set the configuration for the CL url, pylon url, from the provided + /// [`BlockExtractorConfig`]. + pub fn with_config(self, config: &BlockExtractorConfig) -> Result { + let this = self.with_explorer_url(config.blob_explorer_url()); + let this = + if let Some(cl_url) = config.cl_url() { this.with_cl_url(cl_url)? } else { this }; + + if let Some(pylon_url) = config.pylon_url() { + this.with_pylon_url(pylon_url) + } else { + Ok(this) + } + } + /// Set the blob explorer URL to use for the extractor. This will be used /// to construct a [`foundry_blob_explorers::Client`]. pub fn with_explorer_url(mut self, explorer_url: &str) -> Self { diff --git a/crates/blobber/src/config.rs b/crates/blobber/src/config.rs new file mode 100644 index 0000000..428b260 --- /dev/null +++ b/crates/blobber/src/config.rs @@ -0,0 +1,36 @@ +use init4_bin_base::utils::from_env::FromEnv; +use std::borrow::Cow; + +/// Configuration for the block extractor. +#[derive(Debug, Clone, serde::Deserialize, FromEnv)] +#[serde(rename_all = "camelCase")] +pub struct BlockExtractorConfig { + /// URL of the blob explorer. + #[from_env(var = "BLOB_EXPLORER_URL", desc = "URL of the blob explorer", infallible)] + blob_explorer_url: Cow<'static, str>, + + /// Consensus layer RPC URL + #[from_env(var = "SIGNET_CL_URL", desc = "Consensus layer URL", infallible, optional)] + cl_url: Option>, + + /// The Pylon node URL + #[from_env(var = "SIGNET_PYLON_URL", desc = "Pylon node URL", infallible, optional)] + pylon_url: Option>, +} + +impl BlockExtractorConfig { + /// Create a new `BlockExtractorConfig` with the provided CL URL, Pylon URL, + pub fn cl_url(&self) -> Option<&str> { + self.cl_url.as_deref() + } + + /// Get the Pylon URL. + pub fn pylon_url(&self) -> Option<&str> { + self.pylon_url.as_deref() + } + + /// Get the blob explorer URL. + pub fn blob_explorer_url(&self) -> &str { + &self.blob_explorer_url + } +} diff --git a/crates/blobber/src/lib.rs b/crates/blobber/src/lib.rs index 325528f..a17a040 100644 --- a/crates/blobber/src/lib.rs +++ b/crates/blobber/src/lib.rs @@ -17,6 +17,9 @@ pub use block_data::{Blobs, BlockExtractor}; mod builder; pub use builder::BlockExtractorBuilder; +mod config; +pub use config::BlockExtractorConfig; + mod error; pub use error::{BlockExtractionError, ExtractionResult};