feat: make addons stateful (#11204)

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
Matthias Seitz
2024-10-04 08:34:37 +02:00
committed by GitHub
parent ab06997986
commit 84370b81d7
19 changed files with 75 additions and 25 deletions

View File

@ -102,6 +102,10 @@ where
let Self { args } = self;
Self::components(args.clone())
}
fn add_ons(&self) -> Self::AddOns {
OptimismAddOns::new(self.args.sequencer_http.clone())
}
}
impl NodeTypes for OptimismNode {
@ -115,7 +119,21 @@ impl NodeTypesWithEngine for OptimismNode {
/// Add-ons w.r.t. optimism.
#[derive(Debug, Clone)]
pub struct OptimismAddOns;
pub struct OptimismAddOns {
sequencer_http: Option<String>,
}
impl OptimismAddOns {
/// Create a new instance with the given `sequencer_http` URL.
pub const fn new(sequencer_http: Option<String>) -> Self {
Self { sequencer_http }
}
/// Returns the sequencer HTTP URL.
pub fn sequencer_http(&self) -> Option<&str> {
self.sequencer_http.as_deref()
}
}
impl<N: FullNodeComponents> NodeAddOns<N> for OptimismAddOns {
type EthApi = OpEthApi<N>;

View File

@ -15,7 +15,7 @@ fn test_basic_setup() {
.with_database(db)
.with_types::<OptimismNode>()
.with_components(OptimismNode::components(Default::default()))
.with_add_ons::<OptimismAddOns>()
.with_add_ons(OptimismAddOns::new(None))
.on_component_initialized(move |ctx| {
let _provider = ctx.provider();
Ok(())