Skip to content

Commit 6bb03f3

Browse files
authored
feat: BlockExtractorConfig (#4)
1 parent 3f992a5 commit 6bb03f3

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

crates/blobber/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ reth.workspace = true
2020
reth-chainspec.workspace = true
2121
reth-transaction-pool = { workspace = true, optional = true }
2222

23+
serde.workspace = true
2324
smallvec.workspace = true
2425
tokio.workspace = true
2526
tracing.workspace = true

crates/blobber/src/builder.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::block_data::BlockExtractor;
1+
use crate::{block_data::BlockExtractor, BlockExtractorConfig};
22
use init4_bin_base::utils::calc::SlotCalculator;
33
use reth::transaction_pool::TransactionPool;
44
use url::Url;
@@ -59,6 +59,20 @@ impl<Pool> BlockExtractorBuilder<Pool> {
5959
self.with_pool(reth_transaction_pool::test_utils::testing_pool())
6060
}
6161

62+
/// Set the configuration for the CL url, pylon url, from the provided
63+
/// [`BlockExtractorConfig`].
64+
pub fn with_config(self, config: &BlockExtractorConfig) -> Result<Self, BuilderError> {
65+
let this = self.with_explorer_url(config.blob_explorer_url());
66+
let this =
67+
if let Some(cl_url) = config.cl_url() { this.with_cl_url(cl_url)? } else { this };
68+
69+
if let Some(pylon_url) = config.pylon_url() {
70+
this.with_pylon_url(pylon_url)
71+
} else {
72+
Ok(this)
73+
}
74+
}
75+
6276
/// Set the blob explorer URL to use for the extractor. This will be used
6377
/// to construct a [`foundry_blob_explorers::Client`].
6478
pub fn with_explorer_url(mut self, explorer_url: &str) -> Self {

crates/blobber/src/config.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 the provided CL URL, Pylon URL,
23+
pub fn cl_url(&self) -> Option<&str> {
24+
self.cl_url.as_deref()
25+
}
26+
27+
/// Get the Pylon URL.
28+
pub fn pylon_url(&self) -> Option<&str> {
29+
self.pylon_url.as_deref()
30+
}
31+
32+
/// Get the blob explorer URL.
33+
pub fn blob_explorer_url(&self) -> &str {
34+
&self.blob_explorer_url
35+
}
36+
}

crates/blobber/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub use block_data::{Blobs, BlockExtractor};
1717
mod builder;
1818
pub use builder::BlockExtractorBuilder;
1919

20+
mod config;
21+
pub use config::BlockExtractorConfig;
22+
2023
mod error;
2124
pub use error::{BlockExtractionError, ExtractionResult};
2225

0 commit comments

Comments
 (0)