1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use lifeline::dyn_bus::DynBus;

use component_state::state::{BridgeState, StateOptions};
use support_common::config::{Config, Names};
use support_lifeline::task::TaskStack;

use crate::bridge::BridgeConfig;
use crate::service::ecdsa_relay::ECDSARelayService;
use crate::service::message_relay::pangoro_to_goerli::PangoroGoerliMessageRelay;
use crate::{
    bridge::BridgeBus,
    service::{
        header_relay::{
            execution_layer_update::ExecutionLayerRelay,
            goerli_to_pangoro::GoerliToPangoroHeaderRelayService,
            sync_committee_update::SyncCommitteeUpdateService,
        },
        message_relay::goerli_to_pangoro::GoerliPangoroMessageRelay,
    },
};

#[allow(dead_code)]
#[derive(Debug)]
pub struct BridgeTask {
    stack: TaskStack<BridgeBus>,
}

impl BridgeTask {
    pub fn name() -> &'static str {
        "pangoro-goerli"
    }
}

impl BridgeTask {
    pub async fn new() -> color_eyre::Result<Self> {
        let state = BridgeState::new(StateOptions {
            db_name: Self::name().to_string(),
        })?;
        // check config
        let _bridge_config: BridgeConfig = Config::restore(Names::BridgePangoroGoerli)?;

        let bus = BridgeBus::default();
        bus.store_resource::<BridgeState>(state);

        let mut stack = TaskStack::new(bus);
        stack.spawn_service::<GoerliToPangoroHeaderRelayService>()?;
        stack.spawn_service::<SyncCommitteeUpdateService>()?;
        stack.spawn_service::<ExecutionLayerRelay>()?;
        stack.spawn_service::<GoerliPangoroMessageRelay>()?;
        stack.spawn_service::<ECDSARelayService>()?;
        stack.spawn_service::<PangoroGoerliMessageRelay>()?;
        Ok(Self { stack })
    }
}