mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add ChainspecParser trait (#9259)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -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
crates/cli/cli/src/chainspec.rs
Normal file
25
crates/cli/cli/src/chainspec.rs
Normal 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>>;
|
||||
}
|
||||
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user