mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add node builder helpers (#11731)
This commit is contained in:
@ -170,6 +170,18 @@ impl<ChainSpec> NodeBuilder<(), ChainSpec> {
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
/// Apply a function to the builder, if the condition is `true`.
|
||||
pub fn apply_if<F>(self, cond: bool, f: F) -> Self
|
||||
where
|
||||
F: FnOnce(Self) -> Self,
|
||||
{
|
||||
if cond {
|
||||
f(self)
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB, ChainSpec> NodeBuilder<DB, ChainSpec> {
|
||||
@ -421,6 +433,18 @@ where
|
||||
f(self)
|
||||
}
|
||||
|
||||
/// Apply a function to the builder, if the condition is `true`.
|
||||
pub fn apply_if<F>(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<F>(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<F, R, E>(self, cond: bool, exex_id: impl Into<String>, exex: F) -> Self
|
||||
where
|
||||
F: FnOnce(ExExContext<NodeAdapter<T, CB::Components>>) -> R + Send + 'static,
|
||||
R: Future<Output = eyre::Result<E>> + Send,
|
||||
E: Future<Output = eyre::Result<()>> + Send,
|
||||
{
|
||||
if cond {
|
||||
self.install_exex(exex_id, exex)
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Launches the node with the given launcher.
|
||||
pub async fn launch_with<L>(self, launcher: L) -> eyre::Result<L::Node>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user