feat: map_chainspec for NodeConfig (#12068)

This commit is contained in:
greged93
2024-10-26 08:11:27 +02:00
committed by GitHub
parent e0ad59834d
commit cecdf611e9
2 changed files with 26 additions and 19 deletions

View File

@ -422,6 +422,29 @@ impl<ChainSpec> NodeConfig<ChainSpec> {
Err(e) => Err(eyre!("Failed to load configuration: {e}")),
}
}
/// Modifies the [`ChainSpec`] generic of the config using the provided closure.
pub fn map_chainspec<F, C>(self, f: F) -> NodeConfig<C>
where
F: FnOnce(Arc<ChainSpec>) -> C,
{
let chain = Arc::new(f(self.chain));
NodeConfig {
chain,
datadir: self.datadir,
config: self.config,
metrics: self.metrics,
instance: self.instance,
network: self.network,
rpc: self.rpc,
txpool: self.txpool,
builder: self.builder,
debug: self.debug,
db: self.db,
dev: self.dev,
pruning: self.pruning,
}
}
}
impl Default for NodeConfig<ChainSpec> {