Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ChainspecParser trait #9259

Merged
merged 7 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/cli/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ repository.workspace = true
[dependencies]
# reth
reth-cli-runner.workspace = true
reth-chainspec.workspace = true
eyre.workspace = true

# misc
clap.workspace = true
25 changes: 25 additions & 0 deletions crates/cli/cli/src/chainspec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use clap::builder::TypedValueParser;
use reth_chainspec::ChainSpec;
use std::sync::Arc;

/// Trait for parsing chain specifications.
///
/// This trait extends [`clap::builder::TypedValueParser`] to provide a parser for chain
/// specifications. Implementors of this trait must provide a list of supported chains and a

Check failure on line 8 in crates/cli/cli/src/chainspec.rs

View workflow job for this annotation

GitHub Actions / codespell

Implementors ==> Implementers
mattsse marked this conversation as resolved.
Show resolved Hide resolved
/// function to parse a given string into a [`ChainSpec`].
pub trait ChainSpecParser: TypedValueParser<Value = Arc<ChainSpec>> + Default {
/// List of supported chains.
const SUPPORTED_CHAINS: &'static [&'static str];

/// Parses the given string into a [`ChainSpec`].
///
/// # Arguments
///
/// * `s` - A string slice that holds the chain spec to be parsed.
///
/// # Errors
///
/// This function will return an error if the input string cannot be parsed into a valid
/// [`ChainSpec`].
fn parse(&self, s: &str) -> eyre::Result<Arc<ChainSpec>>;
}
2 changes: 2 additions & 0 deletions crates/cli/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use reth_cli_runner::CliRunner;

use clap::{Error, Parser};

pub mod chainspec;

/// Reth based node cli.
///
/// This trait is supposed to be implemented by the main struct of the CLI.
Expand Down
Loading