reth_node_core/args/
era.rs

1use clap::Args;
2use reth_chainspec::{ChainKind, NamedChain};
3use std::path::Path;
4use url::Url;
5
6/// Syncs ERA1 encoded blocks from a local or remote source.
7#[derive(Clone, Debug, Default, Args)]
8pub struct EraArgs {
9    /// Enable import from ERA1 files.
10    #[arg(
11        id = "era.enable",
12        long = "era.enable",
13        value_name = "ERA_ENABLE",
14        default_value_t = false
15    )]
16    pub enabled: bool,
17
18    /// Describes where to get the ERA files to import from.
19    #[clap(flatten)]
20    pub source: EraSourceArgs,
21}
22
23/// Arguments for the block history import based on ERA1 encoded files.
24#[derive(Clone, Debug, Default, Args)]
25#[group(required = false, multiple = false)]
26pub struct EraSourceArgs {
27    /// The path to a directory for import.
28    ///
29    /// The ERA1 files are read from the local directory parsing headers and bodies.
30    #[arg(long = "era.path", value_name = "ERA_PATH", verbatim_doc_comment)]
31    pub path: Option<Box<Path>>,
32
33    /// The URL to a remote host where the ERA1 files are hosted.
34    ///
35    /// The ERA1 files are read from the remote host using HTTP GET requests parsing headers
36    /// and bodies.
37    #[arg(long = "era.url", value_name = "ERA_URL", verbatim_doc_comment)]
38    pub url: Option<Url>,
39}
40
41/// The `ExtractEraHost` trait allows to derive a default URL host for ERA files.
42pub trait DefaultEraHost {
43    /// Converts `self` into [`Url`] index page of the ERA host.
44    ///
45    /// Returns `Err` if the conversion is not possible.
46    fn default_era_host(&self) -> Option<Url>;
47}
48
49impl DefaultEraHost for ChainKind {
50    fn default_era_host(&self) -> Option<Url> {
51        Some(match self {
52            Self::Named(NamedChain::Mainnet) => {
53                Url::parse("https://era.ithaca.xyz/era1/index.html").expect("URL should be valid")
54            }
55            Self::Named(NamedChain::Sepolia) => {
56                Url::parse("https://era.ithaca.xyz/sepolia-era1/index.html")
57                    .expect("URL should be valid")
58            }
59            _ => return None,
60        })
61    }
62}