1use thiserror::Error;
2
3#[async_trait::async_trait]
4pub trait Monitor {
5 type WalletManager: crate::wallet::WalletManager + Send;
7
8 async fn start(&self, scale: &mut Self::WalletManager) -> Result<(), MonitorError>;
10
11 fn stop(&self) -> Result<(), MonitorError>;
13
14 fn is_running(&self) -> bool;
16
17 async fn restart(&self, scale: &mut Self::WalletManager) -> Result<(), MonitorError> {
19 Self::stop(&self)?;
20 Self::start(&self, scale).await?;
21 Ok(())
22 }
23
24 async fn sync(&self) -> Result<(), MonitorError>;
26
27 fn health_check() -> Result<(), MonitorError>;
29}
30
31#[derive(Debug, Error)]
32pub enum MonitorError {
33 #[error("Wallet manager error: {0}")]
35 WalletManagerError(#[from] crate::wallet::WalletManagerError),
36
37 #[error(transparent)]
39 Custom(#[from] Box<dyn std::error::Error + Send + Sync>),
40
41 #[error("Monitor is not running")]
43 NotRunning,
44
45 #[error("Monitor health check failed")]
47 HealthCheckFailed,
48}