sui_bridge/sui_bridge_watchdog/
eth_bridge_status.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The EthBridgeStatus observable monitors whether the Eth Bridge is paused.
5
6use crate::abi::EthSuiBridge;
7use crate::metered_eth_provider::MeteredEthHttpProvier;
8use crate::sui_bridge_watchdog::Observable;
9use async_trait::async_trait;
10use ethers::providers::Provider;
11use ethers::types::Address as EthAddress;
12use prometheus::IntGauge;
13use std::sync::Arc;
14use tokio::time::Duration;
15use tracing::{error, info};
16
17pub struct EthBridgeStatus {
18    bridge_contract: EthSuiBridge<Provider<MeteredEthHttpProvier>>,
19    metric: IntGauge,
20}
21
22impl EthBridgeStatus {
23    pub fn new(
24        provider: Arc<Provider<MeteredEthHttpProvier>>,
25        bridge_address: EthAddress,
26        metric: IntGauge,
27    ) -> Self {
28        let bridge_contract = EthSuiBridge::new(bridge_address, provider.clone());
29        Self {
30            bridge_contract,
31            metric,
32        }
33    }
34}
35
36#[async_trait]
37impl Observable for EthBridgeStatus {
38    fn name(&self) -> &str {
39        "EthBridgeStatus"
40    }
41
42    async fn observe_and_report(&self) {
43        let status = self.bridge_contract.paused().call().await;
44        match status {
45            Ok(status) => {
46                self.metric.set(status as i64);
47                info!("Eth Bridge Status: {:?}", status);
48            }
49            Err(e) => {
50                error!("Error getting eth bridge status: {:?}", e);
51            }
52        }
53    }
54
55    fn interval(&self) -> Duration {
56        Duration::from_secs(10)
57    }
58}