feat: add ChainspecParser trait (#9259)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Luca Provini
2024-07-03 13:03:57 +02:00
committed by GitHub
parent 5827c25996
commit 71041b06a8
4 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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. Implementers of this trait must provide a list of supported chains and a
/// 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>>;
}

View File

@ -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.