use ibc_relayer::chain::handle::CountingAndCachingChainHandle;
use ibc_relayer::config::Config;
use ibc_relayer::registry::SharedRegistry;
use ibc_relayer::supervisor::{spawn_supervisor, SupervisorHandle, SupervisorOptions};
use std::path::PathBuf;
use crate::error::Error;
use crate::types::env::{EnvWriter, ExportEnv};
use crate::util::suspend::hang_on_error;
#[derive(Clone)]
pub struct RelayerDriver {
pub config_path: PathBuf,
pub config: Config,
pub registry: SharedRegistry<CountingAndCachingChainHandle>,
pub hang_on_fail: bool,
}
impl RelayerDriver {
pub fn spawn_supervisor(&self) -> Result<SupervisorHandle, Error> {
spawn_supervisor(
self.config.clone(),
self.registry.clone(),
None,
SupervisorOptions {
health_check: false,
force_full_scan: false,
},
)
.map_err(Error::supervisor)
}
pub fn with_supervisor<R>(&self, cont: impl FnOnce() -> Result<R, Error>) -> Result<R, Error> {
let _handle = self.spawn_supervisor()?;
hang_on_error(self.hang_on_fail, cont)
}
}
impl ExportEnv for RelayerDriver {
fn export_env(&self, writer: &mut impl EnvWriter) {
writer.write_env("RELAYER_CONFIG", &format!("{}", self.config_path.display()));
}
}