diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index 9f7254bad7..fb94413fe7 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -170,6 +170,18 @@ impl NodeBuilder<(), ChainSpec> { { f(self) } + + /// Apply a function to the builder, if the condition is `true`. + pub fn apply_if(self, cond: bool, f: F) -> Self + where + F: FnOnce(Self) -> Self, + { + if cond { + f(self) + } else { + self + } + } } impl NodeBuilder { @@ -421,6 +433,18 @@ where f(self) } + /// Apply a function to the builder, if the condition is `true`. + pub fn apply_if(self, cond: bool, f: F) -> Self + where + F: FnOnce(Self) -> Self, + { + if cond { + f(self) + } else { + self + } + } + /// Sets the hook that is run once the node's components are initialized. pub fn on_component_initialized(self, hook: F) -> Self where @@ -482,6 +506,24 @@ where } } + /// Installs an `ExEx` (Execution Extension) in the node if the condition is true. + /// + /// # Note + /// + /// The `ExEx` ID must be unique. + pub fn install_exex_if(self, cond: bool, exex_id: impl Into, exex: F) -> Self + where + F: FnOnce(ExExContext>) -> R + Send + 'static, + R: Future> + Send, + E: Future> + Send, + { + if cond { + self.install_exex(exex_id, exex) + } else { + self + } + } + /// Launches the node with the given launcher. pub async fn launch_with(self, launcher: L) -> eyre::Result where